Skip to content

Commit

Permalink
Make parse_macro work for "-" outside "<..>" (helix-editor#8475)
Browse files Browse the repository at this point in the history
* Translate  to   when a part of the outher string in

* Changed the if a little
  • Loading branch information
bjorn-ove authored and dgkf committed Jan 30, 2024
1 parent 564e974 commit 929eae1
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion helix-view/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ pub fn parse_macro(keys_str: &str) -> anyhow::Result<Vec<KeyEvent>> {
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") {
Expand Down Expand Up @@ -813,6 +813,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 929eae1

Please sign in to comment.