From d7baf4637a17ac9c36f6b73befc647b346cf8465 Mon Sep 17 00:00:00 2001 From: A-Walrus <58790821+A-Walrus@users.noreply.github.com> Date: Tue, 30 Aug 2022 04:58:51 +0300 Subject: [PATCH] Allow less than and greater than in macros (#3556) * Allow less than and greater than in macros * Fix failing test --- helix-view/src/input.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/helix-view/src/input.rs b/helix-view/src/input.rs index 9fa679dff105f..a7f526ba7c597 100644 --- a/helix-view/src/input.rs +++ b/helix-view/src/input.rs @@ -116,6 +116,8 @@ pub(crate) mod keys { pub(crate) const ESC: &str = "esc"; pub(crate) const SPACE: &str = "space"; pub(crate) const MINUS: &str = "minus"; + pub(crate) const LESS_THAN: &str = "lt"; + pub(crate) const GREATER_THAN: &str = "gt"; } impl fmt::Display for KeyEvent { @@ -156,6 +158,8 @@ impl fmt::Display for KeyEvent { KeyCode::Esc => f.write_str(keys::ESC)?, KeyCode::Char(' ') => f.write_str(keys::SPACE)?, KeyCode::Char('-') => f.write_str(keys::MINUS)?, + KeyCode::Char('<') => f.write_str(keys::LESS_THAN)?, + KeyCode::Char('>') => f.write_str(keys::GREATER_THAN)?, KeyCode::F(i) => f.write_fmt(format_args!("F{}", i))?, KeyCode::Char(c) => f.write_fmt(format_args!("{}", c))?, }; @@ -228,6 +232,8 @@ impl std::str::FromStr for KeyEvent { keys::ESC => KeyCode::Esc, keys::SPACE => KeyCode::Char(' '), keys::MINUS => KeyCode::Char('-'), + keys::LESS_THAN => KeyCode::Char('<'), + keys::GREATER_THAN => 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(); @@ -548,8 +554,6 @@ mod test { #[test] fn parsing_unsupported_named_keys() { - assert!(str::parse::("lt").is_err()); - assert!(str::parse::("gt").is_err()); assert!(str::parse::("plus").is_err()); assert!(str::parse::("percent").is_err()); assert!(str::parse::("semicolon").is_err());