feat: allows shorthand forms like <C-S-x> as <C-X>

This commit is contained in:
sxyazi 2024-08-09 15:26:46 +08:00
parent c8add31606
commit 5fd24e8218
No known key found for this signature in database
2 changed files with 7 additions and 5 deletions

View file

@ -67,9 +67,8 @@ impl FromStr for Key {
let mut key = Self::default(); let mut key = Self::default();
if !s.starts_with('<') || !s.ends_with('>') { if !s.starts_with('<') || !s.ends_with('>') {
let c = s.chars().next().unwrap(); key.code = KeyCode::Char(s.chars().next().unwrap());
key.code = KeyCode::Char(c); key.shift = matches!(key.code, KeyCode::Char(c) if c.is_ascii_uppercase());
key.shift = c.is_ascii_uppercase();
return Ok(key); return Ok(key);
} }
@ -118,7 +117,10 @@ impl FromStr for Key {
"esc" => key.code = KeyCode::Esc, "esc" => key.code = KeyCode::Esc,
_ => match next { _ => match next {
s if it.peek().is_none() => key.code = KeyCode::Char(s.chars().next().unwrap()), s if it.peek().is_none() => {
key.code = KeyCode::Char(s.chars().next().unwrap());
key.shift = matches!(key.code, KeyCode::Char(c) if c.is_ascii_uppercase());
}
s => bail!("unknown key: {s}"), s => bail!("unknown key: {s}"),
}, },
} }