mirror of
https://github.com/godotengine/godot.git
synced 2024-11-21 19:42:43 +00:00
Fix goto line issues in code editor
This commit is contained in:
parent
3e0c10d393
commit
06b17a4d2f
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
@ -493,7 +493,7 @@ void ScriptEditor::_goto_script_line(Ref<RefCounted> p_script, int p_line) {
|
||||
if (ScriptTextEditor *script_text_editor = Object::cast_to<ScriptTextEditor>(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<String> *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<ScriptTextEditor>(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) {
|
||||
|
@ -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;
|
||||
|
@ -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<Resource> 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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user