Sfoglia il codice sorgente

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.
Melissa Geels 4 anni fa
parent
commit
ed4c3eb7b3
1 ha cambiato i file con 12 aggiunte e 0 eliminazioni
  1. 12 0
      scene/gui/text_edit.cpp

+ 12 - 0
scene/gui/text_edit.cpp

@@ -1584,6 +1584,12 @@ void TextEdit::_move_cursor_left(bool p_select, bool p_move_by_word) {
 	// Handle selection
 	// Handle selection
 	if (p_select) {
 	if (p_select) {
 		_pre_shift_selection();
 		_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 {
 	} else {
 		deselect();
 		deselect();
 	}
 	}
@@ -1629,6 +1635,12 @@ void TextEdit::_move_cursor_right(bool p_select, bool p_move_by_word) {
 	// Handle selection
 	// Handle selection
 	if (p_select) {
 	if (p_select) {
 		_pre_shift_selection();
 		_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 {
 	} else {
 		deselect();
 		deselect();
 	}
 	}