fix: ignore {+} expressions when splitting action chains (closes #910)

This commit is contained in:
Loric ANDRE 2026-01-22 13:49:39 +01:00
parent c8acb4b976
commit efb2ea8be5

View file

@ -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())),
]
);
}
}