Skip to content

Commit

Permalink
Update builder.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
rustbasic authored Jul 6, 2024
1 parent 0f6310c commit c184b28
Showing 1 changed file with 30 additions and 2 deletions.
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".
)
}
} 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>) {
// 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

0 comments on commit c184b28

Please sign in to comment.