summaryrefslogtreecommitdiff
path: root/Userland/Applications/TextEditor
diff options
context:
space:
mode:
authorMacDue <macdue@dueutil.tech>2022-07-18 20:03:11 +0100
committerLinus Groh <mail@linusgroh.de>2022-07-19 11:10:02 +0100
commit8266ebf3c61c9c6a4aa98cbddd64814230b83d7d (patch)
tree599199bb3a3d48d84167e3728a5229bb72126ebc /Userland/Applications/TextEditor
parentcdcdc095df47c30d140d9d612390981d673141e9 (diff)
downloadserenity-8266ebf3c61c9c6a4aa98cbddd64814230b83d7d.zip
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.
Diffstat (limited to 'Userland/Applications/TextEditor')
-rw-r--r--Userland/Applications/TextEditor/MainWidget.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/Userland/Applications/TextEditor/MainWidget.cpp b/Userland/Applications/TextEditor/MainWidget.cpp
index 13d1eaf2e6..94b128d74f 100644
--- a/Userland/Applications/TextEditor/MainWidget.cpp
+++ b/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);