summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorkobewi <kobewi4e@gmail.com>2023-03-06 01:24:42 +0100
committerYuri Sizov <yuris@humnom.net>2023-03-27 17:10:54 +0200
commitd91a3985ae44deea62a02956a17d04bfd40a3431 (patch)
tree0f3142a532ab91374bf36080c64c1ed9e612524e /editor
parent68e623459592d557893eddd3fa570d0b7cdf21f2 (diff)
Fix EditorUndoRedoManager's handling of MERGE_ENDS
(cherry picked from commit 38c50b4ed3c24a0bbe7327466a3069b1ac0df6a5)
Diffstat (limited to 'editor')
-rw-r--r--editor/editor_undo_redo_manager.cpp32
1 files changed, 26 insertions, 6 deletions
diff --git a/editor/editor_undo_redo_manager.cpp b/editor/editor_undo_redo_manager.cpp
index f65f905b25..facd1fd6d3 100644
--- a/editor/editor_undo_redo_manager.cpp
+++ b/editor/editor_undo_redo_manager.cpp
@@ -248,12 +248,32 @@ void EditorUndoRedoManager::commit_action(bool p_execute) {
}
if (!history.undo_stack.is_empty()) {
- const Action &prev_action = history.undo_stack.back()->get();
- if (pending_action.merge_mode != UndoRedo::MERGE_DISABLE && pending_action.merge_mode == prev_action.merge_mode && pending_action.action_name == prev_action.action_name) {
- // Discard action if it should be merged (UndoRedo handles merging internally).
- pending_action = Action();
- is_committing = false;
- return;
+ // Discard action if it should be merged (UndoRedo handles merging internally).
+ switch (pending_action.merge_mode) {
+ case UndoRedo::MERGE_DISABLE:
+ break; // Nothing to do here.
+ case UndoRedo::MERGE_ENDS: {
+ if (history.undo_stack.size() < 2) {
+ break;
+ }
+
+ const Action &prev_action = history.undo_stack.back()->get();
+ const Action &pre_prev_action = history.undo_stack.back()->prev()->get();
+ if (pending_action.merge_mode == prev_action.merge_mode && pending_action.merge_mode == pre_prev_action.merge_mode &&
+ pending_action.action_name == prev_action.action_name && pending_action.action_name == pre_prev_action.action_name) {
+ pending_action = Action();
+ is_committing = false;
+ return;
+ }
+ } break;
+ case UndoRedo::MERGE_ALL: {
+ const Action &prev_action = history.undo_stack.back()->get();
+ if (pending_action.merge_mode == prev_action.merge_mode && pending_action.action_name == prev_action.action_name) {
+ pending_action = Action();
+ is_committing = false;
+ return;
+ }
+ } break;
}
}