Преглед на файлове

LibGUI: Clear undo stack when opening a new document

Carlos César Neves Enumo преди 4 години
родител
ревизия
67537bfc80
променени са 3 файла, в които са добавени 9 реда и са изтрити 0 реда
  1. 1 0
      Userland/Libraries/LibGUI/TextDocument.cpp
  2. 6 0
      Userland/Libraries/LibGUI/UndoStack.cpp
  3. 2 0
      Userland/Libraries/LibGUI/UndoStack.h

+ 1 - 0
Userland/Libraries/LibGUI/TextDocument.cpp

@@ -41,6 +41,7 @@ TextDocument::~TextDocument()
 bool TextDocument::set_text(const StringView& text)
 bool TextDocument::set_text(const StringView& text)
 {
 {
     m_client_notifications_enabled = false;
     m_client_notifications_enabled = false;
+    m_undo_stack.clear();
     m_spans.clear();
     m_spans.clear();
     remove_all_lines();
     remove_all_lines();
 
 

+ 6 - 0
Userland/Libraries/LibGUI/UndoStack.cpp

@@ -80,4 +80,10 @@ void UndoStack::finalize_current_combo()
     m_stack.prepend(move(undo_commands_container));
     m_stack.prepend(move(undo_commands_container));
 }
 }
 
 
+void UndoStack::clear()
+{
+    m_stack.clear();
+    m_stack_index = 0;
+}
+
 }
 }

+ 2 - 0
Userland/Libraries/LibGUI/UndoStack.h

@@ -26,6 +26,8 @@ public:
 
 
     void finalize_current_combo();
     void finalize_current_combo();
 
 
+    void clear();
+
 private:
 private:
     struct UndoCommandsContainer {
     struct UndoCommandsContainer {
         NonnullOwnPtrVector<Command> m_undo_vector;
         NonnullOwnPtrVector<Command> m_undo_vector;