Skip to content

Commit

Permalink
Prevent accidental script modifications on error
Browse files Browse the repository at this point in the history
  • Loading branch information
KoBeWi committed Jul 15, 2023
1 parent a758388 commit 69ef6f8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions editor/plugins/script_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,8 @@ void ScriptEditor::_goto_script_line(Ref<RefCounted> p_script, int p_line) {
ScriptEditorBase *current = _get_current_editor();
if (ScriptTextEditor *script_text_editor = Object::cast_to<ScriptTextEditor>(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);
}
Expand Down
14 changes: 14 additions & 0 deletions editor/plugins/script_text_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1522,6 +1522,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()) {
code_editor->get_text_editor()->set_editable(true);
set_process_internal(false);
}
}
}
}

Expand Down Expand Up @@ -2347,3 +2353,11 @@ 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);
set_process_internal(true);
}
2 changes: 2 additions & 0 deletions editor/plugins/script_text_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ class ScriptTextEditor : public ScriptEditorBase {

virtual void validate() override;

void block_input_until_released();

ScriptTextEditor();
~ScriptTextEditor();
};
Expand Down

0 comments on commit 69ef6f8

Please sign in to comment.