瀏覽代碼

Fix console not staying at bottom if new line spanned two lines (#302)

Paulus Schoutsen 2 年之前
父節點
當前提交
de749bd83e
共有 1 個文件被更改,包括 6 次插入5 次删除
  1. 6 5
      src/util/console-color.ts

+ 6 - 5
src/util/console-color.ts

@@ -178,13 +178,14 @@ export class ColoredConsole {
         }
       }
     }
+    const atBottom =
+      this.targetElement.scrollTop >
+      this.targetElement.scrollHeight - this.targetElement.offsetHeight - 50;
+
     addSpan(line.substring(i));
 
-    if (
-      this.targetElement.scrollTop + 56 >=
-      this.targetElement.scrollHeight - this.targetElement.offsetHeight
-    ) {
-      // at bottom
+    // Keep scroll at bottom
+    if (atBottom) {
       this.targetElement.scrollTop = this.targetElement.scrollHeight;
     }
   }