浏览代码

TextEditor: Debounce update_preview() in on_change event

This avoids lag spikes when undoing/redoing large chunks of HTML/CSS
with the HTML preview open. This had been bugging me when reducing
LibWeb issues in the text editor. The debounce timeout is 100ms
so the delay should not be noticeable.
MacDue 3 年之前
父节点
当前提交
8266ebf3c6
共有 1 个文件被更改,包括 4 次插入2 次删除
  1. 4 2
      Userland/Applications/TextEditor/MainWidget.cpp

+ 4 - 2
Userland/Applications/TextEditor/MainWidget.cpp

@@ -11,6 +11,7 @@
 #include <AK/URL.h>
 #include <Applications/TextEditor/TextEditorWindowGML.h>
 #include <LibConfig/Client.h>
+#include <LibCore/Debounce.h>
 #include <LibCore/File.h>
 #include <LibCpp/SyntaxHighlighter.h>
 #include <LibDesktop/Launcher.h>
@@ -63,9 +64,10 @@ MainWidget::MainWidget()
     else
         VERIFY_NOT_REACHED();
 
-    m_editor->on_change = [this] {
+    m_editor->on_change = Core::debounce([this] {
         update_preview();
-    };
+    },
+        100);
 
     m_editor->on_modified_change = [this](bool modified) {
         window()->set_modified(modified);