Skip to content

Commit

Permalink
Allow less than and greater than in macros (helix-editor#3556)
Browse files Browse the repository at this point in the history
* Allow less than and greater than in macros

* Fix failing test
  • Loading branch information
A-Walrus authored and thomasskk committed Sep 9, 2022
1 parent 2aa4781 commit d7baf46
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions helix-view/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))?,
};
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -548,8 +554,6 @@ mod test {

#[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());
Expand Down

0 comments on commit d7baf46

Please sign in to comment.