mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: allows shorthand forms like <C-S-x> as <C-X> (#1448)
This commit is contained in:
parent
c8add31606
commit
5f923e8706
2 changed files with 9 additions and 7 deletions
|
|
@ -231,7 +231,7 @@ keymap = [
|
||||||
{ on = "<End>", run = "move 999", desc = "Move to the EOL" },
|
{ on = "<End>", run = "move 999", desc = "Move to the EOL" },
|
||||||
|
|
||||||
# Delete
|
# 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 = "<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-h>", run = "backspace", desc = "Delete the character before the cursor" },
|
||||||
{ on = "<C-d>", run = "backspace --under", desc = "Delete the character under the cursor" },
|
{ on = "<C-d>", run = "backspace --under", desc = "Delete the character under the cursor" },
|
||||||
|
|
|
||||||
|
|
@ -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,11 @@ 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() => {
|
||||||
|
let c = s.chars().next().unwrap();
|
||||||
|
key.shift |= c.is_ascii_uppercase();
|
||||||
|
key.code = KeyCode::Char(if key.shift { c.to_ascii_uppercase() } else { c });
|
||||||
|
}
|
||||||
s => bail!("unknown key: {s}"),
|
s => bail!("unknown key: {s}"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -134,7 +137,6 @@ impl FromStr for Key {
|
||||||
impl Display for Key {
|
impl Display for Key {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
if let Some(c) = self.plain() {
|
if let Some(c) = self.plain() {
|
||||||
let c = if self.shift { c.to_ascii_uppercase() } else { c };
|
|
||||||
return if c == ' ' { write!(f, "<Space>") } else { f.write_char(c) };
|
return if c == ' ' { write!(f, "<Space>") } else { f.write_char(c) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -190,7 +192,7 @@ impl Display for Key {
|
||||||
|
|
||||||
KeyCode::Char(' ') => "Space",
|
KeyCode::Char(' ') => "Space",
|
||||||
KeyCode::Char(c) => {
|
KeyCode::Char(c) => {
|
||||||
f.write_char(if self.shift { c.to_ascii_uppercase() } else { c })?;
|
f.write_char(c)?;
|
||||||
""
|
""
|
||||||
}
|
}
|
||||||
_ => "Unknown",
|
_ => "Unknown",
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue