From a9e168e10d819ad8c66ccb336df4e2878600c800 Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Sat, 13 May 2023 03:02:05 +0300 Subject: [PATCH] On macOS, fix backspace emission on preedit clear Fixes: d15feb5cfa (On macOS, fix empty marked text) --- CHANGELOG.md | 1 + src/platform_impl/macos/view.rs | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dfcd18d1..49ba7485 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ And please only add new entries to the top of this list, right below the `# Unre - On Wayland, add `Window::drag_resize_window` method. - On Wayland, drop `WINIT_WAYLAND_CSD_THEME` variable. - Bump MSRV from `1.60` to `1.64`. +- On macOS, fix `Backspace` being emitted when clearing preedit with it. # 0.28.5 diff --git a/src/platform_impl/macos/view.rs b/src/platform_impl/macos/view.rs index ef03dd7a..cacbf10e 100644 --- a/src/platform_impl/macos/view.rs +++ b/src/platform_impl/macos/view.rs @@ -50,7 +50,7 @@ impl Default for CursorState { } } -#[derive(Debug, Eq, PartialEq)] +#[derive(Debug, Eq, PartialEq, Clone, Copy)] enum ImeState { /// The IME events are disabled, so only `ReceivedCharacter` is being sent to the user. Disabled, @@ -481,6 +481,7 @@ declare_class!( && !ev_mods.logo(); let characters = get_characters(event, ignore_alt_characters); + let old_ime_state = self.state.ime_state; self.state.forward_key_to_app = false; // The `interpretKeyEvents` function might call @@ -518,7 +519,8 @@ declare_class!( true } ImeState::Preedit => true, - _ => false, + // `key_down` could result in preedit clear, so compare old and current state. + _ => old_ime_state != self.state.ime_state, }; if !had_ime_input || self.state.forward_key_to_app {