From 51c30e2ee2fff8883fc35935415b1e211662c178 Mon Sep 17 00:00:00 2001 From: Dominik Kreutzer Date: Sat, 9 Jul 2022 03:56:53 +0200 Subject: [PATCH] win32: fix encoding of delete and backspace keys When using the win32 keyboard encoding, the delete and backspace keys were encoded with the wrong character codes compared to the native terminal. This caused subtle issues in multiple applications. This change brings the encoding in line with the native terminal. --- wezterm-input-types/src/lib.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/wezterm-input-types/src/lib.rs b/wezterm-input-types/src/lib.rs index 906f23096..c08a5dc79 100644 --- a/wezterm-input-types/src/lib.rs +++ b/wezterm-input-types/src/lib.rs @@ -1222,13 +1222,33 @@ impl KeyEvent { match &self.key { KeyCode::Composed(_) => None, KeyCode::Char(c) => { + let c = match *c { + // Delete key is transmitted as 0x0 + '\x7f' => '\x00', + // Backspace key is transmitted as 0x8, 0x7f or 0x0 + '\x08' => { + if self.modifiers.contains(Modifiers::CTRL) { + if self.modifiers.contains(Modifiers::ALT) + || self.modifiers.contains(Modifiers::SHIFT) + { + '\x00' + } else { + '\x7f' + } + } else { + '\x08' + } + } + _ => *c, + }; + let c = if self.modifiers.contains(Modifiers::CTRL) { // Ensure that we rewrite the unicode value to the ASCII CTRL // equivalent value. // - ctrl_mapping(*c).unwrap_or(*c) + ctrl_mapping(c).unwrap_or(c) } else { - *c + c }; let uni = c as u32;