From c184b280b0fb5474c61171d3be887278aad27f72 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 6 Jul 2024 22:09:29 +0900 Subject: [PATCH 1/2] Update builder.rs --- crates/egui/src/widgets/text_edit/builder.rs | 32 ++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index 8205da63d0e..ca577f45706 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -425,7 +425,7 @@ impl<'t> TextEdit<'t> { frame_rect, visuals.rounding, ui.visuals().extreme_bg_color, - visuals.bg_stroke, // TODO(emilk): we want to show something here, or a text-edit field doesn't "pop". + ui.visuals().widgets.noninteractive.bg_stroke, // TODO(emilk): we want to show something here, or a text-edit field doesn't "pop". ) } } else { @@ -855,7 +855,14 @@ fn events( let mut any_change = false; - let events = ui.input(|i| i.filtered_events(&event_filter)); + let mut events = ui.input(|i| i.filtered_events(&event_filter)); + + if state.ime_enabled { + ime_enabled_filter_events(&mut events); + // Process IME events first: + events.sort_by_key(|e| !matches!(e, Event::Ime(_))); + } + for event in &events { let did_mutate_text = match event { // First handle events that only changes the selection cursor, not the text: @@ -1055,6 +1062,27 @@ fn events( // ---------------------------------------------------------------------------- +fn ime_enabled_filter_events(events: &mut Vec) { + // Remove key events which cause problems while 'IME' is being used. + // See https://github.com/emilk/egui/pull/4509 + events.retain(|event| { + !matches!( + event, + Event::Key { repeat: true, .. } + | Event::Key { + key: Key::Backspace + | Key::ArrowUp + | Key::ArrowDown + | Key::ArrowLeft + | Key::ArrowRight, + .. + } + ) + }); +} + +// ---------------------------------------------------------------------------- + /// Returns `Some(new_cursor)` if we did mutate `text`. fn check_for_mutating_key_press( os: OperatingSystem, From 336196c2fa17795b19eb0245a3991b9900a50ac7 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sun, 7 Jul 2024 16:13:12 +0900 Subject: [PATCH 2/2] Update builder.rs --- crates/egui/src/widgets/text_edit/builder.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index ca577f45706..ed29899b256 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -425,7 +425,7 @@ impl<'t> TextEdit<'t> { frame_rect, visuals.rounding, ui.visuals().extreme_bg_color, - ui.visuals().widgets.noninteractive.bg_stroke, // TODO(emilk): we want to show something here, or a text-edit field doesn't "pop". + visuals.bg_stroke, // TODO(emilk): we want to show something here, or a text-edit field doesn't "pop". ) } } else { @@ -858,7 +858,7 @@ fn events( let mut events = ui.input(|i| i.filtered_events(&event_filter)); if state.ime_enabled { - ime_enabled_filter_events(&mut events); + remove_ime_incompatible_events(&mut events); // Process IME events first: events.sort_by_key(|e| !matches!(e, Event::Ime(_))); } @@ -1062,7 +1062,7 @@ fn events( // ---------------------------------------------------------------------------- -fn ime_enabled_filter_events(events: &mut Vec) { +fn remove_ime_incompatible_events(events: &mut Vec) { // Remove key events which cause problems while 'IME' is being used. // See https://github.com/emilk/egui/pull/4509 events.retain(|event| {