Skip to content

Commit

Permalink
Made KeyEvent::from_str work for "-" as it fails the integration test…
Browse files Browse the repository at this point in the history
…s if the temp files contain one
  • Loading branch information
bjorn-ove committed Oct 6, 2023
1 parent 68fce3e commit 198a91c
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions helix-view/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,14 @@ impl std::str::FromStr for KeyEvent {
type Err = Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
// NOTE: Need to handle dash/minus specially as the split bellow will fail
if s == "-" {
return Ok(KeyEvent {
code: KeyCode::Char('-'),
modifiers: KeyModifiers::empty(),
});
}

let mut tokens: Vec<_> = s.split('-').collect();
let code = match tokens.pop().ok_or_else(|| anyhow!("Missing key code"))? {
keys::BACKSPACE => KeyCode::Backspace,
Expand Down Expand Up @@ -813,6 +821,64 @@ mod test {
},
])
);

assert_eq!(
parse_macro(":w aa-bb.txt<ret>").ok(),
Some(vec![
KeyEvent {
code: KeyCode::Char(':'),
modifiers: KeyModifiers::NONE,
},
KeyEvent {
code: KeyCode::Char('w'),
modifiers: KeyModifiers::NONE,
},
KeyEvent {
code: KeyCode::Char(' '),
modifiers: KeyModifiers::NONE,
},
KeyEvent {
code: KeyCode::Char('a'),
modifiers: KeyModifiers::NONE,
},
KeyEvent {
code: KeyCode::Char('a'),
modifiers: KeyModifiers::NONE,
},
KeyEvent {
code: KeyCode::Char('-'),
modifiers: KeyModifiers::NONE,
},
KeyEvent {
code: KeyCode::Char('b'),
modifiers: KeyModifiers::NONE,
},
KeyEvent {
code: KeyCode::Char('b'),
modifiers: KeyModifiers::NONE,
},
KeyEvent {
code: KeyCode::Char('.'),
modifiers: KeyModifiers::NONE,
},
KeyEvent {
code: KeyCode::Char('t'),
modifiers: KeyModifiers::NONE,
},
KeyEvent {
code: KeyCode::Char('x'),
modifiers: KeyModifiers::NONE,
},
KeyEvent {
code: KeyCode::Char('t'),
modifiers: KeyModifiers::NONE,
},
KeyEvent {
code: KeyCode::Enter,
modifiers: KeyModifiers::NONE,
},
])
);
}

#[test]
Expand Down

0 comments on commit 198a91c

Please sign in to comment.