From 0a66161137988ff197d3a2381841232b4f8066d1 Mon Sep 17 00:00:00 2001 From: Bjorn Ove Hay Andersen Date: Mon, 9 Oct 2023 10:21:20 +0200 Subject: [PATCH 1/2] Translate to when a part of the outher string in --- helix-view/src/input.rs | 64 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/helix-view/src/input.rs b/helix-view/src/input.rs index 87a0bfcaa602..78b2ced0a73e 100644 --- a/helix-view/src/input.rs +++ b/helix-view/src/input.rs @@ -549,7 +549,11 @@ pub fn parse_macro(keys_str: &str) -> anyhow::Result> { if c == ">" { keys_res = Err(anyhow!("Unmatched '>'")); } else if c != "<" { - keys.push(c); + if c != "-" { + keys.push(c); + } else { + keys.push("minus"); + } i += end_i; } else { match s.find('>').context("'>' expected") { @@ -813,6 +817,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] From 037e4f3df1999c17381c3eab2d6435e040beb56c Mon Sep 17 00:00:00 2001 From: Bjorn Ove Hay Andersen Date: Tue, 10 Oct 2023 09:39:04 +0200 Subject: [PATCH 2/2] Changed the if a little --- helix-view/src/input.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/helix-view/src/input.rs b/helix-view/src/input.rs index 78b2ced0a73e..0f4ffaacf9cc 100644 --- a/helix-view/src/input.rs +++ b/helix-view/src/input.rs @@ -549,11 +549,7 @@ pub fn parse_macro(keys_str: &str) -> anyhow::Result> { if c == ">" { keys_res = Err(anyhow!("Unmatched '>'")); } else if c != "<" { - if c != "-" { - keys.push(c); - } else { - keys.push("minus"); - } + keys.push(if c == "-" { keys::MINUS } else { c }); i += end_i; } else { match s.find('>').context("'>' expected") {