summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
authorPouleyKetchoupp <pouleyketchoup@gmail.com>2019-08-20 09:38:57 +0200
committerPouleyKetchoupp <pouleyketchoup@gmail.com>2019-08-25 15:43:45 +0200
commitbc839ed3f31d3e64537c5f00499f48a81579d8eb (patch)
tree081b699d4c16367460be8701d637a37b1f150e1b /scene/gui
parent51def4dab9d0e787c519aef914764a6140565d90 (diff)
Update TextEdit selection & cursor when inserting line
Fixes #31458
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/text_edit.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index a771794f25..597d156c13 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -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) {