kbd: Fix Kdb to support display - key. (#1109)
This commit is contained in:
parent
efa2c7c9ef
commit
6c7a28c818
2 changed files with 65 additions and 67 deletions
|
|
@ -49,6 +49,8 @@ impl Render for KbdStory {
|
||||||
.gap_2()
|
.gap_2()
|
||||||
.child(Kbd::new(Keystroke::parse("cmd-shift-p").unwrap()))
|
.child(Kbd::new(Keystroke::parse("cmd-shift-p").unwrap()))
|
||||||
.child(Kbd::new(Keystroke::parse("cmd-ctrl-t").unwrap()))
|
.child(Kbd::new(Keystroke::parse("cmd-ctrl-t").unwrap()))
|
||||||
|
.child(Kbd::new(Keystroke::parse("cmd--").unwrap()))
|
||||||
|
.child(Kbd::new(Keystroke::parse("cmd-+").unwrap()))
|
||||||
.child(Kbd::new(Keystroke::parse("escape").unwrap()))
|
.child(Kbd::new(Keystroke::parse("escape").unwrap()))
|
||||||
.child(Kbd::new(Keystroke::parse("backspace").unwrap()))
|
.child(Kbd::new(Keystroke::parse("backspace").unwrap()))
|
||||||
.child(Kbd::new(Keystroke::parse("/").unwrap()))
|
.child(Kbd::new(Keystroke::parse("/").unwrap()))
|
||||||
|
|
|
||||||
|
|
@ -107,13 +107,8 @@ impl Kbd {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut keys = String::new();
|
let mut keys = String::new();
|
||||||
|
let key_str = key.key.as_str();
|
||||||
for key in key.key.split("-") {
|
match key_str {
|
||||||
if parts.len() > 0 && keys.len() > 0 {
|
|
||||||
keys.push_str(DIVIDER);
|
|
||||||
}
|
|
||||||
|
|
||||||
match key {
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
"ctrl" => keys.push('⌃'),
|
"ctrl" => keys.push('⌃'),
|
||||||
#[cfg(not(target_os = "macos"))]
|
#[cfg(not(target_os = "macos"))]
|
||||||
|
|
@ -167,14 +162,13 @@ impl Kbd {
|
||||||
#[cfg(not(target_os = "macos"))]
|
#[cfg(not(target_os = "macos"))]
|
||||||
"down" => keys.push_str("Down"),
|
"down" => keys.push_str("Down"),
|
||||||
_ => {
|
_ => {
|
||||||
if key.len() == 1 {
|
if key_str.len() == 1 {
|
||||||
keys.push_str(&key.to_uppercase());
|
keys.push_str(&key_str.to_uppercase());
|
||||||
} else {
|
} else {
|
||||||
if let Some(first_char) = key.chars().next() {
|
if let Some(first_char) = key_str.chars().next() {
|
||||||
keys.push_str(&format!("{}{}", first_char.to_uppercase(), &key[1..]));
|
keys.push_str(&format!("{}{}", first_char.to_uppercase(), &key_str[1..]));
|
||||||
} else {
|
} else {
|
||||||
keys.push_str(&key);
|
keys.push_str(&key_str);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -224,6 +218,8 @@ mod tests {
|
||||||
|
|
||||||
if cfg!(target_os = "macos") {
|
if cfg!(target_os = "macos") {
|
||||||
assert_eq!(Kbd::format(&Keystroke::parse("cmd-a").unwrap()), "⌘A");
|
assert_eq!(Kbd::format(&Keystroke::parse("cmd-a").unwrap()), "⌘A");
|
||||||
|
assert_eq!(Kbd::format(&Keystroke::parse("cmd--").unwrap()), "⌘-");
|
||||||
|
assert_eq!(Kbd::format(&Keystroke::parse("cmd-+").unwrap()), "⌘+");
|
||||||
assert_eq!(Kbd::format(&Keystroke::parse("cmd-enter").unwrap()), "⌘⏎");
|
assert_eq!(Kbd::format(&Keystroke::parse("cmd-enter").unwrap()), "⌘⏎");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Kbd::format(&Keystroke::parse("secondary-f12").unwrap()),
|
Kbd::format(&Keystroke::parse("secondary-f12").unwrap()),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue