From 236700ea5899b3b78ac1d469c3ae4d7131b59f36 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Sun, 12 May 2024 16:16:27 +0200 Subject: [PATCH] samples: fix function that redirects stdout to DOM Fix #920 --- samples/stdout-helper/src/main/webapp/teavm/stdout.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/samples/stdout-helper/src/main/webapp/teavm/stdout.js b/samples/stdout-helper/src/main/webapp/teavm/stdout.js index 9e1116858..05af1d9d6 100644 --- a/samples/stdout-helper/src/main/webapp/teavm/stdout.js +++ b/samples/stdout-helper/src/main/webapp/teavm/stdout.js @@ -1,18 +1,20 @@ let $rt_stdoutBuffer = ""; -function $rt_putStdoutCustom(str) { +function $rt_putStdoutCustom(msg) { let index = 0; while (true) { let next = msg.indexOf('\n', index); if (next < 0) { break; } - let line = buffer + msg.substring(index, next); + let line = $rt_stdoutBuffer + msg.substring(index, next); let lineElem = document.createElement("div"); let stdoutElem = document.getElementById("stdout"); lineElem.appendChild(document.createTextNode(line)); stdoutElem.appendChild(lineElem); - buffer = ""; + stdoutElem.scrollTop = stdoutElem.scrollHeight; + $rt_stdoutBuffer = ""; index = next + 1; } + $rt_stdoutBuffer += msg.substring(index); } this.$rt_putStdoutCustom = $rt_putStdoutCustom; \ No newline at end of file