From d37cf3822152f1f519a7c9dfedcddec4cebe5b49 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 27 Jun 2023 17:48:33 +0200 Subject: [PATCH 1/2] TextEdit: Discard the preedit when focus change or other text is enter Otherwise we end up with outdated pre-edit data if we change focus while editing. Note: Qt doas actually send a "commit" event when the focus change (but of course that does not happen when changing the focus within slint) But firefox does discard the preedit when loosing the focus. CC #1925 --- internal/core/items/text.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/internal/core/items/text.rs b/internal/core/items/text.rs index f92b842112a..361412faeea 100644 --- a/internal/core/items/text.rs +++ b/internal/core/items/text.rs @@ -537,12 +537,6 @@ impl Item for TextInput { KeyEventResult::EventAccepted } KeyEventType::CommitComposition => { - // Winit says that it will always send an event to empty the pre-edit area, but with - // korean IME on Windows for example that's not the case. Qt also doesn't make that guarantee, - // so clear it by hand here. - self.preedit_text.set(Default::default()); - self.preedit_selection_start.set(0); - self.preedit_selection_end.set(0); self.insert(&event.text, window_adapter, self_rc); KeyEventResult::EventAccepted } @@ -579,6 +573,9 @@ impl Item for TextInput { window_adapter.input_method_request(InputMethodRequest::Disable {}); } } + self.preedit_text.set(Default::default()); + self.preedit_selection_start.set(0); + self.preedit_selection_end.set(0); } } FocusEventResult::FocusAccepted @@ -970,6 +967,10 @@ impl TextInput { window_adapter: &Rc, self_rc: &ItemRc, ) { + self.preedit_text.set(Default::default()); + self.preedit_selection_start.set(0); + self.preedit_selection_end.set(0); + self.delete_selection(window_adapter, self_rc); let mut text: String = self.text().into(); let cursor_pos = self.selection_anchor_and_cursor().1; From 3b1b4523ee2594404f60ca15c617e32eda3cc180 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 28 Jun 2023 12:01:16 +0200 Subject: [PATCH 2/2] Update internal/core/items/text.rs Co-authored-by: Simon Hausmann --- internal/core/items/text.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/core/items/text.rs b/internal/core/items/text.rs index 361412faeea..ab542f39346 100644 --- a/internal/core/items/text.rs +++ b/internal/core/items/text.rs @@ -571,11 +571,11 @@ impl Item for TextInput { if !self.read_only() { if let Some(window_adapter) = window_adapter.internal(crate::InternalToken) { window_adapter.input_method_request(InputMethodRequest::Disable {}); + self.preedit_text.set(Default::default()); + self.preedit_selection_start.set(0); + self.preedit_selection_end.set(0); } } - self.preedit_text.set(Default::default()); - self.preedit_selection_start.set(0); - self.preedit_selection_end.set(0); } } FocusEventResult::FocusAccepted