From 1c0bc896647977161b95d2d00e42190306040849 Mon Sep 17 00:00:00 2001 From: Oleksiy Syvokon Date: Thu, 24 Jul 2025 15:22:57 +0300 Subject: [PATCH] linux: Fix `ctrl-0..9`, `ctrl-[`, `ctrl-^` (#35028) There were two different underlying reasons for the issues with ctrl-number and ctrl-punctuation: 1. Some keys in the ctrl-0..9 range send codes in the `\1b`..`\1f` range. For example, `ctrl-2` sends keycode for `ctrl-[` (0x1b), but we want to map it to `2`, not to `[`. 2. `ctrl-[` and four other ctrl-punctuation were incorrectly mapped, since the expected conversion is by adding 0x40 Closes #35012 Release Notes: - N/A --- crates/gpui/src/platform/linux/platform.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/gpui/src/platform/linux/platform.rs b/crates/gpui/src/platform/linux/platform.rs index dfa68a44f3..9efd7e9538 100644 --- a/crates/gpui/src/platform/linux/platform.rs +++ b/crates/gpui/src/platform/linux/platform.rs @@ -845,9 +845,15 @@ impl crate::Keystroke { { if key.is_ascii_graphic() { key_utf8.to_lowercase() - // map ctrl-a to a - } else if key_utf32 <= 0x1f { - ((key_utf32 as u8 + 0x60) as char).to_string() + // map ctrl-a to `a` + // ctrl-0..9 may emit control codes like ctrl-[, but + // we don't want to map them to `[` + } else if key_utf32 <= 0x1f + && !name.chars().next().is_some_and(|c| c.is_ascii_digit()) + { + ((key_utf32 as u8 + 0x40) as char) + .to_ascii_lowercase() + .to_string() } else { name }