Skip to content

Commit

Permalink
Fix: Ensures correct IME behavior when the text input area gains or l…
Browse files Browse the repository at this point in the history
…oses 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`. )
  • Loading branch information
rustbasic authored and 486c committed Oct 9, 2024
1 parent bd30378 commit a72081b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions crates/egui/src/widgets/text_edit/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,16 @@ impl<'t> TextEdit<'t> {
}
}

// Ensures correct IME behavior when the text input area gains or loses focus.
if state.ime_enabled && (response.gained_focus() || response.lost_focus()) {
state.ime_enabled = false;
if let Some(mut ccursor_range) = state.cursor.char_range() {
ccursor_range.secondary.index = ccursor_range.primary.index;
state.cursor.set_char_range(Some(ccursor_range));
}
ui.input_mut(|i| i.events.retain(|e| !matches!(e, Event::Ime(_))));
}

state.clone().store(ui.ctx(), id);

if response.changed {
Expand Down

0 comments on commit a72081b

Please sign in to comment.