Skip to content

Commit

Permalink
Merge pull request #31496 from nekomatata/fix-text-edit-insert-selection
Browse files Browse the repository at this point in the history
Update TextEdit selection when inserting line
  • Loading branch information
akien-mga authored Aug 25, 2019
2 parents 41b5c62 + bc839ed commit 0985d5f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions scene/gui/text_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 0985d5f

Please sign in to comment.