From 9ad65d9031e8cb16a7b553c0e6f74809e9811e92 Mon Sep 17 00:00:00 2001 From: akbash Date: Sat, 12 Sep 2026 00:38:57 +0300 Subject: fix: suppress Windows dead-key fallback characters in remote panes (#3972) refs #3948 Co-authored-by: akbash-bot <300245827+akbash-bot@users.noreply.github.com> --- src/input/encode.rs | 36 ++++++++++++++++++++++++++++++++--- src/input/model.rs | 54 +++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 81 insertions(+), 9 deletions(-) (limited to 'src/input') diff --git a/src/input/encode.rs b/src/input/encode.rs index 1dd56351..27e59dce 100644 --- a/src/input/encode.rs +++ b/src/input/encode.rs @@ -16,10 +16,10 @@ pub fn encode_key(key: KeyEvent, protocol: KeyboardProtocol) -> Vec { } pub fn encode_terminal_key(key: TerminalKey, protocol: KeyboardProtocol) -> Vec { - // A zero Unicode value on this Windows character event means the host layout is - // still composing a dead key. Kitty panes must not receive its physical fallback. + // The host layout has not committed text for this Windows dead key. Neither + // legacy nor Kitty panes should receive its physical character fallback. // Legacy Windows panes take the native ConPTY fallback before reaching this encoder. - if matches!(protocol, KeyboardProtocol::Kitty { .. }) && key.is_windows_shift_dead_key() { + if key.is_windows_dead_key() { return Vec::new(); } @@ -571,6 +571,36 @@ mod tests { assert_eq!(actual.shifted_codepoint, shifted_codepoint); } + #[test] + fn kitty_all_keys_does_not_encode_windows_altgr_dead_key_phases() { + use crossterm::event::KeyEventKind; + + let key = TerminalKey::new(KeyCode::Char('4'), KeyModifiers::empty()).with_windows_record( + crate::input::WindowsKeyRecord { + key_down: true, + repeat_count: 1, + virtual_key_code: 52, + virtual_scan_code: 5, + unicode: 0, + control_key_state: 9, + }, + ); + for kind in [ + KeyEventKind::Press, + KeyEventKind::Repeat, + KeyEventKind::Release, + ] { + assert!( + encode_terminal_key( + key.clone().with_kind(kind), + KeyboardProtocol::Kitty { flags: 31 }, + ) + .is_empty(), + "{kind:?}" + ); + } + } + #[test] fn legacy_enter() { let key = KeyEvent::new(KeyCode::Enter, KeyModifiers::empty()); diff --git a/src/input/model.rs b/src/input/model.rs index 50cd7e42..3828174f 100644 --- a/src/input/model.rs +++ b/src/input/model.rs @@ -78,7 +78,7 @@ pub struct TerminalKey { pub shifted_codepoint: Option, pub generated_text: Option, physical_identity_hint: bool, - windows_shift_dead_key: bool, + windows_dead_key: bool, source: KeySource, } @@ -92,7 +92,7 @@ impl TerminalKey { shifted_codepoint: None, generated_text: None, physical_identity_hint: false, - windows_shift_dead_key: false, + windows_dead_key: false, source: KeySource::Synthesized, } } @@ -160,8 +160,10 @@ impl TerminalKey { mut self, record: Option, ) -> Self { - self.windows_shift_dead_key = matches!(self.code, KeyCode::Char(_)) - && self.modifiers == KeyModifiers::SHIFT + // AltGr is normalized to text-only modifiers by the Windows input mapper. + // Command chords can also have zero Unicode, so retain their fallback keys. + self.windows_dead_key = matches!(self.code, KeyCode::Char(_)) + && self.modifiers.difference(KeyModifiers::SHIFT).is_empty() && record.is_some_and(|record| record.unicode == 0); self } @@ -189,8 +191,8 @@ impl TerminalKey { None } - pub(crate) fn is_windows_shift_dead_key(&self) -> bool { - self.windows_shift_dead_key + pub(crate) fn is_windows_dead_key(&self) -> bool { + self.windows_dead_key } pub(crate) fn identity(&self) -> KeyIdentity { @@ -422,6 +424,46 @@ mod tests { assert_eq!(key.repeat_count, 1); } + #[test] + fn windows_composition_hint_requires_uncommitted_text_not_a_command() { + let record = WindowsKeyRecord { + key_down: true, + repeat_count: 1, + virtual_key_code: 52, + virtual_scan_code: 5, + unicode: 0, + control_key_state: 9, + }; + for modifiers in [ + KeyModifiers::CONTROL, + KeyModifiers::ALT, + KeyModifiers::CONTROL | KeyModifiers::ALT, + KeyModifiers::SUPER, + ] { + let key = TerminalKey::new(KeyCode::Char('4'), modifiers) + .with_windows_composition_hint(Some(record)); + assert!( + !key.is_windows_dead_key(), + "command modifiers: {modifiers:?}" + ); + } + for (code, source) in [ + (KeyCode::Left, Some(record)), + (KeyCode::Char('4'), None), + ( + KeyCode::Char('~'), + Some(WindowsKeyRecord { + unicode: 126, + ..record + }), + ), + ] { + let key = + TerminalKey::new(code, KeyModifiers::empty()).with_windows_composition_hint(source); + assert!(!key.is_windows_dead_key(), "{code:?}, {source:?}"); + } + } + #[test] fn release_clears_generated_text_and_grouped_repeat_count() { let release = TerminalKey::new(KeyCode::Char('a'), KeyModifiers::empty()) -- cgit v1.2.3