ui: reset keyboard window state on opening and inputs focus change

This commit is contained in:
ardocrat
2025-05-30 14:48:49 +03:00
parent 7ae63b2b66
commit 81365dbe6a
3 changed files with 16 additions and 0 deletions
+4
View File
@@ -141,6 +141,10 @@ impl<Platform: PlatformCallbacks> App<Platform> {
if keyboard_showing {
ctx.move_to_top(LayerId::new(Order::Middle, egui::Id::new(KeyboardContent::WINDOW_ID)));
}
// Reset keyboard state for newly opened modal.
if Modal::first_draw() {
KeyboardContent::reset_window_state();
}
}
/// Draw custom desktop window frame content.
+5
View File
@@ -149,6 +149,11 @@ impl TextEdit {
text_edit_resp.request_focus();
}
// Reset keyboard state for newly focused.
if clicked || self.focus_request {
KeyboardContent::reset_window_state();
}
// Apply text from software input.
if text_edit_resp.has_focus() {
ui.data_mut(|data| {
+7
View File
@@ -499,4 +499,11 @@ impl KeyboardContent {
let r_state = WINDOW_STATE.read();
r_state.shift.store(false, Ordering::Relaxed);
}
/// Reset keyboard window state.
pub fn reset_window_state() {
let mut w_state = WINDOW_STATE.write();
w_state.layout = Arc::new(KeyboardLayout::TEXT);
// *w_state = KeyboardState::default();
}
}