From 02ace26e0ac592706a41cb8eddbb8db3cc667351 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Wed, 12 Feb 2020 18:33:28 -0800 Subject: [PATCH] macos: Fix an issue with chorded keys in norwegian keymap fixes: https://github.com/wez/wezterm/issues/151 --- window/src/os/macos/window.rs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/window/src/os/macos/window.rs b/window/src/os/macos/window.rs index 7f9db8b12..fdbafada8 100644 --- a/window/src/os/macos/window.rs +++ b/window/src/os/macos/window.rs @@ -1029,6 +1029,14 @@ impl WindowView { let modifiers = unsafe { key_modifiers(nsevent.modifierFlags()) }; let virtual_key = unsafe { nsevent.keyCode() }; + log::debug!( + "key_common: chars=`{}` unmod=`{}` modifiers=`{:?}` virtual_key={:?}", + chars.escape_debug(), + unmod.escape_debug(), + modifiers, + virtual_key + ); + // `Delete` on macos is really Backspace and emits BS. // `Fn-Delete` emits DEL. // Alt-Delete is mapped by the IME to be equivalent to Fn-Delete. @@ -1045,6 +1053,19 @@ impl WindowView { unmod }; + // If unmod is empty it most likely means that the user has selected + // an alternate keymap that has a chorded representation of eg: an ASCII + // character. One example of this is selecting a Norwegian keymap on + // a US keyboard. The `~` symbol is produced by pressing CTRL-]. + // That shows up here as unmod=`` with modifiers=CTRL. In this situation + // we want to cancel the modifiers out so that we just focus on + // `chars` instead. + let modifiers = if unmod.is_empty() { + Modifiers::NONE + } else { + modifiers + }; + if USE_IME.load(Ordering::Relaxed) && modifiers.is_empty() { unsafe { let input_context: id = msg_send![this, inputContext]; @@ -1089,12 +1110,13 @@ impl WindowView { key_is_down, }; - /* - eprintln!( + log::debug!( "key_common {:?} (chars={:?} unmod={:?} modifiers={:?}", - event, chars, unmod, modifiers + event, + chars, + unmod, + modifiers ); - */ if let Some(myself) = Self::get_this(this) { let mut inner = myself.inner.borrow_mut();