Skip to content

Commit 0a9d8f0

Browse files
committed
Merge pull request godotengine#97410 from KoBeWi/it's_redover
Discard additional redo on commiting actions
2 parents ca1a390 + 7aef30c commit 0a9d8f0

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

core/object/undo_redo.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void UndoRedo::Operation::delete_reference() {
4848
}
4949
}
5050

51-
void UndoRedo::_discard_redo() {
51+
void UndoRedo::discard_redo() {
5252
if (current_action == actions.size() - 1) {
5353
return;
5454
}
@@ -89,7 +89,7 @@ void UndoRedo::create_action(const String &p_name, MergeMode p_mode, bool p_back
8989
uint64_t ticks = OS::get_singleton()->get_ticks_msec();
9090

9191
if (action_level == 0) {
92-
_discard_redo();
92+
discard_redo();
9393

9494
// Check if the merge operation is valid
9595
if (p_mode != MERGE_DISABLE && actions.size() && actions[actions.size() - 1].name == p_name && actions[actions.size() - 1].backward_undo_ops == p_backward_undo_ops && actions[actions.size() - 1].last_tick + 800 > ticks) {
@@ -288,7 +288,7 @@ void UndoRedo::end_force_keep_in_merge_ends() {
288288
}
289289

290290
void UndoRedo::_pop_history_tail() {
291-
_discard_redo();
291+
discard_redo();
292292

293293
if (!actions.size()) {
294294
return;
@@ -455,7 +455,7 @@ String UndoRedo::get_action_name(int p_id) {
455455

456456
void UndoRedo::clear_history(bool p_increase_version) {
457457
ERR_FAIL_COND(action_level > 0);
458-
_discard_redo();
458+
discard_redo();
459459

460460
while (actions.size()) {
461461
_pop_history_tail();

core/object/undo_redo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ class UndoRedo : public Object {
129129
int get_current_action();
130130
String get_action_name(int p_id);
131131
void clear_history(bool p_increase_version = true);
132+
void discard_redo();
132133

133134
bool has_undo() const;
134135
bool has_redo() const;

editor/editor_undo_redo_manager.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,22 @@ void EditorUndoRedoManager::commit_action(bool p_execute) {
264264
history.undo_stack.push_back(pending_action);
265265
}
266266

267+
if (history.id != GLOBAL_HISTORY) {
268+
// Clear global redo, to avoid unexpected actions when redoing.
269+
History &global = get_or_create_history(GLOBAL_HISTORY);
270+
global.redo_stack.clear();
271+
global.undo_redo->discard_redo();
272+
} else {
273+
// On global actions, clear redo of all scenes instead.
274+
for (KeyValue<int, History> &E : history_map) {
275+
if (E.key == GLOBAL_HISTORY) {
276+
continue;
277+
}
278+
E.value.redo_stack.clear();
279+
E.value.undo_redo->discard_redo();
280+
}
281+
}
282+
267283
pending_action = Action();
268284
is_committing = false;
269285
emit_signal(SNAME("history_changed"));

0 commit comments

Comments
 (0)