From 6ffd3f034f328332c0de52063cb08683d700e143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Marcos?= Date: Thu, 17 Apr 2025 21:48:00 -0300 Subject: [PATCH] Don't display MacOS key symbols in Linux (#29016) Release Notes: - Fix MacOS key symbols being displayed in other platforms. --- crates/gpui/src/platform/keystroke.rs | 40 +++++++++++++++++--------- crates/ui/src/components/keybinding.rs | 7 +---- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/crates/gpui/src/platform/keystroke.rs b/crates/gpui/src/platform/keystroke.rs index e2e977539f..5fc0141858 100644 --- a/crates/gpui/src/platform/keystroke.rs +++ b/crates/gpui/src/platform/keystroke.rs @@ -318,10 +318,18 @@ fn is_printable_key(key: &str) -> bool { impl std::fmt::Display for Keystroke { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { if self.modifiers.control { - f.write_char('^')?; + if cfg!(target_os = "macos") { + f.write_char('^')?; + } else { + write!(f, "ctrl-")?; + } } if self.modifiers.alt { - f.write_char('⌥')?; + if cfg!(target_os = "macos") { + f.write_char('⌥')?; + } else { + write!(f, "alt-")?; + } } if self.modifiers.platform { #[cfg(target_os = "macos")] @@ -334,20 +342,24 @@ impl std::fmt::Display for Keystroke { f.write_char('⊞')?; } if self.modifiers.shift { - f.write_char('⇧')?; + if cfg!(target_os = "macos") { + f.write_char('⇧')?; + } else { + write!(f, "shift-")?; + } } let key = match self.key.as_str() { - "backspace" => '⌫', - "up" => '↑', - "down" => '↓', - "left" => '←', - "right" => '→', - "tab" => '⇥', - "escape" => '⎋', - "shift" => '⇧', - "control" => '⌃', - "alt" => '⌥', - "platform" => '⌘', + "backspace" if cfg!(target_os = "macos") => '⌫', + "up" if cfg!(target_os = "macos") => '↑', + "down" if cfg!(target_os = "macos") => '↓', + "left" if cfg!(target_os = "macos") => '←', + "right" if cfg!(target_os = "macos") => '→', + "tab" if cfg!(target_os = "macos") => '⇥', + "escape" if cfg!(target_os = "macos") => '⎋', + "shift" if cfg!(target_os = "macos") => '⇧', + "control" if cfg!(target_os = "macos") => '⌃', + "alt" if cfg!(target_os = "macos") => '⌥', + "platform" if cfg!(target_os = "macos") => '⌘', key => { if key.len() == 1 { key.chars().next().unwrap().to_ascii_uppercase() diff --git a/crates/ui/src/components/keybinding.rs b/crates/ui/src/components/keybinding.rs index 1b3746515d..f41c76356c 100644 --- a/crates/ui/src/components/keybinding.rs +++ b/crates/ui/src/components/keybinding.rs @@ -378,12 +378,7 @@ pub fn text_for_keystroke(keystroke: &Keystroke, cx: &App) -> String { /// Returns a textual representation of the given [`Keystroke`]. fn keystroke_text(keystroke: &Keystroke, platform_style: PlatformStyle, vim_mode: bool) -> String { let mut text = String::new(); - - let delimiter = match (platform_style, vim_mode) { - (PlatformStyle::Mac, false) => '-', - (PlatformStyle::Linux | PlatformStyle::Windows, false) => '-', - (_, true) => '-', - }; + let delimiter = '-'; if keystroke.modifiers.function { match vim_mode {