Browse Source

[GUI] Enforce virtual keyboard redisplay on clear

Sergey Minakov 4 years ago
parent
commit
7b8d6d2413
2 changed files with 20 additions and 14 deletions
  1. 17 14
      scene/gui/line_edit.cpp
  2. 3 0
      scene/gui/line_edit.h

+ 17 - 14
scene/gui/line_edit.cpp

@@ -128,13 +128,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
 			selection.creating = false;
 			selection.doubleclick = false;
 
-			if (OS::get_singleton()->has_virtual_keyboard() && virtual_keyboard_enabled) {
-				if (selection.enabled) {
-					OS::get_singleton()->show_virtual_keyboard(text, get_global_rect(), false, max_length, selection.begin, selection.end);
-				} else {
-					OS::get_singleton()->show_virtual_keyboard(text, get_global_rect(), false, max_length, cursor_pos);
-				}
-			}
+			show_virtual_keyboard();
 		}
 
 		update();
@@ -930,13 +924,7 @@ void LineEdit::_notification(int p_what) {
 				OS::get_singleton()->set_ime_position(get_global_position() + cursor_pos2);
 			}
 
-			if (OS::get_singleton()->has_virtual_keyboard() && virtual_keyboard_enabled) {
-				if (selection.enabled) {
-					OS::get_singleton()->show_virtual_keyboard(text, get_global_rect(), false, max_length, selection.begin, selection.end);
-				} else {
-					OS::get_singleton()->show_virtual_keyboard(text, get_global_rect(), false, max_length, cursor_pos);
-				}
-			}
+			show_virtual_keyboard();
 		} break;
 		case NOTIFICATION_FOCUS_EXIT: {
 
@@ -1277,6 +1265,21 @@ void LineEdit::clear() {
 
 	clear_internal();
 	_text_changed();
+
+	// This should reset virtual keyboard state if needed.
+	if (has_focus()) {
+		show_virtual_keyboard();
+	}
+}
+
+void LineEdit::show_virtual_keyboard() {
+	if (OS::get_singleton()->has_virtual_keyboard() && virtual_keyboard_enabled) {
+		if (selection.enabled) {
+			OS::get_singleton()->show_virtual_keyboard(text, get_global_rect(), false, max_length, selection.begin, selection.end);
+		} else {
+			OS::get_singleton()->show_virtual_keyboard(text, get_global_rect(), false, max_length, cursor_pos);
+		}
+	}
 }
 
 String LineEdit::get_text() const {

+ 3 - 0
scene/gui/line_edit.h

@@ -242,6 +242,9 @@ public:
 	Ref<Texture> get_right_icon();
 
 	virtual bool is_text_field() const;
+
+	void show_virtual_keyboard();
+
 	LineEdit();
 	~LineEdit();
 };