Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent accidental script modifications on error #79517

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading