From fa2709d43bc614df881811a80ab3d54768495aae Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Fri, 13 Aug 2021 21:17:01 +0200 Subject: [PATCH] feat(config): implement search_shortcut field --- espanso-config/src/config/mod.rs | 3 +++ espanso-config/src/config/parse/mod.rs | 2 +- espanso-config/src/config/parse/yaml.rs | 6 ++++++ espanso-config/src/config/resolve.rs | 9 +++++++++ espanso-config/src/legacy/mod.rs | 4 ++++ 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/espanso-config/src/config/mod.rs b/espanso-config/src/config/mod.rs index 3510934..d934275 100644 --- a/espanso-config/src/config/mod.rs +++ b/espanso-config/src/config/mod.rs @@ -114,6 +114,9 @@ pub trait Config: Send + Sync { // Trigger used to show the Search UI fn search_trigger(&self) -> Option; + // Hotkey used to trigger the Search UI + fn search_shortcut(&self) -> Option; + fn is_match<'a>(&self, app: &AppProperties<'a>) -> bool; fn pretty_dump(&self) -> String { diff --git a/espanso-config/src/config/parse/mod.rs b/espanso-config/src/config/parse/mod.rs index 9e049fb..688259c 100644 --- a/espanso-config/src/config/parse/mod.rs +++ b/espanso-config/src/config/parse/mod.rs @@ -38,6 +38,7 @@ pub(crate) struct ParsedConfig { pub backspace_limit: Option, pub apply_patch: Option, pub search_trigger: Option, + pub search_shortcut: Option, pub pre_paste_delay: Option, pub restore_clipboard_delay: Option, @@ -46,7 +47,6 @@ pub(crate) struct ParsedConfig { pub key_delay: Option, pub keyboard_layout: Option>, - // Includes pub includes: Option>, pub excludes: Option>, diff --git a/espanso-config/src/config/parse/yaml.rs b/espanso-config/src/config/parse/yaml.rs index d45a7e3..ccb4328 100644 --- a/espanso-config/src/config/parse/yaml.rs +++ b/espanso-config/src/config/parse/yaml.rs @@ -85,6 +85,9 @@ pub(crate) struct YAMLConfig { #[serde(default)] pub search_trigger: Option, + #[serde(default)] + pub search_shortcut: Option, + // Include/Exclude #[serde(default)] pub includes: Option>, @@ -159,6 +162,7 @@ impl TryFrom for ParsedConfig { .collect() }), search_trigger: yaml_config.search_trigger, + search_shortcut: yaml_config.search_shortcut, pre_paste_delay: yaml_config.pre_paste_delay, restore_clipboard_delay: yaml_config.restore_clipboard_delay, @@ -211,6 +215,7 @@ mod tests { variant: test_variant options: test_options search_trigger: "search" + search_shortcut: "CTRL+SPACE" use_standard_includes: true includes: ["test1"] @@ -255,6 +260,7 @@ mod tests { apply_patch: Some(false), keyboard_layout: Some(keyboard_layout), search_trigger: Some("search".to_owned()), + search_shortcut: Some("CTRL+SPACE".to_owned()), pre_paste_delay: Some(300), diff --git a/espanso-config/src/config/resolve.rs b/espanso-config/src/config/resolve.rs index 5aa7080..685b5b4 100644 --- a/espanso-config/src/config/resolve.rs +++ b/espanso-config/src/config/resolve.rs @@ -282,6 +282,14 @@ impl Config for ResolvedConfig { None => Some("jkj".to_string()), } } + + fn search_shortcut(&self) -> Option { + match self.parsed.search_shortcut.as_deref() { + Some("OFF") | Some("off") => None, + Some(x) => Some(x.to_string()), + None => Some("ALT+SPACE".to_string()), + } + } } impl ResolvedConfig { @@ -356,6 +364,7 @@ impl ResolvedConfig { backspace_limit, keyboard_layout, search_trigger, + search_shortcut, includes, excludes, extra_includes, diff --git a/espanso-config/src/legacy/mod.rs b/espanso-config/src/legacy/mod.rs index 45588ab..0f935d0 100644 --- a/espanso-config/src/legacy/mod.rs +++ b/espanso-config/src/legacy/mod.rs @@ -362,6 +362,10 @@ impl Config for LegacyInteropConfig { fn search_trigger(&self) -> Option { None } + + fn search_shortcut(&self) -> Option { + None + } } struct LegacyMatchGroup {