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

Handle the IME event first in TextEdit to fix some bugs #4794

Merged
merged 2 commits into from
Jul 7, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions crates/egui/src/widgets/text_edit/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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".
emilk marked this conversation as resolved.
Show resolved Hide resolved
)
}
} else {
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -1055,6 +1062,27 @@ fn events(

// ----------------------------------------------------------------------------

fn ime_enabled_filter_events(events: &mut Vec<Event>) {
emilk marked this conversation as resolved.
Show resolved Hide resolved
// 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,
Expand Down
Loading