From 574f82130892d4a388bfdcce63fe2c4a190e479e Mon Sep 17 00:00:00 2001 From: Bjorn Ove Hay Andersen Date: Thu, 12 Oct 2023 14:09:57 +0200 Subject: Make parse_macro work for "-" outside "<..>" (#8475) * Translate to when a part of the outher string in * Changed the if a little--- helix-view/src/input.rs | 60 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) (limited to 'helix-view/src') diff --git a/helix-view/src/input.rs b/helix-view/src/input.rs index 87a0bfca..0f4ffaac 100644 --- a/helix-view/src/input.rs +++ b/helix-view/src/input.rs @@ -549,7 +549,7 @@ pub fn parse_macro(keys_str: &str) -> anyhow::Result> { if c == ">" { keys_res = Err(anyhow!("Unmatched '>'")); } else if c != "<" { - keys.push(c); + keys.push(if c == "-" { keys::MINUS } else { c }); i += end_i; } else { match s.find('>').context("'>' expected") { @@ -813,6 +813,64 @@ mod test { }, ]) ); + + assert_eq!( + parse_macro(":w aa-bb.txt").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] -- cgit v1.2.3-70-g09d2