Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextEdit: Discard the preedit when focus change or other text is enter #3000

Merged
merged 2 commits into from Jun 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions internal/core/items/text.rs
Expand Up @@ -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
}
Expand Down Expand Up @@ -577,6 +571,9 @@ 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);
}
}
}
Expand Down Expand Up @@ -970,6 +967,10 @@ impl TextInput {
window_adapter: &Rc<dyn WindowAdapter>,
self_rc: &ItemRc,
) {
self.preedit_text.set(Default::default());
self.preedit_selection_start.set(0);
self.preedit_selection_end.set(0);
Comment on lines +970 to +972
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might or might not help, but it carries the risk of the input method being out of sync with the state that we think it is in. When the text of the input field changes, we should inform the input method about what the new text is. Qt has APIs for that, winit unfortunately doesn't.


self.delete_selection(window_adapter, self_rc);
let mut text: String = self.text().into();
let cursor_pos = self.selection_anchor_and_cursor().1;
Expand Down