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

Update TextEdit selection when inserting line #31496

Merged
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
16 changes: 14 additions & 2 deletions scene/gui/text_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6216,9 +6216,21 @@ void TextEdit::set_line(int line, String new_text) {
}

void TextEdit::insert_at(const String &p_text, int at) {
cursor_set_column(0);
cursor_set_line(at, false, true);
_insert_text(at, 0, p_text + "\n");
if (cursor.line >= at) {
// offset cursor when located after inserted line
++cursor.line;
}
if (is_selection_active()) {
if (selection.from_line >= at) {
// offset selection when located after inserted line
++selection.from_line;
++selection.to_line;
} else if (selection.to_line >= at) {
// extend selection that includes inserted line
++selection.to_line;
}
}
}

void TextEdit::set_show_line_numbers(bool p_show) {
Expand Down