Skip to content

Commit

Permalink
Fix backspace/arrow keys in TextEdit on Linux (emilk#5188)
Browse files Browse the repository at this point in the history
* Closes emilk#5008
* Closes emilk#5182
* Bug introduced in emilk#4912

I suspect this will make IME no longer work on Linux, though I don't
know if it ever worked.
I rather have backspace/arrows working though.

Please help test this (I don't have Linux!)

# Tested on
* [x] Mac
* [ ] Linux Wayland
* [x] Linux X11
  • Loading branch information
emilk authored and hacknus committed Oct 30, 2024
1 parent 7a0e8e7 commit 9a69c2b
Showing 1 changed file with 37 additions and 33 deletions.
70 changes: 37 additions & 33 deletions crates/egui-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,39 +329,43 @@ impl State {
}

WindowEvent::Ime(ime) => {
// on Mac even Cmd-C is pressed during ime, a `c` is pushed to Preedit.
// So no need to check is_mac_cmd.
//
// How winit produce `Ime::Enabled` and `Ime::Disabled` differs in MacOS
// and Windows.
//
// - On Windows, before and after each Commit will produce an Enable/Disabled
// event.
// - On MacOS, only when user explicit enable/disable ime. No Disabled
// after Commit.
//
// We use input_method_editor_started to manually insert CompositionStart
// between Commits.
match ime {
winit::event::Ime::Enabled => {
self.ime_event_enable();
}
winit::event::Ime::Preedit(text, Some(_cursor)) => {
self.ime_event_enable();
self.egui_input
.events
.push(egui::Event::Ime(egui::ImeEvent::Preedit(text.clone())));
}
winit::event::Ime::Commit(text) => {
self.egui_input
.events
.push(egui::Event::Ime(egui::ImeEvent::Commit(text.clone())));
self.ime_event_disable();
}
winit::event::Ime::Disabled | winit::event::Ime::Preedit(_, None) => {
self.ime_event_disable();
}
};
if cfg!(target_os = "linux") {
// We ignore IME events on linux, because of https://github.com/emilk/egui/issues/5008
} else {
// on Mac even Cmd-C is pressed during ime, a `c` is pushed to Preedit.
// So no need to check is_mac_cmd.
//
// How winit produce `Ime::Enabled` and `Ime::Disabled` differs in MacOS
// and Windows.
//
// - On Windows, before and after each Commit will produce an Enable/Disabled
// event.
// - On MacOS, only when user explicit enable/disable ime. No Disabled
// after Commit.
//
// We use input_method_editor_started to manually insert CompositionStart
// between Commits.
match ime {
winit::event::Ime::Enabled => {
self.ime_event_enable();
}
winit::event::Ime::Preedit(text, Some(_cursor)) => {
self.ime_event_enable();
self.egui_input
.events
.push(egui::Event::Ime(egui::ImeEvent::Preedit(text.clone())));
}
winit::event::Ime::Commit(text) => {
self.egui_input
.events
.push(egui::Event::Ime(egui::ImeEvent::Commit(text.clone())));
self.ime_event_disable();
}
winit::event::Ime::Disabled | winit::event::Ime::Preedit(_, None) => {
self.ime_event_disable();
}
};
}

EventResponse {
repaint: true,
Expand Down

0 comments on commit 9a69c2b

Please sign in to comment.