From 64dd7b90741df44d9cbc648d17aaebe3ecd1fe8b Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Wed, 12 Aug 2020 20:37:15 +0200 Subject: [PATCH] Fix undo backspace on macOS --- src/config/mod.rs | 6 ++++++ src/engine.rs | 7 +++++++ src/matcher/scrolling.rs | 7 ------- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index a11e212..a2adafe 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -152,6 +152,9 @@ fn default_global_vars() -> Vec { fn default_modulo_path() -> Option { None } +fn default_mac_post_inject_delay() -> u64 { + 100 +} #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Configs { @@ -235,6 +238,9 @@ pub struct Configs { #[serde(default = "default_secure_input_watcher_interval")] pub secure_input_watcher_interval: i32, + + #[serde(default = "default_mac_post_inject_delay")] + pub mac_post_inject_delay: u64, #[serde(default = "default_secure_input_notification")] pub secure_input_notification: bool, diff --git a/src/engine.rs b/src/engine.rs index eb8fb65..9c2680d 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -306,6 +306,13 @@ impl< .set_clipboard(&previous_clipboard_content); } + // On macOS, because the keyinjection is async, we need to wait a bit before + // giving back the control. Otherwise, the injected actions will be handled back + // by espanso itself. + if cfg!(target_os = "macos") { + std::thread::sleep(std::time::Duration::from_millis(config.mac_post_inject_delay)); + } + // Re-allow espanso to interpret actions self.is_injecting.store(false, Release); diff --git a/src/matcher/scrolling.rs b/src/matcher/scrolling.rs index c070c4a..38c6d58 100644 --- a/src/matcher/scrolling.rs +++ b/src/matcher/scrolling.rs @@ -106,13 +106,6 @@ impl<'a, R: MatchReceiver, M: ConfigManager<'a>> super::Matcher for ScrollingMat .word_separators .contains(&c.chars().nth(0).unwrap_or_default()); - // Workaround needed on macos to consider espanso replacement key presses as separators. - if cfg!(target_os = "macos") { - if c.len() > 1 { - is_current_word_separator = true; - } - } - let mut was_previous_char_a_match = self.was_previous_char_a_match.borrow_mut(); (*was_previous_char_a_match) = false;