From eab305d45fb39a292aa5523e6ae67ac1de863231 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Sun, 15 Aug 2021 11:01:36 +0200 Subject: [PATCH] feat(config): add undo_backspace option --- espanso-config/src/config/mod.rs | 4 ++++ espanso-config/src/config/parse/mod.rs | 1 + espanso-config/src/config/parse/yaml.rs | 6 ++++++ espanso-config/src/config/resolve.rs | 5 +++++ espanso-config/src/legacy/mod.rs | 4 ++++ 5 files changed, 20 insertions(+) diff --git a/espanso-config/src/config/mod.rs b/espanso-config/src/config/mod.rs index d934275..e544f95 100644 --- a/espanso-config/src/config/mod.rs +++ b/espanso-config/src/config/mod.rs @@ -117,6 +117,10 @@ pub trait Config: Send + Sync { // Hotkey used to trigger the Search UI fn search_shortcut(&self) -> Option; + // When enabled, espanso automatically "reverts" an expansion if the user + // presses the Backspace key afterwards. + fn undo_backspace(&self) -> bool; + 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 688259c..9558b1d 100644 --- a/espanso-config/src/config/parse/mod.rs +++ b/espanso-config/src/config/parse/mod.rs @@ -39,6 +39,7 @@ pub(crate) struct ParsedConfig { pub apply_patch: Option, pub search_trigger: Option, pub search_shortcut: Option, + pub undo_backspace: Option, pub pre_paste_delay: Option, pub restore_clipboard_delay: Option, diff --git a/espanso-config/src/config/parse/yaml.rs b/espanso-config/src/config/parse/yaml.rs index ccb4328..6f6e34d 100644 --- a/espanso-config/src/config/parse/yaml.rs +++ b/espanso-config/src/config/parse/yaml.rs @@ -88,6 +88,9 @@ pub(crate) struct YAMLConfig { #[serde(default)] pub search_shortcut: Option, + #[serde(default)] + pub undo_backspace: Option, + // Include/Exclude #[serde(default)] pub includes: Option>, @@ -163,6 +166,7 @@ impl TryFrom for ParsedConfig { }), search_trigger: yaml_config.search_trigger, search_shortcut: yaml_config.search_shortcut, + undo_backspace: yaml_config.undo_backspace, pre_paste_delay: yaml_config.pre_paste_delay, restore_clipboard_delay: yaml_config.restore_clipboard_delay, @@ -216,6 +220,7 @@ mod tests { options: test_options search_trigger: "search" search_shortcut: "CTRL+SPACE" + undo_backspace: false use_standard_includes: true includes: ["test1"] @@ -261,6 +266,7 @@ mod tests { keyboard_layout: Some(keyboard_layout), search_trigger: Some("search".to_owned()), search_shortcut: Some("CTRL+SPACE".to_owned()), + undo_backspace: Some(false), pre_paste_delay: Some(300), diff --git a/espanso-config/src/config/resolve.rs b/espanso-config/src/config/resolve.rs index 685b5b4..a18fb0b 100644 --- a/espanso-config/src/config/resolve.rs +++ b/espanso-config/src/config/resolve.rs @@ -290,6 +290,10 @@ impl Config for ResolvedConfig { None => Some("ALT+SPACE".to_string()), } } + + fn undo_backspace(&self) -> bool { + self.parsed.undo_backspace.unwrap_or(true) + } } impl ResolvedConfig { @@ -365,6 +369,7 @@ impl ResolvedConfig { keyboard_layout, search_trigger, search_shortcut, + undo_backspace, includes, excludes, extra_includes, diff --git a/espanso-config/src/legacy/mod.rs b/espanso-config/src/legacy/mod.rs index 0f935d0..02f920a 100644 --- a/espanso-config/src/legacy/mod.rs +++ b/espanso-config/src/legacy/mod.rs @@ -366,6 +366,10 @@ impl Config for LegacyInteropConfig { fn search_shortcut(&self) -> Option { None } + + fn undo_backspace(&self) -> bool { + self.config.undo_backspace + } } struct LegacyMatchGroup {