diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index d24b1edd709..e5f422b7fdc 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -1296,23 +1296,29 @@ void CodeTextEditor::toggle_inline_comment(const String &delimiter) { text_editor->end_complex_operation(); } -void CodeTextEditor::goto_line(int p_line) { +void CodeTextEditor::goto_line(int p_line, int p_column) { text_editor->remove_secondary_carets(); text_editor->deselect(); - text_editor->unfold_line(p_line); - callable_mp((TextEdit *)text_editor, &TextEdit::set_caret_line).call_deferred(p_line, true, true, 0, 0); + text_editor->unfold_line(CLAMP(p_line, 0, text_editor->get_line_count() - 1)); + text_editor->set_caret_line(p_line, false); + text_editor->set_caret_column(p_column, false); + // Defer in case the CodeEdit was just created and needs to be resized. + callable_mp((TextEdit *)text_editor, &TextEdit::adjust_viewport_to_caret).call_deferred(0); } void CodeTextEditor::goto_line_selection(int p_line, int p_begin, int p_end) { text_editor->remove_secondary_carets(); - text_editor->unfold_line(p_line); - callable_mp((TextEdit *)text_editor, &TextEdit::set_caret_line).call_deferred(p_line, true, true, 0, 0); - callable_mp((TextEdit *)text_editor, &TextEdit::set_caret_column).call_deferred(p_begin, true, 0); + text_editor->unfold_line(CLAMP(p_line, 0, text_editor->get_line_count() - 1)); text_editor->select(p_line, p_begin, p_line, p_end); + callable_mp((TextEdit *)text_editor, &TextEdit::adjust_viewport_to_caret).call_deferred(0); } -void CodeTextEditor::goto_line_centered(int p_line) { - goto_line(p_line); +void CodeTextEditor::goto_line_centered(int p_line, int p_column) { + text_editor->remove_secondary_carets(); + text_editor->deselect(); + text_editor->unfold_line(CLAMP(p_line, 0, text_editor->get_line_count() - 1)); + text_editor->set_caret_line(p_line, false); + text_editor->set_caret_column(p_column, false); callable_mp((TextEdit *)text_editor, &TextEdit::center_viewport_to_caret).call_deferred(0); } @@ -1440,13 +1446,7 @@ void CodeTextEditor::goto_error() { corrected_column -= tab_count * (indent_size - 1); } - if (text_editor->get_line_count() != error_line) { - text_editor->unfold_line(error_line); - } - text_editor->remove_secondary_carets(); - text_editor->set_caret_line(error_line); - text_editor->set_caret_column(corrected_column); - text_editor->center_viewport_to_caret(); + goto_line_centered(error_line, corrected_column); } } diff --git a/editor/code_editor.h b/editor/code_editor.h index 28f6944b669..d209d5c7a28 100644 --- a/editor/code_editor.h +++ b/editor/code_editor.h @@ -246,9 +246,9 @@ public: /// by adding or removing comment delimiter void toggle_inline_comment(const String &delimiter); - void goto_line(int p_line); + void goto_line(int p_line, int p_column = 0); void goto_line_selection(int p_line, int p_begin, int p_end); - void goto_line_centered(int p_line); + void goto_line_centered(int p_line, int p_column = 0); 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 c51eb44aee4..f19d0d75471 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -493,7 +493,7 @@ void ScriptEditor::_goto_script_line(Ref p_script, int p_line) { 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); + current->goto_line(p_line); } _save_history(); @@ -1857,17 +1857,13 @@ void ScriptEditor::get_breakpoints(List *p_breakpoints) { } void ScriptEditor::_members_overview_selected(int p_idx) { - ScriptEditorBase *se = _get_current_editor(); - if (!se) { - return; + int line = members_overview->get_item_metadata(p_idx); + ScriptEditorBase *current = _get_current_editor(); + if (ScriptTextEditor *script_text_editor = Object::cast_to(current)) { + script_text_editor->goto_line_centered(line); + } else if (current) { + current->goto_line(line); } - // Go to the member's line and reset the cursor column. We can't change scroll_position - // directly until we have gone to the line first, since code might be folded. - se->goto_line(members_overview->get_item_metadata(p_idx)); - Dictionary state = se->get_edit_state(); - state["column"] = 0; - state["scroll_position"] = members_overview->get_item_metadata(p_idx); - se->set_edit_state(state); } void ScriptEditor::_help_overview_selected(int p_idx) { diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index 9db1aff76ac..edddba7a696 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -170,7 +170,7 @@ public: virtual Variant get_edit_state() = 0; virtual void set_edit_state(const Variant &p_state) = 0; virtual Variant get_navigation_state() = 0; - virtual void goto_line(int p_line, bool p_with_error = false) = 0; + virtual void goto_line(int p_line, int p_column = 0) = 0; virtual void set_executing_line(int p_line) = 0; virtual void clear_executing_line() = 0; virtual void trim_trailing_whitespace() = 0; diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 070471f3f3e..8d61176af0d 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -302,16 +302,14 @@ void ScriptTextEditor::_warning_clicked(const Variant &p_line) { void ScriptTextEditor::_error_clicked(const Variant &p_line) { if (p_line.get_type() == Variant::INT) { - code_editor->get_text_editor()->remove_secondary_carets(); - code_editor->get_text_editor()->set_caret_line(p_line.operator int64_t()); + goto_line_centered(p_line.operator int64_t()); } else if (p_line.get_type() == Variant::DICTIONARY) { Dictionary meta = p_line.operator Dictionary(); const String path = meta["path"].operator String(); const int line = meta["line"].operator int64_t(); const int column = meta["column"].operator int64_t(); if (path.is_empty()) { - code_editor->get_text_editor()->remove_secondary_carets(); - code_editor->get_text_editor()->set_caret_line(line); + goto_line_centered(line, column); } else { Ref scr = ResourceLoader::load(path); if (!scr.is_valid()) { @@ -456,16 +454,16 @@ void ScriptTextEditor::tag_saved_version() { code_editor->get_text_editor()->tag_saved_version(); } -void ScriptTextEditor::goto_line(int p_line, bool p_with_error) { - code_editor->goto_line(p_line); +void ScriptTextEditor::goto_line(int p_line, int p_column) { + code_editor->goto_line(p_line, p_column); } 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::goto_line_centered(int p_line, int p_column) { + code_editor->goto_line_centered(p_line, p_column); } void ScriptTextEditor::set_executing_line(int p_line) { @@ -919,8 +917,7 @@ void ScriptTextEditor::_breakpoint_item_pressed(int p_idx) { if (p_idx < 4) { // Any item before the separator. _edit_option(breakpoints_menu->get_item_id(p_idx)); } else { - code_editor->goto_line(breakpoints_menu->get_item_metadata(p_idx)); - callable_mp((TextEdit *)code_editor->get_text_editor(), &TextEdit::center_viewport_to_caret).call_deferred(0); // Needs to be deferred, because goto uses call_deferred(). + code_editor->goto_line_centered(breakpoints_menu->get_item_metadata(p_idx)); } } diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h index 8c2ec1561b3..7aa0726479f 100644 --- a/editor/plugins/script_text_editor.h +++ b/editor/plugins/script_text_editor.h @@ -234,9 +234,9 @@ public: virtual void convert_indent() override; virtual void tag_saved_version() override; - virtual void goto_line(int p_line, bool p_with_error = false) override; + virtual void goto_line(int p_line, int p_column = 0) override; void goto_line_selection(int p_line, int p_begin, int p_end); - void goto_line_centered(int p_line); + void goto_line_centered(int p_line, int p_column = 0); virtual void set_executing_line(int p_line) override; virtual void clear_executing_line() override; diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp index ecdc4acf47c..cb1f6c1ec63 100644 --- a/editor/plugins/text_editor.cpp +++ b/editor/plugins/text_editor.cpp @@ -304,8 +304,8 @@ void TextEditor::tag_saved_version() { code_editor->get_text_editor()->tag_saved_version(); } -void TextEditor::goto_line(int p_line, bool p_with_error) { - code_editor->goto_line(p_line); +void TextEditor::goto_line(int p_line, int p_column) { + code_editor->goto_line(p_line, p_column); } void TextEditor::goto_line_selection(int p_line, int p_begin, int p_end) { diff --git a/editor/plugins/text_editor.h b/editor/plugins/text_editor.h index 268e5c32b4d..1acec4e9597 100644 --- a/editor/plugins/text_editor.h +++ b/editor/plugins/text_editor.h @@ -129,7 +129,7 @@ public: virtual PackedInt32Array get_breakpoints() override; virtual void set_breakpoint(int p_line, bool p_enabled) override{}; virtual void clear_breakpoints() override{}; - virtual void goto_line(int p_line, bool p_with_error = false) override; + virtual void goto_line(int p_line, int p_column = 0) override; void goto_line_selection(int p_line, int p_begin, int p_end); virtual void set_executing_line(int p_line) override; virtual void clear_executing_line() override; diff --git a/editor/plugins/text_shader_editor.cpp b/editor/plugins/text_shader_editor.cpp index 276c57533f7..9453b5a4b7a 100644 --- a/editor/plugins/text_shader_editor.cpp +++ b/editor/plugins/text_shader_editor.cpp @@ -779,7 +779,7 @@ void TextShaderEditor::_show_warnings_panel(bool p_show) { void TextShaderEditor::_warning_clicked(const Variant &p_line) { if (p_line.get_type() == Variant::INT) { - code_editor->get_text_editor()->set_caret_line(p_line.operator int64_t()); + code_editor->goto_line_centered(p_line.operator int64_t()); } }