From 5fd24e82189e675ce541c3e8a67d2e3c47a97d2f Mon Sep 17 00:00:00 2001 From: sxyazi Date: Fri, 9 Aug 2024 15:26:46 +0800 Subject: [PATCH] feat: allows shorthand forms like `` as `` --- yazi-config/preset/keymap.toml | 2 +- yazi-config/src/keymap/key.rs | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/yazi-config/preset/keymap.toml b/yazi-config/preset/keymap.toml index d2350efe..9a2b7c28 100644 --- a/yazi-config/preset/keymap.toml +++ b/yazi-config/preset/keymap.toml @@ -231,7 +231,7 @@ keymap = [ { on = "", run = "move 999", desc = "Move to the EOL" }, # Delete - { on = "", run = "backspace", desc = "Delete the character before the cursor" }, + { on = "", run = "backspace", desc = "Delete the character before the cursor" }, { on = "", run = "backspace --under", desc = "Delete the character under the cursor" }, { on = "", run = "backspace", desc = "Delete the character before the cursor" }, { on = "", run = "backspace --under", desc = "Delete the character under the cursor" }, diff --git a/yazi-config/src/keymap/key.rs b/yazi-config/src/keymap/key.rs index d9a78106..7f8f1880 100644 --- a/yazi-config/src/keymap/key.rs +++ b/yazi-config/src/keymap/key.rs @@ -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}"), }, }