From 0a6e577e108676cce4b1e4b8c74b600640e36857 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Mon, 11 Sep 2023 09:37:58 -0600 Subject: [PATCH 1/2] Fix some international keybindings This adds primitive interaction with the IME system for keyboard shortcuts in zed. For zed-industries/community#1981 For zed-industroes/community#1913 --- crates/gpui/src/platform/mac/window.rs | 27 +++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/crates/gpui/src/platform/mac/window.rs b/crates/gpui/src/platform/mac/window.rs index 3be425d312..a3d4c39418 100644 --- a/crates/gpui/src/platform/mac/window.rs +++ b/crates/gpui/src/platform/mac/window.rs @@ -988,7 +988,32 @@ extern "C" fn handle_key_event(this: &Object, native_event: id, key_equivalent: .flatten() .is_some(); if !is_composing { - handled = callback(Event::KeyDown(event)); + // if the IME has changed the key, we'll first emit an event with the character + // generated by the IME system; then fallback to the keystroke if that is not + // handled. + // (e.g. on a brazillian keyboard to type a quote you type quote then space) + // (e.g. on a czech keyboard typing a $ requires option+shift+4) + if ime_text.is_some() && ime_text.as_ref() != Some(&event.keystroke.key) { + let event_with_ime_text = KeyDownEvent { + is_held: false, + keystroke: Keystroke { + ctrl: false, + alt: false, + shift: false, + cmd: false, + function: false, + key: ime_text.clone().unwrap(), + }, + }; + handled = callback(Event::KeyDown(event_with_ime_text)); + } + if !handled { + // empty key happens when you type a deadkey in input composition. + // (e.g. on a brazillian keyboard typing quote is a deadkey) + if !event.keystroke.key.is_empty() { + handled = callback(Event::KeyDown(event)); + } + } } if !handled { From e017dc6a5e17c170397d0e00f784bb3ba9980a7d Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Mon, 11 Sep 2023 11:16:18 -0600 Subject: [PATCH 2/2] Fix ctrl-` on Brazillian too --- crates/gpui/src/platform/mac/window.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/crates/gpui/src/platform/mac/window.rs b/crates/gpui/src/platform/mac/window.rs index a3d4c39418..e7befc2728 100644 --- a/crates/gpui/src/platform/mac/window.rs +++ b/crates/gpui/src/platform/mac/window.rs @@ -991,13 +991,21 @@ extern "C" fn handle_key_event(this: &Object, native_event: id, key_equivalent: // if the IME has changed the key, we'll first emit an event with the character // generated by the IME system; then fallback to the keystroke if that is not // handled. - // (e.g. on a brazillian keyboard to type a quote you type quote then space) - // (e.g. on a czech keyboard typing a $ requires option+shift+4) + // cases that we have working: + // - " on a brazillian layout by typing + // - ctrl-` on a brazillian layout by typing + // - $ on a czech QWERTY layout by typing + // - 4 on a czech QWERTY layout by typing + // - ctrl-4 on a czech QWERTY layout by typing (or ) if ime_text.is_some() && ime_text.as_ref() != Some(&event.keystroke.key) { let event_with_ime_text = KeyDownEvent { is_held: false, keystroke: Keystroke { - ctrl: false, + // we match ctrl because some use-cases need it. + // we don't match alt because it's often used to generate the optional character + // we don't match shift because we're not here with letters (usually) + // we don't match cmd/fn because they don't seem to use IME + ctrl: event.keystroke.ctrl, alt: false, shift: false, cmd: false,