Skip to content

Commit

Permalink
Merge pull request #94474 from dalexeev/editor-fix-jump-to-error-column
Browse files Browse the repository at this point in the history
Editor: Consider tabs when calculating column for jump to error
  • Loading branch information
akien-mga committed Jul 17, 2024
2 parents 6d7ef2c + 063a362 commit da4f6e4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 10 additions & 1 deletion editor/code_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1431,12 +1431,21 @@ Point2i CodeTextEditor::get_error_pos() const {

void CodeTextEditor::goto_error() {
if (!error->get_text().is_empty()) {
int corrected_column = error_column;

const String line_text = text_editor->get_line(error_line);
const int indent_size = text_editor->get_indent_size();
if (indent_size > 1) {
const int tab_count = line_text.length() - line_text.lstrip("\t").length();
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(error_column);
text_editor->set_caret_column(corrected_column);
text_editor->center_viewport_to_caret();
}
}
Expand Down
11 changes: 10 additions & 1 deletion editor/plugins/script_text_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,16 @@ void ScriptTextEditor::_error_clicked(const Variant &p_line) {
if (!scr.is_valid()) {
EditorNode::get_singleton()->show_warning(TTR("Could not load file at:") + "\n\n" + path, TTR("Error!"));
} else {
ScriptEditor::get_singleton()->edit(scr, line, column);
int corrected_column = column;

const String line_text = code_editor->get_text_editor()->get_line(line);
const int indent_size = code_editor->get_text_editor()->get_indent_size();
if (indent_size > 1) {
const int tab_count = line_text.length() - line_text.lstrip("\t").length();
corrected_column -= tab_count * (indent_size - 1);
}

ScriptEditor::get_singleton()->edit(scr, line, corrected_column);
}
}
}
Expand Down

0 comments on commit da4f6e4

Please sign in to comment.