Skip to content

Commit f00d0e6

Browse files
Ensure correct unlocking of script editor history
1 parent 78d9194 commit f00d0e6

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

doc/classes/Object.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@
476476
node.CallDeferred(Node3D.MethodName.Rotate, new Vector3(1f, 0f, 0f), 1.571f);
477477
[/csharp]
478478
[/codeblocks]
479+
For methods which are deferred from the same thread, the order of execution at idle time is identical to the order in which [code]call_deferred[/code] was called.
479480
See also [method Callable.call_deferred].
480481
[b]Note:[/b] In C#, [param method] must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the [code]MethodName[/code] class to avoid allocating a new [StringName] on each call.
481482
[b]Note:[/b] If you're looking to delay the function call by a frame, refer to the [signal SceneTree.process_frame] and [signal SceneTree.physics_frame] signals.

editor/script/script_editor_plugin.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,6 @@ void ScriptEditor::_save_history() {
676676
void ScriptEditor::_save_previous_state(Dictionary p_state) {
677677
if (lock_history) {
678678
// Done as a result of a deferred call triggered by set_edit_state().
679-
lock_history = false;
680679
return;
681680
}
682681

@@ -3853,6 +3852,10 @@ void ScriptEditor::_update_selected_editor_menu() {
38533852
}
38543853
}
38553854

3855+
void ScriptEditor::_unlock_history() {
3856+
lock_history = false;
3857+
}
3858+
38563859
void ScriptEditor::_update_history_pos(int p_new_pos) {
38573860
Node *n = tab_container->get_current_tab_control();
38583861

@@ -3872,6 +3875,10 @@ void ScriptEditor::_update_history_pos(int p_new_pos) {
38723875
if (seb) {
38733876
lock_history = true;
38743877
seb->set_edit_state(history[history_pos].state);
3878+
// `set_edit_state()` can modify the caret position which might trigger a
3879+
// request to save the history. Since `TextEdit::caret_changed` is emitted
3880+
// deferred, we need to defer unlocking of the history as well.
3881+
callable_mp(this, &ScriptEditor::_unlock_history).call_deferred();
38753882
seb->ensure_focus();
38763883

38773884
Ref<Script> scr = seb->get_edited_resource();

editor/script/script_editor_plugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ class ScriptEditor : public PanelContainer {
526526

527527
bool waiting_update_names;
528528
bool lock_history = false;
529+
void _unlock_history();
529530

530531
void _help_class_open(const String &p_class);
531532
void _help_class_goto(const String &p_desc);

0 commit comments

Comments
 (0)