diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 9a8164a3cf2..4843faf46fe 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -479,6 +479,8 @@ void ScriptEditor::_goto_script_line(Ref p_script, int p_line) { ScriptEditorBase *current = _get_current_editor(); if (ScriptTextEditor *script_text_editor = Object::cast_to(current)) { script_text_editor->goto_line_centered(p_line); + // In case user is holding some key, disable script editor input to prevent accidentally modifying the script. + script_text_editor->block_input_until_released(); } else if (current) { current->goto_line(p_line, true); } diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 38f3d865d45..fd483503b6b 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -1628,6 +1628,12 @@ void ScriptTextEditor::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { code_editor->get_text_editor()->set_gutter_width(connection_gutter, code_editor->get_text_editor()->get_line_height()); } break; + case NOTIFICATION_INTERNAL_PROCESS: { + if (!Input::get_singleton()->is_anything_pressed() && OS::get_singleton()->get_unix_time() - block_input_time > 0.25) { + code_editor->get_text_editor()->set_editable(true); + set_process_internal(false); + } + } } } @@ -2509,3 +2515,12 @@ void ScriptTextEditor::register_editor() { void ScriptTextEditor::validate() { this->code_editor->validate_script(); } + +void ScriptTextEditor::block_input_until_released() { + if (!Input::get_singleton()->is_anything_pressed()) { + return; + } + code_editor->get_text_editor()->set_editable(false); + block_input_time = OS::get_singleton()->get_unix_time(); + set_process_internal(true); +} diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h index 8c0ba6d7e66..3a67dbb2bad 100644 --- a/editor/plugins/script_text_editor.h +++ b/editor/plugins/script_text_editor.h @@ -106,6 +106,7 @@ class ScriptTextEditor : public ScriptEditorBase { String color_args; bool theme_loaded = false; + double block_input_time = 0.0; enum { EDIT_UNDO, @@ -259,6 +260,8 @@ class ScriptTextEditor : public ScriptEditorBase { virtual void validate() override; + void block_input_until_released(); + ScriptTextEditor(); ~ScriptTextEditor(); };