diff --git a/src/config/mod.rs b/src/config/mod.rs index 154dccf..8eb2c2e 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -63,6 +63,7 @@ fn default_enable_passive() -> bool { false } fn default_enable_active() -> bool { true } fn default_action_noop_interval() -> u128 { 500 } fn default_backspace_limit() -> i32 { 3 } +fn default_restore_clipboard_delay() -> i32 { 300 } fn default_exclude_default_matches() -> bool {false} fn default_matches() -> Vec { Vec::new() } @@ -137,6 +138,9 @@ pub struct Configs { #[serde(default = "default_backspace_limit")] pub backspace_limit: i32, + #[serde(default = "default_restore_clipboard_delay")] + pub restore_clipboard_delay: i32, + #[serde(default)] pub backend: BackendType, @@ -185,6 +189,7 @@ impl Configs { validate_field!(result, self.passive_arg_escape, default_passive_arg_escape()); validate_field!(result, self.passive_key, default_passive_key()); validate_field!(result, self.action_noop_interval, default_action_noop_interval()); + validate_field!(result, self.restore_clipboard_delay, default_restore_clipboard_delay()); result } diff --git a/src/engine.rs b/src/engine.rs index a971a4f..ce3faca 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -239,6 +239,10 @@ impl <'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, U: UIMa // Restore previous clipboard content if let Some(previous_clipboard_content) = previous_clipboard_content { + // Sometimes an expansion gets overwritten before pasting by the previous content + // A delay is needed to mitigate the problem + std::thread::sleep(std::time::Duration::from_millis(config.restore_clipboard_delay as u64)); + self.clipboard_manager.set_clipboard(&previous_clipboard_content); } }