mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 17:36:19 +04:00
simplify some keymap key names (#2677)
This commit is contained in:
parent
0035c29fc1
commit
8351a82c2c
@ -33,12 +33,7 @@ # At most one section each of 'keys.normal', 'keys.insert' and 'keys.select'
|
|||||||
| Backspace | `"backspace"` |
|
| Backspace | `"backspace"` |
|
||||||
| Space | `"space"` |
|
| Space | `"space"` |
|
||||||
| Return/Enter | `"ret"` |
|
| Return/Enter | `"ret"` |
|
||||||
| < | `"lt"` |
|
|
||||||
| \> | `"gt"` |
|
|
||||||
| \+ | `"plus"` |
|
|
||||||
| \- | `"minus"` |
|
| \- | `"minus"` |
|
||||||
| ; | `"semicolon"` |
|
|
||||||
| % | `"percent"` |
|
|
||||||
| Left | `"left"` |
|
| Left | `"left"` |
|
||||||
| Right | `"right"` |
|
| Right | `"right"` |
|
||||||
| Up | `"up"` |
|
| Up | `"up"` |
|
||||||
|
@ -41,12 +41,7 @@ pub(crate) mod keys {
|
|||||||
pub(crate) const NULL: &str = "null";
|
pub(crate) const NULL: &str = "null";
|
||||||
pub(crate) const ESC: &str = "esc";
|
pub(crate) const ESC: &str = "esc";
|
||||||
pub(crate) const SPACE: &str = "space";
|
pub(crate) const SPACE: &str = "space";
|
||||||
pub(crate) const LESS_THAN: &str = "lt";
|
|
||||||
pub(crate) const GREATER_THAN: &str = "gt";
|
|
||||||
pub(crate) const PLUS: &str = "plus";
|
|
||||||
pub(crate) const MINUS: &str = "minus";
|
pub(crate) const MINUS: &str = "minus";
|
||||||
pub(crate) const SEMICOLON: &str = "semicolon";
|
|
||||||
pub(crate) const PERCENT: &str = "percent";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for KeyEvent {
|
impl fmt::Display for KeyEvent {
|
||||||
@ -86,12 +81,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result {
|
|||||||
KeyCode::Null => f.write_str(keys::NULL)?,
|
KeyCode::Null => f.write_str(keys::NULL)?,
|
||||||
KeyCode::Esc => f.write_str(keys::ESC)?,
|
KeyCode::Esc => f.write_str(keys::ESC)?,
|
||||||
KeyCode::Char(' ') => f.write_str(keys::SPACE)?,
|
KeyCode::Char(' ') => f.write_str(keys::SPACE)?,
|
||||||
KeyCode::Char('<') => f.write_str(keys::LESS_THAN)?,
|
|
||||||
KeyCode::Char('>') => f.write_str(keys::GREATER_THAN)?,
|
|
||||||
KeyCode::Char('+') => f.write_str(keys::PLUS)?,
|
|
||||||
KeyCode::Char('-') => f.write_str(keys::MINUS)?,
|
KeyCode::Char('-') => f.write_str(keys::MINUS)?,
|
||||||
KeyCode::Char(';') => f.write_str(keys::SEMICOLON)?,
|
|
||||||
KeyCode::Char('%') => f.write_str(keys::PERCENT)?,
|
|
||||||
KeyCode::F(i) => f.write_fmt(format_args!("F{}", i))?,
|
KeyCode::F(i) => f.write_fmt(format_args!("F{}", i))?,
|
||||||
KeyCode::Char(c) => f.write_fmt(format_args!("{}", c))?,
|
KeyCode::Char(c) => f.write_fmt(format_args!("{}", c))?,
|
||||||
};
|
};
|
||||||
@ -119,12 +109,7 @@ fn width(&self) -> usize {
|
|||||||
KeyCode::Null => keys::NULL.len(),
|
KeyCode::Null => keys::NULL.len(),
|
||||||
KeyCode::Esc => keys::ESC.len(),
|
KeyCode::Esc => keys::ESC.len(),
|
||||||
KeyCode::Char(' ') => keys::SPACE.len(),
|
KeyCode::Char(' ') => keys::SPACE.len(),
|
||||||
KeyCode::Char('<') => keys::LESS_THAN.len(),
|
|
||||||
KeyCode::Char('>') => keys::GREATER_THAN.len(),
|
|
||||||
KeyCode::Char('+') => keys::PLUS.len(),
|
|
||||||
KeyCode::Char('-') => keys::MINUS.len(),
|
KeyCode::Char('-') => keys::MINUS.len(),
|
||||||
KeyCode::Char(';') => keys::SEMICOLON.len(),
|
|
||||||
KeyCode::Char('%') => keys::PERCENT.len(),
|
|
||||||
KeyCode::F(1..=9) => 2,
|
KeyCode::F(1..=9) => 2,
|
||||||
KeyCode::F(_) => 3,
|
KeyCode::F(_) => 3,
|
||||||
KeyCode::Char(c) => c.width().unwrap_or(0),
|
KeyCode::Char(c) => c.width().unwrap_or(0),
|
||||||
@ -168,12 +153,7 @@ fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|||||||
keys::NULL => KeyCode::Null,
|
keys::NULL => KeyCode::Null,
|
||||||
keys::ESC => KeyCode::Esc,
|
keys::ESC => KeyCode::Esc,
|
||||||
keys::SPACE => KeyCode::Char(' '),
|
keys::SPACE => KeyCode::Char(' '),
|
||||||
keys::LESS_THAN => KeyCode::Char('<'),
|
|
||||||
keys::GREATER_THAN => KeyCode::Char('>'),
|
|
||||||
keys::PLUS => KeyCode::Char('+'),
|
|
||||||
keys::MINUS => KeyCode::Char('-'),
|
keys::MINUS => KeyCode::Char('-'),
|
||||||
keys::SEMICOLON => KeyCode::Char(';'),
|
|
||||||
keys::PERCENT => KeyCode::Char('%'),
|
|
||||||
single if single.chars().count() == 1 => KeyCode::Char(single.chars().next().unwrap()),
|
single if single.chars().count() == 1 => KeyCode::Char(single.chars().next().unwrap()),
|
||||||
function if function.len() > 1 && function.starts_with('F') => {
|
function if function.len() > 1 && function.starts_with('F') => {
|
||||||
let function: String = function.chars().skip(1).collect();
|
let function: String = function.chars().skip(1).collect();
|
||||||
@ -336,6 +316,14 @@ fn parsing_unmodified_keys() {
|
|||||||
modifiers: KeyModifiers::NONE
|
modifiers: KeyModifiers::NONE
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
str::parse::<KeyEvent>("%").unwrap(),
|
||||||
|
KeyEvent {
|
||||||
|
code: KeyCode::Char('%'),
|
||||||
|
modifiers: KeyModifiers::NONE
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -375,6 +363,16 @@ fn parsing_nonsensical_keys_fails() {
|
|||||||
assert!(str::parse::<KeyEvent>("FU").is_err());
|
assert!(str::parse::<KeyEvent>("FU").is_err());
|
||||||
assert!(str::parse::<KeyEvent>("123").is_err());
|
assert!(str::parse::<KeyEvent>("123").is_err());
|
||||||
assert!(str::parse::<KeyEvent>("S--").is_err());
|
assert!(str::parse::<KeyEvent>("S--").is_err());
|
||||||
|
assert!(str::parse::<KeyEvent>("S-percent").is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parsing_unsupported_named_keys() {
|
||||||
|
assert!(str::parse::<KeyEvent>("lt").is_err());
|
||||||
|
assert!(str::parse::<KeyEvent>("gt").is_err());
|
||||||
|
assert!(str::parse::<KeyEvent>("plus").is_err());
|
||||||
|
assert!(str::parse::<KeyEvent>("percent").is_err());
|
||||||
|
assert!(str::parse::<KeyEvent>("semicolon").is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user