mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-26 19:32:06 -05:00
LibGUI: Debounce TextDocument undo stack
This replaces the repeating 2-sec timer with a debounced single-shot timer on user input.
This commit is contained in:
parent
824bfa9600
commit
97d0028098
2 changed files with 7 additions and 5 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue