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(*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 m_lines; Vector m_spans;