Merge pull request #51502 from codecat/fix-caret-selection

Move cursor to edge of selection when moving caret left/right
This commit is contained in:
Rémi Verschelde 2021-08-12 10:07:12 +02:00 committed by GitHub
commit fba0c8e2e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();
}