feat(config): add backspace_limit option

This commit is contained in:
Federico Terzi 2021-06-10 21:27:05 +02:00
parent 581bd199bb
commit ddbfa06881
5 changed files with 21 additions and 0 deletions

View File

@ -95,6 +95,11 @@ pub trait Config: Send {
// Examples of this are . or ,
fn word_separators(&self) -> Vec<String>;
// 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;
}

View File

@ -35,6 +35,7 @@ pub(crate) struct ParsedConfig {
pub paste_shortcut: Option<String>,
pub disable_x11_fast_inject: Option<bool>,
pub word_separators: Option<Vec<String>>,
pub backspace_limit: Option<usize>,
pub pre_paste_delay: Option<usize>,
pub restore_clipboard_delay: Option<usize>,

View File

@ -72,6 +72,9 @@ pub(crate) struct YAMLConfig {
#[serde(default)]
pub word_separators: Option<Vec<String>>,
#[serde(default)]
pub backspace_limit: Option<usize>,
// Include/Exclude
#[serde(default)]
pub includes: Option<Vec<String>>,
@ -131,6 +134,7 @@ impl TryFrom<YAMLConfig> 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),

View File

@ -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,

View File

@ -331,6 +331,10 @@ impl Config for LegacyInteropConfig {
fn word_separators(&self) -> Vec<String> {
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 {