mirror of
https://github.com/godotengine/godot.git
synced 2024-11-27 09:16:35 +08:00
Merge pull request #84557 from TheSofox/undo-history-sync-fix
Fix for stopping the Undo History being desynchronised from actual Undo queue
This commit is contained in:
commit
96fa86f9a0
@ -463,6 +463,10 @@ bool UndoRedo::has_redo() const {
|
||||
return (current_action + 1) < actions.size();
|
||||
}
|
||||
|
||||
bool UndoRedo::is_merging() const {
|
||||
return merging;
|
||||
}
|
||||
|
||||
uint64_t UndoRedo::get_version() const {
|
||||
return version;
|
||||
}
|
||||
|
@ -131,6 +131,8 @@ public:
|
||||
bool has_undo() const;
|
||||
bool has_redo() const;
|
||||
|
||||
bool is_merging() const;
|
||||
|
||||
uint64_t get_version() const;
|
||||
|
||||
void set_commit_notify_callback(CommitNotifyCallback p_callback, void *p_ud);
|
||||
|
@ -239,6 +239,7 @@ void EditorUndoRedoManager::commit_action(bool p_execute) {
|
||||
is_committing = true;
|
||||
|
||||
History &history = get_or_create_history(pending_action.history_id);
|
||||
bool merging = history.undo_redo->is_merging();
|
||||
history.undo_redo->commit_action(p_execute);
|
||||
history.redo_stack.clear();
|
||||
|
||||
@ -248,39 +249,10 @@ void EditorUndoRedoManager::commit_action(bool p_execute) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!history.undo_stack.is_empty()) {
|
||||
// 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;
|
||||
emit_signal(SNAME("history_changed"));
|
||||
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;
|
||||
emit_signal(SNAME("history_changed"));
|
||||
return;
|
||||
}
|
||||
} break;
|
||||
}
|
||||
if (!merging) {
|
||||
history.undo_stack.push_back(pending_action);
|
||||
}
|
||||
|
||||
history.undo_stack.push_back(pending_action);
|
||||
pending_action = Action();
|
||||
is_committing = false;
|
||||
emit_signal(SNAME("history_changed"));
|
||||
|
Loading…
Reference in New Issue
Block a user