From a72bdd7a85a2841bf0217192b1623cfb521dad61 Mon Sep 17 00:00:00 2001 From: Ygor Souza Date: Mon, 30 Sep 2024 16:20:40 +0200 Subject: [PATCH 1/2] Revert "Fix backspace/arrow keys in TextEdit on Linux (#5188)" This reverts commit 15d3d43aa30317ec7c0611d4faae890166d7a22b. --- crates/egui-winit/src/lib.rs | 70 +++++++++++++++++------------------- 1 file changed, 33 insertions(+), 37 deletions(-) diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index 1980376b97a..7110ef3fe21 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -329,43 +329,39 @@ impl State { } WindowEvent::Ime(ime) => { - 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(); - } - }; - } + // 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, From a293206224c6c3bacf2c0a8bdd2551e273003346 Mon Sep 17 00:00:00 2001 From: Ygor Souza Date: Mon, 30 Sep 2024 17:28:05 +0200 Subject: [PATCH 2/2] Ignore Ime::Enabled event on Linux It means different things on X11 and Wayland, and causes us to assume IME is active when it isn't, causing the backspace and arrow keys to be disabled. --- crates/egui-winit/src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index 7110ef3fe21..85cd5047f9f 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -344,7 +344,13 @@ impl State { // between Commits. match ime { winit::event::Ime::Enabled => { - self.ime_event_enable(); + if cfg!(target_os = "linux") { + // This event means different things in X11 and Wayland, but we can just + // ignore it and enable IME on the preedit event. + // See + } else { + self.ime_event_enable(); + } } winit::event::Ime::Preedit(text, Some(_cursor)) => { self.ime_event_enable();