diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 8b3c537fe31..848921d870b 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -1217,6 +1217,11 @@ void CodeTextEditor::goto_line_selection(int p_line, int p_begin, int p_end) { text_editor->select(p_line, p_begin, p_line, p_end); } +void CodeTextEditor::goto_line_centered(int p_line) { + goto_line(p_line); + text_editor->call_deferred("center_viewport_to_cursor"); +} + void CodeTextEditor::set_executing_line(int p_line) { text_editor->set_executing_line(p_line); } diff --git a/editor/code_editor.h b/editor/code_editor.h index ce219f340cf..c0989f9704c 100644 --- a/editor/code_editor.h +++ b/editor/code_editor.h @@ -219,6 +219,7 @@ public: void goto_line(int p_line); void goto_line_selection(int p_line, int p_begin, int p_end); + void goto_line_centered(int p_line); void set_executing_line(int p_line); void clear_executing_line(); diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index d5e21321c36..1b00889e9a5 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -306,8 +306,11 @@ void ScriptEditor::_goto_script_line(REF p_script, int p_line) { editor->push_item(p_script.ptr()); ScriptEditorBase *current = _get_current_editor(); - if (current) + if (ScriptTextEditor *script_text_editor = Object::cast_to(current)) { + script_text_editor->goto_line_centered(p_line); + } 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 ce0859a1f60..2c2b1508c34 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -487,6 +487,11 @@ void ScriptTextEditor::goto_line_selection(int p_line, int p_begin, int p_end) { code_editor->goto_line_selection(p_line, p_begin, p_end); } +void ScriptTextEditor::goto_line_centered(int p_line) { + + code_editor->goto_line_centered(p_line); +} + void ScriptTextEditor::set_executing_line(int p_line) { code_editor->set_executing_line(p_line); } diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h index 24d40a5eece..89975e061e0 100644 --- a/editor/plugins/script_text_editor.h +++ b/editor/plugins/script_text_editor.h @@ -201,6 +201,7 @@ public: virtual void goto_line(int p_line, bool p_with_error = false); void goto_line_selection(int p_line, int p_begin, int p_end); + void goto_line_centered(int p_line); virtual void set_executing_line(int p_line); virtual void clear_executing_line(); diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 36d7dad1d3c..1e7066e1840 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -6452,6 +6452,7 @@ void TextEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("get_text"), &TextEdit::get_text); ClassDB::bind_method(D_METHOD("get_line", "line"), &TextEdit::get_line); + ClassDB::bind_method(D_METHOD("center_viewport_to_cursor"), &TextEdit::center_viewport_to_cursor); ClassDB::bind_method(D_METHOD("cursor_set_column", "column", "adjust_viewport"), &TextEdit::cursor_set_column, DEFVAL(true)); ClassDB::bind_method(D_METHOD("cursor_set_line", "line", "adjust_viewport", "can_be_hidden", "wrap_index"), &TextEdit::cursor_set_line, DEFVAL(true), DEFVAL(true), DEFVAL(0));