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 Jan 12, 2024
1 parent 26b1fd0 commit ce6d5c0
Show file tree
Hide file tree
Showing 3 changed files with 20 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 @@ -479,6 +479,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
15 changes: 15 additions & 0 deletions editor/plugins/script_text_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}

Expand Down Expand Up @@ -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);
}
3 changes: 3 additions & 0 deletions editor/plugins/script_text_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class ScriptTextEditor : public ScriptEditorBase {
String color_args;

bool theme_loaded = false;
double block_input_time = 0.0;

enum {
EDIT_UNDO,
Expand Down Expand Up @@ -259,6 +260,8 @@ class ScriptTextEditor : public ScriptEditorBase {

virtual void validate() override;

void block_input_until_released();

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

0 comments on commit ce6d5c0

Please sign in to comment.