Add delay to mitigate clipboard restoration race condition. Fix #148

This commit is contained in:
Federico Terzi 2020-01-26 22:40:32 +01:00
parent 025d00ad26
commit a6282b1a9d
2 changed files with 9 additions and 0 deletions

View File

@ -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<Match> { 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
}

View File

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