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

@ -231,7 +231,7 @@ keymap = [
{ on = "<End>", run = "move 999", desc = "Move to the EOL" },
# Delete
{ on = "<Backspace>", run = "backspace", desc = "Delete the character before the cursor" },
{ on = "<Backspace>", run = "backspace", desc = "Delete the character before the cursor" },
{ on = "<Delete>", run = "backspace --under", desc = "Delete the character under the cursor" },
{ on = "<C-h>", run = "backspace", desc = "Delete the character before the cursor" },
{ on = "<C-d>", run = "backspace --under", desc = "Delete the character under the cursor" },

View file

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