Skip to content

Commit

Permalink
[GUI] Enforce virtual keyboard redisplay on clear
Browse files Browse the repository at this point in the history
  • Loading branch information
naithar committed Jan 26, 2021
1 parent 2a3e771 commit ba6aa76
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
32 changes: 17 additions & 15 deletions scene/gui/line_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
selection.creating = false;
selection.doubleclick = false;

if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD) && virtual_keyboard_enabled) {
if (selection.enabled) {
DisplayServer::get_singleton()->virtual_keyboard_show(text, get_global_rect(), false, max_length, selection.begin, selection.end);
} else {
DisplayServer::get_singleton()->virtual_keyboard_show(text, get_global_rect(), false, max_length, cursor_pos);
}
}
show_virtual_keyboard();
}

update();
Expand Down Expand Up @@ -953,14 +947,7 @@ void LineEdit::_notification(int p_what) {
DisplayServer::get_singleton()->window_set_ime_position(get_global_position() + cursor_pos, get_viewport()->get_window_id());
}

if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD) && virtual_keyboard_enabled) {
if (selection.enabled) {
DisplayServer::get_singleton()->virtual_keyboard_show(text, get_global_rect(), false, max_length, selection.begin, selection.end);
} else {
DisplayServer::get_singleton()->virtual_keyboard_show(text, get_global_rect(), false, max_length, cursor_pos);
}
}

show_virtual_keyboard();
} break;
case NOTIFICATION_FOCUS_EXIT: {
if (caret_blink_enabled && !caret_force_displayed) {
Expand Down Expand Up @@ -1407,6 +1394,21 @@ Array LineEdit::get_structured_text_bidi_override_options() const {
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 (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD) && virtual_keyboard_enabled) {
if (selection.enabled) {
DisplayServer::get_singleton()->virtual_keyboard_show(text, get_global_rect(), false, max_length, selection.begin, selection.end);
} else {
DisplayServer::get_singleton()->virtual_keyboard_show(text, get_global_rect(), false, max_length, cursor_pos);
}
}
}

String LineEdit::get_text() const {
Expand Down
3 changes: 3 additions & 0 deletions scene/gui/line_edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ class LineEdit : public Control {
Ref<Texture2D> get_right_icon();

virtual bool is_text_field() const override;

void show_virtual_keyboard();

LineEdit();
~LineEdit();
};
Expand Down

0 comments on commit ba6aa76

Please sign in to comment.