diff options
author | Melissa Geels <spansjh@gmail.com> | 2021-08-11 10:44:19 +0200 |
---|---|---|
committer | Melissa Geels <spansjh@gmail.com> | 2021-08-11 13:27:12 +0200 |
commit | ed4c3eb7b350f3a4597f301a45139b31269bf95e (patch) | |
tree | 2a6fad876318800476b4d4d4995a3fbacf9e8987 /scene/gui | |
parent | a902f760634432adcb5f74b3b6cd27a7275a320f (diff) |
Move cursor to edge of selection when moving caret left/right
This is to mimic the behavior of many third party text editors. The
reason it's not doing it when moving by word is due to that behavior
being mostly the same on other editors.
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/text_edit.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 1b3935dd25..932846e73e 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1584,6 +1584,12 @@ void TextEdit::_move_cursor_left(bool p_select, bool p_move_by_word) { // Handle selection if (p_select) { _pre_shift_selection(); + } else if (selection.active && !p_move_by_word) { + // If a selection is active, move cursor to start of selection + cursor_set_line(selection.from_line); + cursor_set_column(selection.from_column); + deselect(); + return; } else { deselect(); } @@ -1629,6 +1635,12 @@ void TextEdit::_move_cursor_right(bool p_select, bool p_move_by_word) { // Handle selection if (p_select) { _pre_shift_selection(); + } else if (selection.active && !p_move_by_word) { + // If a selection is active, move cursor to end of selection + cursor_set_line(selection.to_line); + cursor_set_column(selection.to_column); + deselect(); + return; } else { deselect(); } |