Skip to content

Commit 7d20999

Browse files
rustbasichacknus
authored andcommitted
Fix: Ensures correct IME behavior when the text input area gains or loses focus. (emilk#4896)
Fix: Ensures correct IME behavior when the text input area gains or loses focus. Fix: Handling `state.ime_enabled` in multiple `TextEdit`. Fix: A symptom of characters being copied when there are multiple TextEdits. * Related emilk#4137 * Related emilk#4358 * Closes emilk#4374 * Related emilk#4436 * Related emilk#4794 * Related emilk#4908 * Related emilk#5008 Fix Issues: When focus is moved elsewhere, you must set `state.ime_enabled = false`, otherwise the IME will have problems when focus returns. Fix Issues: A symptom of characters being copied when there are multiple TextEdits. Deletes all current `IME events`, preventing them from being copied to `other TextEdits`, without saving the `TextEdit ID`, ( Related Issues: Some `LINUX` seem to trigger an IME enable event on startup. So, when we gained focus, we do `state.ime_enabled = false`. )
1 parent f9236be commit 7d20999

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

crates/egui/src/widgets/text_edit/builder.rs

+10
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,16 @@ impl<'t> TextEdit<'t> {
745745
}
746746
}
747747

748+
// Ensures correct IME behavior when the text input area gains or loses focus.
749+
if state.ime_enabled && (response.gained_focus() || response.lost_focus()) {
750+
state.ime_enabled = false;
751+
if let Some(mut ccursor_range) = state.cursor.char_range() {
752+
ccursor_range.secondary.index = ccursor_range.primary.index;
753+
state.cursor.set_char_range(Some(ccursor_range));
754+
}
755+
ui.input_mut(|i| i.events.retain(|e| !matches!(e, Event::Ime(_))));
756+
}
757+
748758
state.clone().store(ui.ctx(), id);
749759

750760
if response.changed {

0 commit comments

Comments
 (0)