diff options
author | Carlos César Neves Enumo <paker_wreah@hotmail.com> | 2021-05-02 17:57:58 -0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-03 08:43:10 +0200 |
commit | 97d00280982c7ea51ada6a4a4068cb23eb9c9097 (patch) | |
tree | b51b8740d1619403b9f9fe97b7236901df0bf07c /Userland/Libraries | |
parent | 824bfa9600f0e98a0550dcbc992edaa0cd59fba1 (diff) | |
download | serenity-97d00280982c7ea51ada6a4a4068cb23eb9c9097.zip |
LibGUI: Debounce TextDocument undo stack
This replaces the repeating 2-sec timer with a debounced single-shot
timer on user input.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibGUI/TextDocument.cpp | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/TextDocument.h | 2 |
2 files changed, 7 insertions, 5 deletions
diff --git a/Userland/Libraries/LibGUI/TextDocument.cpp b/Userland/Libraries/LibGUI/TextDocument.cpp index f4c425c078..6799e5c90d 100644 --- a/Userland/Libraries/LibGUI/TextDocument.cpp +++ b/Userland/Libraries/LibGUI/TextDocument.cpp @@ -28,10 +28,9 @@ TextDocument::TextDocument(Client* client) append_line(make<TextDocumentLine>(*this)); set_modified(false); - // FIXME: Instead of a repeating timer, we should punt a deferred single-shot 2-sec timer on user input. - m_undo_timer = Core::Timer::construct( + m_undo_timer = Core::Timer::create_single_shot( 2000, [this] { - update_undo_timer(); + update_undo(); }); } @@ -311,6 +310,9 @@ void TextDocument::notify_did_change() { set_modified(true); + if (m_undo_timer) + m_undo_timer->restart(); + if (m_client_notifications_enabled) { for (auto* client : m_clients) client->document_did_change(); @@ -791,7 +793,7 @@ void RemoveTextCommand::undo() m_document.set_all_cursors(new_cursor); } -void TextDocument::update_undo_timer() +void TextDocument::update_undo() { m_undo_stack.finalize_current_combo(); } diff --git a/Userland/Libraries/LibGUI/TextDocument.h b/Userland/Libraries/LibGUI/TextDocument.h index 0b11739244..6fa9b1783e 100644 --- a/Userland/Libraries/LibGUI/TextDocument.h +++ b/Userland/Libraries/LibGUI/TextDocument.h @@ -129,7 +129,7 @@ protected: explicit TextDocument(Client* client); private: - void update_undo_timer(); + void update_undo(); NonnullOwnPtrVector<TextDocumentLine> m_lines; Vector<TextDocumentSpan> m_spans; |