diff --git a/Userland/Libraries/LibGUI/Command.h b/Userland/Libraries/LibGUI/Command.h index 10d4a65cff..82626fd7cb 100644 --- a/Userland/Libraries/LibGUI/Command.h +++ b/Userland/Libraries/LibGUI/Command.h @@ -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; } diff --git a/Userland/Libraries/LibGUI/UndoStack.cpp b/Userland/Libraries/LibGUI/UndoStack.cpp index dec25df49c..2df8460070 100644 --- a/Userland/Libraries/LibGUI/UndoStack.cpp +++ b/Userland/Libraries/LibGUI/UndoStack.cpp @@ -77,6 +77,12 @@ void UndoStack::push(NonnullOwnPtr&& 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)