diff options
author | Henry | 2022-06-06 02:22:10 +0000 |
---|---|---|
committer | GitHub | 2022-06-06 02:22:10 +0000 |
commit | 8351a82c2cae58dd49c654d0e878c9d7227ef9c8 (patch) | |
tree | 5aaf8913ee98abd84c9bcae3a50e65c890419c19 /helix-view/src | |
parent | 0035c29fc16f6c795257e241fddd9f2178bc4b4c (diff) |
simplify some keymap key names (#2677)
Diffstat (limited to 'helix-view/src')
-rw-r--r-- | helix-view/src/input.rs | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/helix-view/src/input.rs b/helix-view/src/input.rs index 14dadc3b..b4875d49 100644 --- a/helix-view/src/input.rs +++ b/helix-view/src/input.rs @@ -41,12 +41,7 @@ pub(crate) mod keys { pub(crate) const NULL: &str = "null"; pub(crate) const ESC: &str = "esc"; 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 SEMICOLON: &str = "semicolon"; - pub(crate) const PERCENT: &str = "percent"; } impl fmt::Display for KeyEvent { @@ -86,12 +81,7 @@ impl fmt::Display for KeyEvent { KeyCode::Null => f.write_str(keys::NULL)?, KeyCode::Esc => f.write_str(keys::ESC)?, 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::SEMICOLON)?, - KeyCode::Char('%') => f.write_str(keys::PERCENT)?, KeyCode::F(i) => f.write_fmt(format_args!("F{}", i))?, KeyCode::Char(c) => f.write_fmt(format_args!("{}", c))?, }; @@ -119,12 +109,7 @@ impl UnicodeWidthStr for KeyEvent { KeyCode::Null => keys::NULL.len(), KeyCode::Esc => keys::ESC.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::SEMICOLON.len(), - KeyCode::Char('%') => keys::PERCENT.len(), KeyCode::F(1..=9) => 2, KeyCode::F(_) => 3, KeyCode::Char(c) => c.width().unwrap_or(0), @@ -168,12 +153,7 @@ impl std::str::FromStr for KeyEvent { keys::NULL => KeyCode::Null, keys::ESC => KeyCode::Esc, keys::SPACE => KeyCode::Char(' '), - keys::LESS_THAN => KeyCode::Char('<'), - keys::GREATER_THAN => KeyCode::Char('>'), - keys::PLUS => 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()), function if function.len() > 1 && function.starts_with('F') => { let function: String = function.chars().skip(1).collect(); @@ -336,6 +316,14 @@ mod test { modifiers: KeyModifiers::NONE } ); + + assert_eq!( + str::parse::<KeyEvent>("%").unwrap(), + KeyEvent { + code: KeyCode::Char('%'), + modifiers: KeyModifiers::NONE + } + ) } #[test] @@ -375,6 +363,16 @@ mod test { assert!(str::parse::<KeyEvent>("FU").is_err()); assert!(str::parse::<KeyEvent>("123").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] |