1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:57:44 +00:00

LibGUI: Reverse internal direction of GUI::UndoStack

The undo stack was very difficult to understand as it grew by adding
new undo commands to the front of the internal vector. This meant we
had to keep updating indices as the stack grew and shrank.

This patch makes the internal vector grow by appending instead.
This commit is contained in:
Andreas Kling 2021-05-08 13:09:24 +02:00
parent 2ef4fbc5c1
commit 74a4571f02
2 changed files with 46 additions and 51 deletions

View file

@ -18,8 +18,8 @@ public:
void push(NonnullOwnPtr<Command>&&);
bool can_undo() const { return m_stack_index < m_stack.size() && !m_stack.is_empty(); }
bool can_redo() const { return m_stack_index > 0 && !m_stack.is_empty() && m_stack[m_stack_index - 1].commands.size() > 0; }
bool can_undo() const;
bool can_redo() const;
void undo();
void redo();
@ -36,6 +36,8 @@ private:
NonnullOwnPtrVector<Command> commands;
};
void pop();
NonnullOwnPtrVector<Combo> m_stack;
size_t m_stack_index { 0 };
Optional<size_t> m_clean_index;