Skip to content

Commit

Permalink
Merge pull request #74460 from KoBeWi/undo_mergundo
Browse files Browse the repository at this point in the history
Fix EditorUndoRedoManager's handling of MERGE_ENDS
  • Loading branch information
akien-mga committed Mar 6, 2023
2 parents f408e7a + 38c50b4 commit 9fa3208
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions editor/editor_undo_redo_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 9fa3208

Please sign in to comment.