Merge pull request #31496 from nekomatata/fix-text-edit-insert-selection

Update TextEdit selection when inserting line
This commit is contained in:
Rémi Verschelde 2019-08-25 22:33:23 +02:00 committed by GitHub
commit 0985d5fa99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6550,9 +6550,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) {