From ddbfa068812beb5e3ebb1d9a822b5df92ace9156 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Thu, 10 Jun 2021 21:27:05 +0200 Subject: [PATCH] feat(config): add backspace_limit option --- espanso-config/src/config/mod.rs | 5 +++++ 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, 21 insertions(+) diff --git a/espanso-config/src/config/mod.rs b/espanso-config/src/config/mod.rs index e0c1edf..fe5a54d 100644 --- a/espanso-config/src/config/mod.rs +++ b/espanso-config/src/config/mod.rs @@ -95,6 +95,11 @@ pub trait Config: Send { // Examples of this are . or , fn word_separators(&self) -> Vec; + // Maximum number of backspace presses espanso keeps track of. + // For example, this is needed to correctly expand even if typos + // are typed. + fn backspace_limit(&self) -> usize; + fn is_match<'a>(&self, app: &AppProperties<'a>) -> bool; } diff --git a/espanso-config/src/config/parse/mod.rs b/espanso-config/src/config/parse/mod.rs index 31e9007..a1615e2 100644 --- a/espanso-config/src/config/parse/mod.rs +++ b/espanso-config/src/config/parse/mod.rs @@ -35,6 +35,7 @@ pub(crate) struct ParsedConfig { pub paste_shortcut: Option, pub disable_x11_fast_inject: Option, pub word_separators: Option>, + pub backspace_limit: 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 96c62d0..67af459 100644 --- a/espanso-config/src/config/parse/yaml.rs +++ b/espanso-config/src/config/parse/yaml.rs @@ -72,6 +72,9 @@ pub(crate) struct YAMLConfig { #[serde(default)] pub word_separators: Option>, + #[serde(default)] + pub backspace_limit: Option, + // Include/Exclude #[serde(default)] pub includes: Option>, @@ -131,6 +134,7 @@ impl TryFrom for ParsedConfig { inject_delay: yaml_config.inject_delay, key_delay: yaml_config.key_delay.or(yaml_config.backspace_delay), word_separators: yaml_config.word_separators, + backspace_limit: yaml_config.backspace_limit, pre_paste_delay: yaml_config.pre_paste_delay, restore_clipboard_delay: yaml_config.restore_clipboard_delay, @@ -174,6 +178,7 @@ mod tests { key_delay: 20 backspace_delay: 30 word_separators: ["'", "."] + backspace_limit: 10 use_standard_includes: true includes: ["test1"] @@ -205,6 +210,7 @@ mod tests { disable_x11_fast_inject: Some(true), inject_delay: Some(10), key_delay: Some(20), + backspace_limit: Some(10), pre_paste_delay: Some(300), diff --git a/espanso-config/src/config/resolve.rs b/espanso-config/src/config/resolve.rs index 4019b37..ab8a158 100644 --- a/espanso-config/src/config/resolve.rs +++ b/espanso-config/src/config/resolve.rs @@ -243,6 +243,10 @@ impl Config for ResolvedConfig { (22u8 as char).to_string(), ]) } + + fn backspace_limit(&self) -> usize { + self.parsed.backspace_limit.unwrap_or(5) + } } impl ResolvedConfig { @@ -312,6 +316,7 @@ impl ResolvedConfig { inject_delay, key_delay, word_separators, + backspace_limit, includes, excludes, extra_includes, diff --git a/espanso-config/src/legacy/mod.rs b/espanso-config/src/legacy/mod.rs index 1655a45..f8be156 100644 --- a/espanso-config/src/legacy/mod.rs +++ b/espanso-config/src/legacy/mod.rs @@ -331,6 +331,10 @@ impl Config for LegacyInteropConfig { fn word_separators(&self) -> Vec { self.config.word_separators.iter().map(|c| String::from(*c)).collect() } + + fn backspace_limit(&self) -> usize { + self.config.backspace_limit.try_into().unwrap() + } } struct LegacyMatchGroup {