Browse Source

Merge pull request #52686 from eswartz/line-edit-move-cursor-on-unselect-3.x

Rémi Verschelde 3 years ago
parent
commit
2b61a4fa1a
1 changed files with 16 additions and 7 deletions
  1. 16 7
      scene/gui/line_edit.cpp

+ 16 - 7
scene/gui/line_edit.cpp

@@ -381,13 +381,17 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
 					FALLTHROUGH;
 					FALLTHROUGH;
 				}
 				}
 				case KEY_LEFT: {
 				case KEY_LEFT: {
-#ifdef APPLE_STYLE_KEYS
-					shift_selection_check_pre(k->get_shift());
-#else
-					if (!k->get_alt()) {
+#ifndef APPLE_STYLE_KEYS
+					if (!k->get_alt())
+#endif
+					{
 						shift_selection_check_pre(k->get_shift());
 						shift_selection_check_pre(k->get_shift());
+						if (selection.enabled && !k->get_shift()) {
+							set_cursor_position(selection.begin);
+							deselect();
+							break;
+						}
 					}
 					}
-#endif
 
 
 #ifdef APPLE_STYLE_KEYS
 #ifdef APPLE_STYLE_KEYS
 					if (k->get_command()) {
 					if (k->get_command()) {
@@ -430,8 +434,13 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
 					FALLTHROUGH;
 					FALLTHROUGH;
 				}
 				}
 				case KEY_RIGHT: {
 				case KEY_RIGHT: {
-					shift_selection_check_pre(k->get_shift());
-
+					if (selection.enabled && !k->get_shift()) {
+						set_cursor_position(selection.end);
+						deselect();
+						break;
+					} else {
+						shift_selection_check_pre(k->get_shift());
+					}
 #ifdef APPLE_STYLE_KEYS
 #ifdef APPLE_STYLE_KEYS
 					if (k->get_command()) {
 					if (k->get_command()) {
 						set_cursor_position(text.length());
 						set_cursor_position(text.length());