diff --git a/espanso-match/src/regex/mod.rs b/espanso-match/src/regex/mod.rs index af34dd1..560f513 100644 --- a/espanso-match/src/regex/mod.rs +++ b/espanso-match/src/regex/mod.rs @@ -91,10 +91,12 @@ where "".to_string() }; - if let Event::Key { key: _, chars } = event { - if let Some(chars) = chars { - buffer.push_str(&chars); - } + if let Event::Key { + key: _, + chars: Some(chars), + } = event + { + buffer.push_str(&chars); } // Keep the buffer length in check @@ -259,13 +261,16 @@ mod tests { RegexMatch::new(2, "multi\\((?P.*?),(?P.*?)\\)"), ], RegexMatcherOptions { - max_buffer_size: 15 + max_buffer_size: 15, }, ); assert_eq!( get_matches_after_str("say hello(mary)", &matcher), vec![match_result(1, "hello(mary)", &[("name", "mary")])] ); - assert_eq!(get_matches_after_str("hello(very long name over buffer)", &matcher), vec![]); + assert_eq!( + get_matches_after_str("hello(very long name over buffer)", &matcher), + vec![] + ); } } diff --git a/espanso-match/src/rolling/matcher.rs b/espanso-match/src/rolling/matcher.rs index 6e9526b..136bed3 100644 --- a/espanso-match/src/rolling/matcher.rs +++ b/espanso-match/src/rolling/matcher.rs @@ -203,10 +203,10 @@ impl RollingMatcher { fn is_word_separator(&self, event: &Event) -> bool { match event { Event::Key { key, chars } => { - if self.key_word_separators.contains(&key) { + if self.key_word_separators.contains(key) { true } else if let Some(char) = chars { - self.char_word_separators.contains(&char) + self.char_word_separators.contains(char) } else { false } diff --git a/espanso-match/src/rolling/tree.rs b/espanso-match/src/rolling/tree.rs index b42bb0d..9b9c138 100644 --- a/espanso-match/src/rolling/tree.rs +++ b/espanso-match/src/rolling/tree.rs @@ -66,15 +66,13 @@ fn insert_items_recursively(id: Id, node: &mut MatcherTreeNode, items: & return; } + let item = items.get(0).unwrap(); if items.len() == 1 { - let item = items.get(0).unwrap(); match item { RollingItem::WordSeparator => { let mut new_matches = Vec::new(); - if let Some(node_ref) = node.word_separators.take() { - if let MatcherTreeRef::Matches(matches) = node_ref { - new_matches.extend(matches); - } + if let Some(MatcherTreeRef::Matches(matches)) = node.word_separators.take() { + new_matches.extend(matches); } new_matches.push(id); node.word_separators = Some(MatcherTreeRef::Matches(new_matches)) @@ -125,7 +123,6 @@ fn insert_items_recursively(id: Id, node: &mut MatcherTreeNode, items: & } } } else { - let item = items.get(0).unwrap(); match item { RollingItem::WordSeparator => match node.word_separators.as_mut() { Some(MatcherTreeRef::Node(next_node)) => { diff --git a/espanso-match/src/rolling/util.rs b/espanso-match/src/rolling/util.rs index bb87aba..d137c35 100644 --- a/espanso-match/src/rolling/util.rs +++ b/espanso-match/src/rolling/util.rs @@ -30,16 +30,18 @@ pub(crate) fn extract_string_from_events( let mut right_separator = None; for (i, (event, is_word_separator)) in events.iter().enumerate() { - if let Event::Key { key: _, chars } = event { - if let Some(chars) = chars { - string.push_str(chars); + if let Event::Key { + key: _, + chars: Some(chars), + } = event + { + string.push_str(chars); - if *is_word_separator { - if i == 0 { - left_separator = Some(chars.clone()); - } else if i == (events.len() - 1) { - right_separator = Some(chars.clone()); - } + if *is_word_separator { + if i == 0 { + left_separator = Some(chars.clone()); + } else if i == (events.len() - 1) { + right_separator = Some(chars.clone()); } } }