Always use capital letters when rendering a keystroke

This commit is contained in:
Max Brunsfeld
2022-06-16 17:48:10 -07:00
parent a3b17ffd15
commit 2c61bc2b1f
2 changed files with 24 additions and 21 deletions
+4 -7
View File
@@ -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 {
+20 -14
View File
@@ -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)
}
}