From 81365dbe6aabef455d36078ad1b1cd5bae3d0ca4 Mon Sep 17 00:00:00 2001 From: ardocrat Date: Fri, 30 May 2025 14:48:49 +0300 Subject: [PATCH] ui: reset keyboard window state on opening and inputs focus change --- src/gui/app.rs | 4 ++++ src/gui/views/input/edit.rs | 5 +++++ src/gui/views/input/keyboard.rs | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/src/gui/app.rs b/src/gui/app.rs index c9465b9e..9e3ca8fd 100755 --- a/src/gui/app.rs +++ b/src/gui/app.rs @@ -141,6 +141,10 @@ impl App { 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. diff --git a/src/gui/views/input/edit.rs b/src/gui/views/input/edit.rs index 39a3c446..645a992e 100644 --- a/src/gui/views/input/edit.rs +++ b/src/gui/views/input/edit.rs @@ -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| { diff --git a/src/gui/views/input/keyboard.rs b/src/gui/views/input/keyboard.rs index fc5e9aa6..d4b7141f 100644 --- a/src/gui/views/input/keyboard.rs +++ b/src/gui/views/input/keyboard.rs @@ -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(); + } } \ No newline at end of file