Add delay and remove hardcoded amount
This commit is contained in:
parent
e784b94792
commit
a4e30fdc64
|
@ -95,6 +95,9 @@ fn default_passive_arg_delimiter() -> char {
|
||||||
fn default_passive_arg_escape() -> char {
|
fn default_passive_arg_escape() -> char {
|
||||||
'\\'
|
'\\'
|
||||||
}
|
}
|
||||||
|
fn default_passive_delay() -> u64 {
|
||||||
|
100
|
||||||
|
}
|
||||||
fn default_passive_key() -> KeyModifier {
|
fn default_passive_key() -> KeyModifier {
|
||||||
KeyModifier::OFF
|
KeyModifier::OFF
|
||||||
}
|
}
|
||||||
|
@ -206,6 +209,9 @@ pub struct Configs {
|
||||||
#[serde(default = "default_passive_key")]
|
#[serde(default = "default_passive_key")]
|
||||||
pub passive_key: KeyModifier,
|
pub passive_key: KeyModifier,
|
||||||
|
|
||||||
|
#[serde(default = "default_passive_delay")]
|
||||||
|
pub passive_delay: u64,
|
||||||
|
|
||||||
#[serde(default = "default_enable_passive")]
|
#[serde(default = "default_enable_passive")]
|
||||||
pub enable_passive: bool,
|
pub enable_passive: bool,
|
||||||
|
|
||||||
|
|
|
@ -349,23 +349,23 @@ impl<
|
||||||
let previous_clipboard = self.clipboard_manager.get_clipboard().unwrap_or_default();
|
let previous_clipboard = self.clipboard_manager.get_clipboard().unwrap_or_default();
|
||||||
|
|
||||||
// Sleep for a while, giving time to effectively copy the text
|
// Sleep for a while, giving time to effectively copy the text
|
||||||
std::thread::sleep(std::time::Duration::from_millis(100)); // TODO: avoid hardcoding
|
std::thread::sleep(std::time::Duration::from_millis(config.passive_delay));
|
||||||
|
|
||||||
// Clear the clipboard, for new-content detection later
|
// Clear the clipboard, for new-content detection later
|
||||||
self.clipboard_manager.set_clipboard("");
|
self.clipboard_manager.set_clipboard("");
|
||||||
|
|
||||||
|
// Sleep for a while, giving time to effectively copy the text
|
||||||
|
std::thread::sleep(std::time::Duration::from_millis(config.passive_delay));
|
||||||
|
|
||||||
// Trigger a copy shortcut to transfer the content of the selection to the clipboard
|
// Trigger a copy shortcut to transfer the content of the selection to the clipboard
|
||||||
self.keyboard_manager.trigger_copy(&config);
|
self.keyboard_manager.trigger_copy(&config);
|
||||||
|
|
||||||
// Sleep for a while, giving time to effectively copy the text
|
// Sleep for a while, giving time to effectively copy the text
|
||||||
std::thread::sleep(std::time::Duration::from_millis(100)); // TODO: avoid hardcoding
|
std::thread::sleep(std::time::Duration::from_millis(config.passive_delay));
|
||||||
|
|
||||||
// Then get the text from the clipboard and render the match output
|
// Then get the text from the clipboard and render the match output
|
||||||
let clipboard = self.clipboard_manager.get_clipboard();
|
let clipboard = self.clipboard_manager.get_clipboard();
|
||||||
|
|
||||||
// Restore original clipboard now, in case expansion doesn't happen at all
|
|
||||||
self.clipboard_manager.set_clipboard(&previous_clipboard);
|
|
||||||
|
|
||||||
if let Some(clipboard) = clipboard {
|
if let Some(clipboard) = clipboard {
|
||||||
// Don't expand empty clipboards, as usually they are the result of an empty passive selection
|
// Don't expand empty clipboards, as usually they are the result of an empty passive selection
|
||||||
if clipboard.trim().is_empty() {
|
if clipboard.trim().is_empty() {
|
||||||
|
@ -380,16 +380,19 @@ impl<
|
||||||
// Paste back the result in the field
|
// Paste back the result in the field
|
||||||
self.clipboard_manager.set_clipboard(&payload);
|
self.clipboard_manager.set_clipboard(&payload);
|
||||||
|
|
||||||
std::thread::sleep(std::time::Duration::from_millis(100)); // TODO: avoid hardcoding
|
std::thread::sleep(std::time::Duration::from_millis(config.passive_delay));
|
||||||
self.keyboard_manager.trigger_paste(&config);
|
self.keyboard_manager.trigger_paste(&config);
|
||||||
|
|
||||||
self.clipboard_manager.set_clipboard(&previous_clipboard);
|
|
||||||
}
|
}
|
||||||
_ => warn!("Cannot expand passive match"),
|
_ => warn!("Cannot expand passive match"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::thread::sleep(std::time::Duration::from_millis(config.passive_delay));
|
||||||
|
|
||||||
|
// Restore original clipboard
|
||||||
|
self.clipboard_manager.set_clipboard(&previous_clipboard);
|
||||||
|
|
||||||
// Re-allow espanso to interpret actions
|
// Re-allow espanso to interpret actions
|
||||||
self.is_injecting.store(false, Release);
|
self.is_injecting.store(false, Release);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user