diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-08-25 22:33:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-25 22:33:23 +0200 |
commit | 0985d5fa991d14f5393ced5783b69b967a69f4f5 (patch) | |
tree | 429b24bd22a8ba71a486a8cc51222ac30aea62d8 /scene/gui | |
parent | 41b5c6295278cb00b0372b01481c674561e8f4ef (diff) | |
parent | bc839ed3f31d3e64537c5f00499f48a81579d8eb (diff) |
Merge pull request #31496 from nekomatata/fix-text-edit-insert-selection
Update TextEdit selection when inserting line
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/text_edit.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index c125f7b531..7d1895a67a 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -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) { |