summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos César Neves Enumo <paker_wreah@hotmail.com>2021-05-05 12:21:45 -0300
committerAndreas Kling <kling@serenityos.org>2021-05-06 08:40:26 +0200
commit67537bfc80e0efefd555bf1b5cda4eac1a01fbdb (patch)
treeacbc53425bbe7e0307d14708355d6088255bf0b8
parent88803b2e3424a5f197f57252c4bc1b7f7b635d96 (diff)
downloadserenity-67537bfc80e0efefd555bf1b5cda4eac1a01fbdb.zip
LibGUI: Clear undo stack when opening a new document
-rw-r--r--Userland/Libraries/LibGUI/TextDocument.cpp1
-rw-r--r--Userland/Libraries/LibGUI/UndoStack.cpp6
-rw-r--r--Userland/Libraries/LibGUI/UndoStack.h2
3 files changed, 9 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/TextDocument.cpp b/Userland/Libraries/LibGUI/TextDocument.cpp
index 6799e5c90d..27042d1696 100644
--- a/Userland/Libraries/LibGUI/TextDocument.cpp
+++ b/Userland/Libraries/LibGUI/TextDocument.cpp
@@ -41,6 +41,7 @@ TextDocument::~TextDocument()
bool TextDocument::set_text(const StringView& text)
{
m_client_notifications_enabled = false;
+ m_undo_stack.clear();
m_spans.clear();
remove_all_lines();
diff --git a/Userland/Libraries/LibGUI/UndoStack.cpp b/Userland/Libraries/LibGUI/UndoStack.cpp
index 7267c83bf4..7f32d3e4fb 100644
--- a/Userland/Libraries/LibGUI/UndoStack.cpp
+++ b/Userland/Libraries/LibGUI/UndoStack.cpp
@@ -80,4 +80,10 @@ void UndoStack::finalize_current_combo()
m_stack.prepend(move(undo_commands_container));
}
+void UndoStack::clear()
+{
+ m_stack.clear();
+ m_stack_index = 0;
+}
+
}
diff --git a/Userland/Libraries/LibGUI/UndoStack.h b/Userland/Libraries/LibGUI/UndoStack.h
index 0921d835a5..f854171c83 100644
--- a/Userland/Libraries/LibGUI/UndoStack.h
+++ b/Userland/Libraries/LibGUI/UndoStack.h
@@ -26,6 +26,8 @@ public:
void finalize_current_combo();
+ void clear();
+
private:
struct UndoCommandsContainer {
NonnullOwnPtrVector<Command> m_undo_vector;