mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-21 02:08:12 +03:00
LibGUI: Support merging of adjacent commands on the UndoStack
When pushing a new command on an undo stack, we will now attempt to merge it into the stack's current command. Merging is implemented by overriding the "merge_with(Command const&)" virtual on GUI::Command. :^)
This commit is contained in:
parent
244665d99c
commit
ff912946ae
Notes:
sideshowbarker
2024-07-18 18:29:00 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/ff912946ae3
@ -19,6 +19,8 @@ public:
|
||||
|
||||
String action_text() const { return m_action_text; }
|
||||
|
||||
virtual bool merge_with(Command const&) { return false; }
|
||||
|
||||
protected:
|
||||
Command() { }
|
||||
void set_action_text(const String& text) { m_action_text = text; }
|
||||
|
@ -77,6 +77,12 @@ void UndoStack::push(NonnullOwnPtr<Command>&& command)
|
||||
finalize_current_combo();
|
||||
}
|
||||
|
||||
if (!m_stack.last().commands.is_empty()) {
|
||||
bool merged = m_stack.last().commands.last().merge_with(*command);
|
||||
if (merged)
|
||||
return;
|
||||
}
|
||||
|
||||
m_stack.last().commands.append(move(command));
|
||||
|
||||
if (on_state_change)
|
||||
|
Loading…
Reference in New Issue
Block a user