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

Fix off-by-one issue where "Go to Line" dialog shows the incorrect line number (one less than the actual current line). #75523

Merged
merged 1 commit into from
Apr 2, 2023
Merged
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
19 changes: 11 additions & 8 deletions editor/code_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
void GotoLineDialog::popup_find_line(CodeEdit *p_edit) {
text_editor = p_edit;

line->set_text(itos(text_editor->get_caret_line()));
// Add 1 because text_editor->get_caret_line() starts from 0, but the editor user interface starts from 1.
line->set_text(itos(text_editor->get_caret_line() + 1));
line->select_all();
popup_centered(Size2(180, 80) * EDSCALE);
line->grab_focus();
Expand All @@ -53,12 +54,14 @@ int GotoLineDialog::get_line() const {
}

void GotoLineDialog::ok_pressed() {
if (get_line() < 1 || get_line() > text_editor->get_line_count()) {
// Subtract 1 because the editor user interface starts from 1, but text_editor->set_caret_line(n) starts from 0.
const int line_number = get_line() - 1;
if (line_number < 0 || line_number >= text_editor->get_line_count()) {
return;
}
text_editor->remove_secondary_carets();
text_editor->unfold_line(get_line() - 1);
text_editor->set_caret_line(get_line() - 1);
text_editor->unfold_line(line_number);
text_editor->set_caret_line(line_number);
hide();
}

Expand Down Expand Up @@ -1092,13 +1095,13 @@ void CodeTextEditor::remove_find_replace_bar() {
}

void CodeTextEditor::trim_trailing_whitespace() {
bool trimed_whitespace = false;
bool trimmed_whitespace = false;
YuriSizov marked this conversation as resolved.
Show resolved Hide resolved
for (int i = 0; i < text_editor->get_line_count(); i++) {
String line = text_editor->get_line(i);
if (line.ends_with(" ") || line.ends_with("\t")) {
if (!trimed_whitespace) {
if (!trimmed_whitespace) {
text_editor->begin_complex_operation();
trimed_whitespace = true;
trimmed_whitespace = true;
}

int end = 0;
Expand All @@ -1112,7 +1115,7 @@ void CodeTextEditor::trim_trailing_whitespace() {
}
}

if (trimed_whitespace) {
if (trimmed_whitespace) {
text_editor->merge_overlapping_carets();
text_editor->end_complex_operation();
text_editor->queue_redraw();
Expand Down