diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 42c1af75476..fe2d6207a57 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -128,13 +128,7 @@ void LineEdit::_gui_input(Ref 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 { diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h index 1d4cd24e464..d1ebda9bf60 100644 --- a/scene/gui/line_edit.h +++ b/scene/gui/line_edit.h @@ -242,6 +242,9 @@ public: Ref get_right_icon(); virtual bool is_text_field() const; + + void show_virtual_keyboard(); + LineEdit(); ~LineEdit(); };