From 2c61bc2b1fd8ccb4a4164a025a4a294d4709c7be Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 16 Jun 2022 17:48:10 -0700 Subject: [PATCH] Always use capital letters when rendering a keystroke --- crates/gpui/src/elements/keystroke_label.rs | 11 +++---- crates/gpui/src/keymap.rs | 34 ++++++++++++--------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/crates/gpui/src/elements/keystroke_label.rs b/crates/gpui/src/elements/keystroke_label.rs index 2cd55e5ff0238a8fc801a801d9b710edaab33db4..0112b548463b450c0b49aa5e1ad4c93f633a5d10 100644 --- a/crates/gpui/src/elements/keystroke_label.rs +++ b/crates/gpui/src/elements/keystroke_label.rs @@ -40,13 +40,10 @@ impl Element for KeystrokeLabel { let mut element = if let Some(keystrokes) = cx.keystrokes_for_action(self.action.as_ref()) { Flex::row() .with_children(keystrokes.iter().map(|keystroke| { - Label::new( - keystroke.to_string().to_uppercase(), - self.text_style.clone(), - ) - .contained() - .with_style(self.container_style) - .boxed() + Label::new(keystroke.to_string(), self.text_style.clone()) + .contained() + .with_style(self.container_style) + .boxed() })) .boxed() } else { diff --git a/crates/gpui/src/keymap.rs b/crates/gpui/src/keymap.rs index 786adad704a1a72f7266c59c5a4021ea45ae3a9e..22cb3ba5dea4d357405f2e0d99b1e2efe6242d6a 100644 --- a/crates/gpui/src/keymap.rs +++ b/crates/gpui/src/keymap.rs @@ -4,7 +4,7 @@ use smallvec::SmallVec; use std::{ any::{Any, TypeId}, collections::{HashMap, HashSet}, - fmt::Debug, + fmt::{Debug, Write}, }; use tree_sitter::{Language, Node, Parser}; @@ -318,28 +318,34 @@ impl Keystroke { impl std::fmt::Display for Keystroke { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { if self.ctrl { - write!(f, "{}", "^")?; + f.write_char('^')?; } if self.alt { - write!(f, "{}", "⎇")?; + f.write_char('⎇')?; } if self.cmd { - write!(f, "{}", "⌘")?; + f.write_char('⌘')?; } if self.shift { - write!(f, "{}", "⇧")?; + f.write_char('⇧')?; } let key = match self.key.as_str() { - "backspace" => "⌫", - "up" => "↑", - "down" => "↓", - "left" => "←", - "right" => "→", - "tab" => "⇥", - "escape" => "⎋", - key => key, + "backspace" => '⌫', + "up" => '↑', + "down" => '↓', + "left" => '←', + "right" => '→', + "tab" => '⇥', + "escape" => '⎋', + key => { + if key.len() == 1 { + key.chars().next().unwrap().to_ascii_uppercase() + } else { + return f.write_str(key); + } + } }; - write!(f, "{}", key) + f.write_char(key) } }