From 405cd3be36256dffcf5dd4a0b20b83c580085b19 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 3 Nov 2019 19:35:54 -0800 Subject: [PATCH] fix key repeat with IME --- window/src/os/macos/window.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/window/src/os/macos/window.rs b/window/src/os/macos/window.rs index ff7c4c88e..7378c6956 100644 --- a/window/src/os/macos/window.rs +++ b/window/src/os/macos/window.rs @@ -828,11 +828,12 @@ impl WindowView { } fn key_common(this: &mut Object, nsevent: id, key_is_down: bool) { + let is_a_repeat = unsafe { nsevent.isARepeat() == YES }; let chars = unsafe { nsstring_to_str(nsevent.characters()) }; // let unmod = unsafe { nsstring_to_str(nsevent.charactersIgnoringModifiers()) }; let modifiers = unsafe { key_modifiers(nsevent.modifierFlags()) }; - if modifiers.is_empty() && key_is_down { + if modifiers.is_empty() && !is_a_repeat { unsafe { let input_context: id = msg_send![this, inputContext]; let res: BOOL = msg_send![input_context, handleEvent: nsevent]; @@ -881,9 +882,11 @@ impl WindowView { Self::key_common(this, nsevent, true); } + /* extern "C" fn key_up(this: &mut Object, _sel: Sel, nsevent: id) { Self::key_common(this, nsevent, false); } + */ extern "C" fn did_resize(this: &mut Object, _sel: Sel, _notification: id) { #[cfg(feature = "opengl")] @@ -1077,10 +1080,15 @@ impl WindowView { sel!(keyDown:), Self::key_down as extern "C" fn(&mut Object, Sel, id), ); + /* keyUp events mess up the IME and we generally only care + * about the down events anyway. Leaving this un-plumbed + * means that we'll fall back to the default behavior for + * keyUp which helps make key repeat work. cls.add_method( sel!(keyUp:), Self::key_up as extern "C" fn(&mut Object, Sel, id), ); + */ cls.add_method( sel!(acceptsFirstResponder),