mirror of
https://github.com/lotabout/skim.git
synced 2026-09-10 07:16:23 -04:00
fix: ignore {+} expressions when splitting action chains (closes #910)
This commit is contained in:
parent
c8acb4b976
commit
efb2ea8be5
34
src/binds.rs
34
src/binds.rs
|
|
@ -202,14 +202,12 @@ where
|
|||
/// Parses an action chain, separated by '+'s into the corresponding actions
|
||||
pub fn parse_action_chain(action_chain: &str) -> Result<Vec<Action>> {
|
||||
let mut actions: Vec<Action> = vec![];
|
||||
let mut split = action_chain.split('+');
|
||||
let mut split = action_chain.split("+");
|
||||
loop {
|
||||
let opt_s = split.next();
|
||||
if opt_s.is_none() {
|
||||
let Some(mut s) = split.next().map(String::from) else {
|
||||
break;
|
||||
}
|
||||
let mut s = opt_s.unwrap().to_string();
|
||||
if s.starts_with("if-")
|
||||
};
|
||||
if (s.starts_with("if-") || s.ends_with("{"))
|
||||
&& let Some(otherwise) = split.next()
|
||||
{
|
||||
s += &(String::from("+") + otherwise);
|
||||
|
|
@ -237,3 +235,27 @@ pub fn parse_keymap(key_action: &str) -> Result<(&str, Vec<Action>)> {
|
|||
debug!("parsed key_action: {:?}: {:?}", key, action_chain);
|
||||
Ok((key, parse_action_chain(action_chain)?))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use event::Action::*;
|
||||
#[test]
|
||||
fn test_parse_action_chain() {
|
||||
let parsed = parse_action_chain(
|
||||
"execute-silent:1 {}+execute-silent:2 {+}+execute-silent:3 {+n}+reload+if-query-empty:reload+up",
|
||||
);
|
||||
assert!(parsed.is_ok());
|
||||
let res = parsed.unwrap();
|
||||
assert_eq!(
|
||||
res,
|
||||
vec![
|
||||
ExecuteSilent("1 {}".into()),
|
||||
ExecuteSilent("2 {+}".into()),
|
||||
ExecuteSilent("3 {+n}".into()),
|
||||
Reload(None),
|
||||
IfQueryEmpty("reload".into(), Some("up".into())),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue