feat(config): implement search_shortcut field

This commit is contained in:
Federico Terzi 2021-08-13 21:17:01 +02:00
parent 5c06699a80
commit fa2709d43b
5 changed files with 23 additions and 1 deletions

View File

@ -114,6 +114,9 @@ pub trait Config: Send + Sync {
// Trigger used to show the Search UI
fn search_trigger(&self) -> Option<String>;
// Hotkey used to trigger the Search UI
fn search_shortcut(&self) -> Option<String>;
fn is_match<'a>(&self, app: &AppProperties<'a>) -> bool;
fn pretty_dump(&self) -> String {

View File

@ -38,6 +38,7 @@ pub(crate) struct ParsedConfig {
pub backspace_limit: Option<usize>,
pub apply_patch: Option<bool>,
pub search_trigger: Option<String>,
pub search_shortcut: Option<String>,
pub pre_paste_delay: Option<usize>,
pub restore_clipboard_delay: Option<usize>,
@ -46,7 +47,6 @@ pub(crate) struct ParsedConfig {
pub key_delay: Option<usize>,
pub keyboard_layout: Option<BTreeMap<String, String>>,
// Includes
pub includes: Option<Vec<String>>,
pub excludes: Option<Vec<String>>,

View File

@ -85,6 +85,9 @@ pub(crate) struct YAMLConfig {
#[serde(default)]
pub search_trigger: Option<String>,
#[serde(default)]
pub search_shortcut: Option<String>,
// Include/Exclude
#[serde(default)]
pub includes: Option<Vec<String>>,
@ -159,6 +162,7 @@ impl TryFrom<YAMLConfig> for ParsedConfig {
.collect()
}),
search_trigger: yaml_config.search_trigger,
search_shortcut: yaml_config.search_shortcut,
pre_paste_delay: yaml_config.pre_paste_delay,
restore_clipboard_delay: yaml_config.restore_clipboard_delay,
@ -211,6 +215,7 @@ mod tests {
variant: test_variant
options: test_options
search_trigger: "search"
search_shortcut: "CTRL+SPACE"
use_standard_includes: true
includes: ["test1"]
@ -255,6 +260,7 @@ mod tests {
apply_patch: Some(false),
keyboard_layout: Some(keyboard_layout),
search_trigger: Some("search".to_owned()),
search_shortcut: Some("CTRL+SPACE".to_owned()),
pre_paste_delay: Some(300),

View File

@ -282,6 +282,14 @@ impl Config for ResolvedConfig {
None => Some("jkj".to_string()),
}
}
fn search_shortcut(&self) -> Option<String> {
match self.parsed.search_shortcut.as_deref() {
Some("OFF") | Some("off") => None,
Some(x) => Some(x.to_string()),
None => Some("ALT+SPACE".to_string()),
}
}
}
impl ResolvedConfig {
@ -356,6 +364,7 @@ impl ResolvedConfig {
backspace_limit,
keyboard_layout,
search_trigger,
search_shortcut,
includes,
excludes,
extra_includes,

View File

@ -362,6 +362,10 @@ impl Config for LegacyInteropConfig {
fn search_trigger(&self) -> Option<String> {
None
}
fn search_shortcut(&self) -> Option<String> {
None
}
}
struct LegacyMatchGroup {