Fix nested actions in EditorUndoRedoManager

This commit is contained in:
kobewi
2022-10-28 02:54:55 +02:00
parent 0486810697
commit d7ebf725c9
4 changed files with 20 additions and 4 deletions

View File

@@ -109,9 +109,14 @@ EditorUndoRedoManager::History &EditorUndoRedoManager::get_history_for_object(Ob
}
void EditorUndoRedoManager::create_action_for_history(const String &p_name, int p_history_id, UndoRedo::MergeMode p_mode) {
pending_action.action_name = p_name;
pending_action.timestamp = OS::get_singleton()->get_unix_time();
pending_action.merge_mode = p_mode;
if (pending_action.history_id != INVALID_HISTORY) {
// Nested action.
p_history_id = pending_action.history_id;
} else {
pending_action.action_name = p_name;
pending_action.timestamp = OS::get_singleton()->get_unix_time();
pending_action.merge_mode = p_mode;
}
if (p_history_id != INVALID_HISTORY) {
pending_action.history_id = p_history_id;
@@ -228,6 +233,12 @@ void EditorUndoRedoManager::commit_action(bool p_execute) {
history.undo_redo->commit_action(p_execute);
history.redo_stack.clear();
if (history.undo_redo->get_action_level() > 0) {
// Nested action.
is_committing = false;
return;
}
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) {