feat(config): add preserve clipboard config fields
This commit is contained in:
parent
28d8194b4a
commit
dadc71728c
|
@ -54,8 +54,20 @@ pub trait Config: Send {
|
||||||
// Defines the key that disables/enables espanso when double pressed
|
// Defines the key that disables/enables espanso when double pressed
|
||||||
fn toggle_key(&self) -> Option<ToggleKey>;
|
fn toggle_key(&self) -> Option<ToggleKey>;
|
||||||
|
|
||||||
|
// If true, instructs the daemon process to restart the worker (and refresh
|
||||||
|
// the configuration) after a configuration file change is detected on disk.
|
||||||
fn auto_restart(&self) -> bool;
|
fn auto_restart(&self) -> bool;
|
||||||
|
|
||||||
|
// If true, espanso will attempt to preserve the previous clipboard content
|
||||||
|
// after an expansion has taken place (when using the Clipboard backend).
|
||||||
|
fn preserve_clipboard(&self) -> bool;
|
||||||
|
|
||||||
|
// The number of milliseconds to wait before restoring the previous clipboard
|
||||||
|
// content after an expansion. This is needed as without this delay, sometimes
|
||||||
|
// the target application detects the previous clipboard content instead of
|
||||||
|
// the expansion content.
|
||||||
|
fn restore_clipboard_delay(&self) -> usize;
|
||||||
|
|
||||||
fn is_match<'a>(&self, app: &AppProperties<'a>) -> bool;
|
fn is_match<'a>(&self, app: &AppProperties<'a>) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,8 +30,10 @@ pub(crate) struct ParsedConfig {
|
||||||
pub backend: Option<String>,
|
pub backend: Option<String>,
|
||||||
pub clipboard_threshold: Option<usize>,
|
pub clipboard_threshold: Option<usize>,
|
||||||
pub auto_restart: Option<bool>,
|
pub auto_restart: Option<bool>,
|
||||||
|
pub preserve_clipboard: Option<bool>,
|
||||||
|
|
||||||
pub pre_paste_delay: Option<usize>,
|
pub pre_paste_delay: Option<usize>,
|
||||||
|
pub restore_clipboard_delay: Option<usize>,
|
||||||
|
|
||||||
pub toggle_key: Option<String>,
|
pub toggle_key: Option<String>,
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,12 @@ pub(crate) struct YAMLConfig {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub auto_restart: Option<bool>,
|
pub auto_restart: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(default)]
|
||||||
|
pub preserve_clipboard: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(default)]
|
||||||
|
pub restore_clipboard_delay: Option<usize>,
|
||||||
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub includes: Option<Vec<String>>,
|
pub includes: Option<Vec<String>>,
|
||||||
|
|
||||||
|
@ -96,8 +102,10 @@ impl TryFrom<YAMLConfig> for ParsedConfig {
|
||||||
backend: yaml_config.backend,
|
backend: yaml_config.backend,
|
||||||
clipboard_threshold: yaml_config.clipboard_threshold,
|
clipboard_threshold: yaml_config.clipboard_threshold,
|
||||||
auto_restart: yaml_config.auto_restart,
|
auto_restart: yaml_config.auto_restart,
|
||||||
|
preserve_clipboard: yaml_config.preserve_clipboard,
|
||||||
|
|
||||||
pre_paste_delay: yaml_config.pre_paste_delay,
|
pre_paste_delay: yaml_config.pre_paste_delay,
|
||||||
|
restore_clipboard_delay: yaml_config.restore_clipboard_delay,
|
||||||
|
|
||||||
toggle_key: yaml_config.toggle_key,
|
toggle_key: yaml_config.toggle_key,
|
||||||
|
|
||||||
|
@ -130,6 +138,8 @@ mod tests {
|
||||||
pre_paste_delay: 300
|
pre_paste_delay: 300
|
||||||
toggle_key: CTRL
|
toggle_key: CTRL
|
||||||
auto_restart: false
|
auto_restart: false
|
||||||
|
preserve_clipboard: false
|
||||||
|
restore_clipboard_delay: 400
|
||||||
|
|
||||||
use_standard_includes: true
|
use_standard_includes: true
|
||||||
includes: ["test1"]
|
includes: ["test1"]
|
||||||
|
@ -154,6 +164,8 @@ mod tests {
|
||||||
backend: Some("clipboard".to_string()),
|
backend: Some("clipboard".to_string()),
|
||||||
clipboard_threshold: Some(200),
|
clipboard_threshold: Some(200),
|
||||||
auto_restart: Some(false),
|
auto_restart: Some(false),
|
||||||
|
preserve_clipboard: Some(false),
|
||||||
|
restore_clipboard_delay: Some(400),
|
||||||
|
|
||||||
pre_paste_delay: Some(300),
|
pre_paste_delay: Some(300),
|
||||||
|
|
||||||
|
|
|
@ -177,7 +177,7 @@ impl Config for ResolvedConfig {
|
||||||
Some("right_ctrl") => Some(ToggleKey::RightCtrl),
|
Some("right_ctrl") => Some(ToggleKey::RightCtrl),
|
||||||
Some("right_alt") => Some(ToggleKey::RightAlt),
|
Some("right_alt") => Some(ToggleKey::RightAlt),
|
||||||
Some("right_shift") => Some(ToggleKey::RightShift),
|
Some("right_shift") => Some(ToggleKey::RightShift),
|
||||||
Some("right_meta") | Some("right_cmd")=> Some(ToggleKey::RightMeta),
|
Some("right_meta") | Some("right_cmd") => Some(ToggleKey::RightMeta),
|
||||||
Some("left_ctrl") => Some(ToggleKey::LeftCtrl),
|
Some("left_ctrl") => Some(ToggleKey::LeftCtrl),
|
||||||
Some("left_alt") => Some(ToggleKey::LeftAlt),
|
Some("left_alt") => Some(ToggleKey::LeftAlt),
|
||||||
Some("left_shift") => Some(ToggleKey::LeftShift),
|
Some("left_shift") => Some(ToggleKey::LeftShift),
|
||||||
|
@ -185,11 +185,22 @@ impl Config for ResolvedConfig {
|
||||||
Some("off") => None,
|
Some("off") => None,
|
||||||
None => Some(ToggleKey::Alt),
|
None => Some(ToggleKey::Alt),
|
||||||
err => {
|
err => {
|
||||||
error!("invalid toggle_key specified {:?}, falling back to ALT", err);
|
error!(
|
||||||
|
"invalid toggle_key specified {:?}, falling back to ALT",
|
||||||
|
err
|
||||||
|
);
|
||||||
Some(ToggleKey::Alt)
|
Some(ToggleKey::Alt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn preserve_clipboard(&self) -> bool {
|
||||||
|
self.parsed.preserve_clipboard.unwrap_or(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn restore_clipboard_delay(&self) -> usize {
|
||||||
|
self.parsed.restore_clipboard_delay.unwrap_or(300)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ResolvedConfig {
|
impl ResolvedConfig {
|
||||||
|
@ -250,6 +261,8 @@ impl ResolvedConfig {
|
||||||
clipboard_threshold,
|
clipboard_threshold,
|
||||||
auto_restart,
|
auto_restart,
|
||||||
pre_paste_delay,
|
pre_paste_delay,
|
||||||
|
preserve_clipboard,
|
||||||
|
restore_clipboard_delay,
|
||||||
toggle_key,
|
toggle_key,
|
||||||
includes,
|
includes,
|
||||||
excludes,
|
excludes,
|
||||||
|
|
|
@ -281,9 +281,17 @@ impl Config for LegacyInteropConfig {
|
||||||
model::KeyModifier::RIGHT_META => Some(crate::config::ToggleKey::RightMeta),
|
model::KeyModifier::RIGHT_META => Some(crate::config::ToggleKey::RightMeta),
|
||||||
model::KeyModifier::LEFT_SHIFT => Some(crate::config::ToggleKey::LeftShift),
|
model::KeyModifier::LEFT_SHIFT => Some(crate::config::ToggleKey::LeftShift),
|
||||||
model::KeyModifier::RIGHT_SHIFT => Some(crate::config::ToggleKey::RightShift),
|
model::KeyModifier::RIGHT_SHIFT => Some(crate::config::ToggleKey::RightShift),
|
||||||
model::KeyModifier::CAPS_LOCK => None
|
model::KeyModifier::CAPS_LOCK => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn preserve_clipboard(&self) -> bool {
|
||||||
|
self.config.preserve_clipboard
|
||||||
|
}
|
||||||
|
|
||||||
|
fn restore_clipboard_delay(&self) -> usize {
|
||||||
|
self.config.restore_clipboard_delay.try_into().unwrap()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LegacyMatchGroup {
|
struct LegacyMatchGroup {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user