diff options
author | Carlos César Neves Enumo <paker_wreah@hotmail.com> | 2021-05-08 04:51:52 -0300 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-05-08 09:55:45 +0100 |
commit | 0b7e19e2bb34cceb340607f0b7f76b338d78767e (patch) | |
tree | 2f0f2fcd457d48a94b666d3af9ef2a988ca93123 | |
parent | 3c01de4f0bb9257bf539e916bfab63f6b5c36498 (diff) | |
download | serenity-0b7e19e2bb34cceb340607f0b7f76b338d78767e.zip |
LibGUI: Fix undo stack reporting wrong modified state
Since the `redo` action never goes back to `index: 0`,
we have to mark the clean index as being the current
non-empty index for the undo/redo navigation to work properly.
The problem is that if we never `undo`, the stack index stays at zero,
which is the empty container waiting for commands. In that situation,
if we save the document, it registers the clean index as being 1
(the non-empty index) but because the stack index has never left zero,
the document was being reported as modified, being out of sync with
the window modified state.
-rw-r--r-- | Userland/Libraries/LibGUI/UndoStack.cpp | 16 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/UndoStack.h | 2 |
2 files changed, 12 insertions, 6 deletions
diff --git a/Userland/Libraries/LibGUI/UndoStack.cpp b/Userland/Libraries/LibGUI/UndoStack.cpp index 47e584bbb5..0a6fd094da 100644 --- a/Userland/Libraries/LibGUI/UndoStack.cpp +++ b/Userland/Libraries/LibGUI/UndoStack.cpp @@ -92,16 +92,12 @@ void UndoStack::finalize_current_combo() void UndoStack::set_current_unmodified() { - // Skip empty container - if (can_undo() && m_stack[m_stack_index].commands.is_empty()) - m_clean_index = m_stack_index + 1; - else - m_clean_index = m_stack_index; + m_clean_index = non_empty_stack_index(); } bool UndoStack::is_current_modified() const { - return !m_clean_index.has_value() || m_stack_index != m_clean_index.value(); + return !m_clean_index.has_value() || non_empty_stack_index() != m_clean_index.value(); } void UndoStack::clear() @@ -111,4 +107,12 @@ void UndoStack::clear() m_clean_index.clear(); } +size_t UndoStack::non_empty_stack_index() const +{ + if (can_undo() && m_stack[m_stack_index].commands.is_empty()) + return m_stack_index + 1; + else + return m_stack_index; +} + } diff --git a/Userland/Libraries/LibGUI/UndoStack.h b/Userland/Libraries/LibGUI/UndoStack.h index 51b5e00436..db3065f183 100644 --- a/Userland/Libraries/LibGUI/UndoStack.h +++ b/Userland/Libraries/LibGUI/UndoStack.h @@ -32,6 +32,8 @@ public: void clear(); private: + size_t non_empty_stack_index() const; + struct Combo { NonnullOwnPtrVector<Command> commands; }; |