feat(config): add option to skip patching

This commit is contained in:
Federico Terzi 2021-07-31 17:17:24 +02:00
parent 0112603ff7
commit 4504977384
5 changed files with 18 additions and 0 deletions

View File

@ -103,6 +103,9 @@ pub trait Config: Send + Sync {
// are typed. // are typed.
fn backspace_limit(&self) -> usize; fn backspace_limit(&self) -> usize;
// If false, avoid applying the built-in patches to the current config.
fn apply_patch(&self) -> bool;
fn is_match<'a>(&self, app: &AppProperties<'a>) -> bool; fn is_match<'a>(&self, app: &AppProperties<'a>) -> bool;
} }

View File

@ -36,6 +36,7 @@ pub(crate) struct ParsedConfig {
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 backspace_limit: Option<usize>,
pub apply_patch: Option<bool>,
pub pre_paste_delay: Option<usize>, pub pre_paste_delay: Option<usize>,
pub restore_clipboard_delay: Option<usize>, pub restore_clipboard_delay: Option<usize>,

View File

@ -75,6 +75,9 @@ pub(crate) struct YAMLConfig {
#[serde(default)] #[serde(default)]
pub backspace_limit: Option<usize>, pub backspace_limit: Option<usize>,
#[serde(default)]
pub apply_patch: Option<bool>,
// Include/Exclude // Include/Exclude
#[serde(default)] #[serde(default)]
pub includes: Option<Vec<String>>, pub includes: Option<Vec<String>>,
@ -135,6 +138,7 @@ impl TryFrom<YAMLConfig> for ParsedConfig {
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, backspace_limit: yaml_config.backspace_limit,
apply_patch: yaml_config.apply_patch,
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,
@ -211,6 +215,7 @@ mod tests {
inject_delay: Some(10), inject_delay: Some(10),
key_delay: Some(20), key_delay: Some(20),
backspace_limit: Some(10), backspace_limit: Some(10),
apply_patch: Some(false),
pre_paste_delay: Some(300), pre_paste_delay: Some(300),

View File

@ -247,6 +247,10 @@ impl Config for ResolvedConfig {
fn backspace_limit(&self) -> usize { fn backspace_limit(&self) -> usize {
self.parsed.backspace_limit.unwrap_or(5) self.parsed.backspace_limit.unwrap_or(5)
} }
fn apply_patch(&self) -> bool {
self.parsed.apply_patch.unwrap_or(true)
}
} }
impl ResolvedConfig { impl ResolvedConfig {
@ -310,6 +314,7 @@ impl ResolvedConfig {
preserve_clipboard, preserve_clipboard,
restore_clipboard_delay, restore_clipboard_delay,
paste_shortcut, paste_shortcut,
apply_patch,
paste_shortcut_event_delay, paste_shortcut_event_delay,
disable_x11_fast_inject, disable_x11_fast_inject,
toggle_key, toggle_key,

View File

@ -339,6 +339,10 @@ impl Config for LegacyInteropConfig {
fn backspace_limit(&self) -> usize { fn backspace_limit(&self) -> usize {
self.config.backspace_limit.try_into().unwrap() self.config.backspace_limit.try_into().unwrap()
} }
fn apply_patch(&self) -> bool {
true
}
} }
struct LegacyMatchGroup { struct LegacyMatchGroup {