feat(config): add backspace_limit option
This commit is contained in:
parent
581bd199bb
commit
ddbfa06881
|
@ -95,6 +95,11 @@ pub trait Config: Send {
|
||||||
// Examples of this are . or ,
|
// Examples of this are . or ,
|
||||||
fn word_separators(&self) -> Vec<String>;
|
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;
|
fn is_match<'a>(&self, app: &AppProperties<'a>) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ pub(crate) struct ParsedConfig {
|
||||||
pub paste_shortcut: Option<String>,
|
pub paste_shortcut: Option<String>,
|
||||||
pub disable_x11_fast_inject: Option<bool>,
|
pub disable_x11_fast_inject: Option<bool>,
|
||||||
pub word_separators: Option<Vec<String>>,
|
pub word_separators: Option<Vec<String>>,
|
||||||
|
pub backspace_limit: Option<usize>,
|
||||||
|
|
||||||
pub pre_paste_delay: Option<usize>,
|
pub pre_paste_delay: Option<usize>,
|
||||||
pub restore_clipboard_delay: Option<usize>,
|
pub restore_clipboard_delay: Option<usize>,
|
||||||
|
|
|
@ -72,6 +72,9 @@ pub(crate) struct YAMLConfig {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub word_separators: Option<Vec<String>>,
|
pub word_separators: Option<Vec<String>>,
|
||||||
|
|
||||||
|
#[serde(default)]
|
||||||
|
pub backspace_limit: Option<usize>,
|
||||||
|
|
||||||
// Include/Exclude
|
// Include/Exclude
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub includes: Option<Vec<String>>,
|
pub includes: Option<Vec<String>>,
|
||||||
|
@ -131,6 +134,7 @@ impl TryFrom<YAMLConfig> for ParsedConfig {
|
||||||
inject_delay: yaml_config.inject_delay,
|
inject_delay: yaml_config.inject_delay,
|
||||||
key_delay: yaml_config.key_delay.or(yaml_config.backspace_delay),
|
key_delay: yaml_config.key_delay.or(yaml_config.backspace_delay),
|
||||||
word_separators: yaml_config.word_separators,
|
word_separators: yaml_config.word_separators,
|
||||||
|
backspace_limit: yaml_config.backspace_limit,
|
||||||
|
|
||||||
pre_paste_delay: yaml_config.pre_paste_delay,
|
pre_paste_delay: yaml_config.pre_paste_delay,
|
||||||
restore_clipboard_delay: yaml_config.restore_clipboard_delay,
|
restore_clipboard_delay: yaml_config.restore_clipboard_delay,
|
||||||
|
@ -174,6 +178,7 @@ mod tests {
|
||||||
key_delay: 20
|
key_delay: 20
|
||||||
backspace_delay: 30
|
backspace_delay: 30
|
||||||
word_separators: ["'", "."]
|
word_separators: ["'", "."]
|
||||||
|
backspace_limit: 10
|
||||||
|
|
||||||
use_standard_includes: true
|
use_standard_includes: true
|
||||||
includes: ["test1"]
|
includes: ["test1"]
|
||||||
|
@ -205,6 +210,7 @@ mod tests {
|
||||||
disable_x11_fast_inject: Some(true),
|
disable_x11_fast_inject: Some(true),
|
||||||
inject_delay: Some(10),
|
inject_delay: Some(10),
|
||||||
key_delay: Some(20),
|
key_delay: Some(20),
|
||||||
|
backspace_limit: Some(10),
|
||||||
|
|
||||||
pre_paste_delay: Some(300),
|
pre_paste_delay: Some(300),
|
||||||
|
|
||||||
|
|
|
@ -243,6 +243,10 @@ impl Config for ResolvedConfig {
|
||||||
(22u8 as char).to_string(),
|
(22u8 as char).to_string(),
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn backspace_limit(&self) -> usize {
|
||||||
|
self.parsed.backspace_limit.unwrap_or(5)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ResolvedConfig {
|
impl ResolvedConfig {
|
||||||
|
@ -312,6 +316,7 @@ impl ResolvedConfig {
|
||||||
inject_delay,
|
inject_delay,
|
||||||
key_delay,
|
key_delay,
|
||||||
word_separators,
|
word_separators,
|
||||||
|
backspace_limit,
|
||||||
includes,
|
includes,
|
||||||
excludes,
|
excludes,
|
||||||
extra_includes,
|
extra_includes,
|
||||||
|
|
|
@ -331,6 +331,10 @@ impl Config for LegacyInteropConfig {
|
||||||
fn word_separators(&self) -> Vec<String> {
|
fn word_separators(&self) -> Vec<String> {
|
||||||
self.config.word_separators.iter().map(|c| String::from(*c)).collect()
|
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 {
|
struct LegacyMatchGroup {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user