From cb893ccd84fcd2faa9f1d2696d5ceec939ed4147 Mon Sep 17 00:00:00 2001 From: Junkui Zhang <364772080@qq.com> Date: Tue, 6 May 2025 19:22:28 +0800 Subject: [PATCH] use `is_immutable_key` again --- crates/gpui/src/platform/linux/keyboard.rs | 64 +++++++++++++++++++++- crates/gpui/src/platform/linux/platform.rs | 9 +-- 2 files changed, 64 insertions(+), 9 deletions(-) diff --git a/crates/gpui/src/platform/linux/keyboard.rs b/crates/gpui/src/platform/linux/keyboard.rs index 36cae6a43b..2b65173d35 100644 --- a/crates/gpui/src/platform/linux/keyboard.rs +++ b/crates/gpui/src/platform/linux/keyboard.rs @@ -61,7 +61,7 @@ impl PlatformKeyboardMapper for LinuxKeyboardMapper { } fn get_shifted_key(&self, key: &str) -> anyhow::Result> { - if key.chars().count() != 1 { + if is_immutable_key(key) { return Ok(None); } if is_alphabetic_key(key) { @@ -183,6 +183,68 @@ const TYPEABLE_CODES: &[u32] = &[ 0x003d, // / Slash ]; +#[cfg(any(feature = "wayland", feature = "x11"))] +fn is_immutable_key(key: &str) -> bool { + matches!( + key, + "f1" | "f2" + | "f3" + | "f4" + | "f5" + | "f6" + | "f7" + | "f8" + | "f9" + | "f10" + | "f11" + | "f12" + | "f13" + | "f14" + | "f15" + | "f16" + | "f17" + | "f18" + | "f19" + | "f20" + | "f21" + | "f22" + | "f23" + | "f24" + | "backspace" + | "delete" + | "left" + | "right" + | "up" + | "down" + | "pageup" + | "pagedown" + | "insert" + | "home" + | "end" + | "back" + | "forward" + | "escape" + | "space" + | "tab" + | "enter" + | "shift" + | "control" + | "alt" + | "platform" + | "cmd" + | "super" + | "win" + | "fn" + | "menu" + | "copy" + | "paste" + | "cut" + | "find" + | "open" + | "save" + ) +} + #[cfg(any(feature = "wayland", feature = "x11"))] fn get_scan_code(scan_code: ScanCode) -> Option { // https://github.com/microsoft/node-native-keymap/blob/main/deps/chromium/dom_code_data.inc diff --git a/crates/gpui/src/platform/linux/platform.rs b/crates/gpui/src/platform/linux/platform.rs index d51f8f6087..901575eed3 100644 --- a/crates/gpui/src/platform/linux/platform.rs +++ b/crates/gpui/src/platform/linux/platform.rs @@ -140,14 +140,7 @@ impl Platform for P { } fn keyboard_mapper(&self) -> Box { - #[cfg(any(feature = "wayland", feature = "x11"))] - { - Box::new(super::LinuxKeyboardMapper::new()) - } - #[cfg(not(any(feature = "wayland", feature = "x11")))] - { - Box::new(crate::EmptyKeyboardMapper) - } + Box::new(super::LinuxKeyboardMapper::new()) } fn keyboard_layout(&self) -> Box {