From 2e60042b2bcd42d0461bc9202725972883cf0cb5 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Mon, 21 Oct 2019 23:52:03 +0200 Subject: [PATCH] Improve newline support on windows for Word matches --- src/engine.rs | 11 +++++++++-- src/matcher/scrolling.rs | 12 +++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/engine.rs b/src/engine.rs index 72ad643..4376c52 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -150,9 +150,16 @@ impl <'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, U: UIMa // If a trailing separator was counted in the match, add it back to the target string if let Some(trailing_separator) = trailing_separator { - target_string.push(trailing_separator); + if trailing_separator == '\r' { // If the trailing separator is a carriage return, + target_string.push('\n'); // convert it to new line + }else{ + target_string.push(trailing_separator); + } } + // Convert Windows style newlines into unix styles + target_string = target_string.replace("\r\n", "\n"); + match config.backend { BackendType::Inject => { // Send the expected string. On linux, newlines are managed automatically @@ -162,7 +169,7 @@ impl <'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, U: UIMa self.keyboard_manager.send_string(&target_string); }else{ // To handle newlines, substitute each "\n" char with an Enter key press. - let splits = target_string.lines(); + let splits = target_string.split('\n'); for (i, split) in splits.enumerate() { if i > 0 { diff --git a/src/matcher/scrolling.rs b/src/matcher/scrolling.rs index b45b09c..e3f7a69 100644 --- a/src/matcher/scrolling.rs +++ b/src/matcher/scrolling.rs @@ -91,9 +91,6 @@ impl <'a, R: MatchReceiver, M: ConfigManager<'a>> super::Matcher for ScrollingMa let is_current_word_separator = active_config.word_separators.contains( &c.chars().nth(0).unwrap_or_default() ); - if is_current_word_separator { - - } let mut was_previous_word_separator = self.was_previous_char_word_separator.borrow_mut(); @@ -104,6 +101,8 @@ impl <'a, R: MatchReceiver, M: ConfigManager<'a>> super::Matcher for ScrollingMa if !x.trigger.starts_with(c) { false }else{ + // If word option is true, a match can only be started if the previous + // char was a word separator if x.word { *was_previous_word_separator }else{ @@ -188,6 +187,8 @@ impl <'a, R: MatchReceiver, M: ConfigManager<'a>> super::Matcher for ScrollingMa current_set_queue.pop_front(); } + *was_previous_word_separator = is_current_word_separator; + if let Some(match_entry) = found_match { if let Some(last) = current_set_queue.back_mut() { last.clear(); @@ -196,6 +197,9 @@ impl <'a, R: MatchReceiver, M: ConfigManager<'a>> super::Matcher for ScrollingMa let trailing_separator = if !match_entry.waiting_for_separator { None }else{ + // Force espanso to consider the previous char a word separator after a match + *was_previous_word_separator = true; + let as_char = c.chars().nth(0); match as_char { Some(c) => { @@ -207,8 +211,6 @@ impl <'a, R: MatchReceiver, M: ConfigManager<'a>> super::Matcher for ScrollingMa self.receiver.on_match(match_entry._match, trailing_separator); } - - *was_previous_word_separator = is_current_word_separator; } fn handle_modifier(&self, m: KeyModifier) {