Skip to content

Commit

Permalink
Merge pull request #199 from lotabout/ticket-196
Browse files Browse the repository at this point in the history
fix #196: `+` in execute was eaten by skim
  • Loading branch information
lotabout authored Jul 14, 2019
2 parents 65aad28 + 2f4786e commit 711eab5
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ impl Input {

// key_action is comma separated: 'ctrl-j:accept,ctrl-k:kill-line'
pub fn parse_keymap(&mut self, key_action: &str) {
debug!("got key_action: {:?}", key_action);
for (key, action_chain) in parse_key_action(key_action).into_iter() {
debug!("parsed key_action: {:?}: {:?}", key, action_chain);
let action_chain = action_chain
.into_iter()
.filter_map(|(action, arg)| {
Expand Down Expand Up @@ -112,18 +114,28 @@ pub fn parse_key_action(key_action: &str) -> Vec<(&str, Vec<(&str, Option<String
Regex::new(r#"(?si)([^:]+?):((?:\+?[a-z-]+?(?:"[^"]*?"|'[^']*?'|\([^\)]*?\)|\[[^\]]*?\]|:[^:]*?)?\s*)+)(?:,|$)"#)
.unwrap();
// grab key, action and arg out.
static ref RE_BIND: Regex = Regex::new(r#"(?si)([a-z-]+)(?:[:\(\["'](.+?)[\)"'\]]?)?(?:\+|$)"#).unwrap();
static ref RE_BIND: Regex = Regex::new(r#"(?si)([a-z-]+)("[^"]+?"|'[^']+?'|\([^\)]+?\)|\[[^\]]+?\]|:[^:]+?)?(?:\+|$)"#).unwrap();
}

RE.captures_iter(&key_action)
.map(|caps| {
debug!("RE: caps: {:?}", caps);
let key = caps.get(1).unwrap().as_str();
let actions = RE_BIND
.captures_iter(caps.get(2).unwrap().as_str())
.map(|caps| {
debug!("RE_BIND: caps: {:?}", caps);
(
caps.get(1).unwrap().as_str(),
caps.get(2).map(|s| s.as_str().to_string()),
caps.get(2).map(|s| {
// (arg) => arg, :end_arg => arg
let action = s.as_str();
if action.starts_with(":") {
return action[1..].to_string();
} else {
return action[1..action.len() - 1].to_string();
}
}),
)
})
.collect();
Expand Down Expand Up @@ -224,6 +236,14 @@ mod test {
("ctrl-y", vec![("execute-silent", Some("echo {} | pbcopy".to_string()))]),
key_action[1]
);

// #196
let key_action_str = "enter:execute($EDITOR +{2} {1})";
let key_action = parse_key_action(key_action_str);
assert_eq!(
("enter", vec![("execute", Some("$EDITOR +{2} {1}".to_string()))]),
key_action[0]
);
}

#[test]
Expand Down

0 comments on commit 711eab5

Please sign in to comment.