diff --git a/espanso-config/src/matches/group/loader/yaml/mod.rs b/espanso-config/src/matches/group/loader/yaml/mod.rs index 1559fda..ebe1dea 100644 --- a/espanso-config/src/matches/group/loader/yaml/mod.rs +++ b/espanso-config/src/matches/group/loader/yaml/mod.rs @@ -300,6 +300,7 @@ pub fn try_convert_into_match( effect, label: yaml_match.label, id: next_id(), + search_terms: yaml_match.search_terms.unwrap_or_default(), }, warnings, )) diff --git a/espanso-config/src/matches/group/loader/yaml/parse.rs b/espanso-config/src/matches/group/loader/yaml/parse.rs index 50c1463..bcdfe18 100644 --- a/espanso-config/src/matches/group/loader/yaml/parse.rs +++ b/espanso-config/src/matches/group/loader/yaml/parse.rs @@ -114,6 +114,9 @@ pub struct YAMLMatch { #[serde(default)] pub html: Option, + + #[serde(default)] + pub search_terms: Option>, } #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] diff --git a/espanso-config/src/matches/mod.rs b/espanso-config/src/matches/mod.rs index 33fd8e4..474b40b 100644 --- a/espanso-config/src/matches/mod.rs +++ b/espanso-config/src/matches/mod.rs @@ -35,6 +35,7 @@ pub struct Match { // Metadata pub label: Option, + pub search_terms: Vec, } impl Default for Match { @@ -44,6 +45,7 @@ impl Default for Match { effect: MatchEffect::None, label: None, id: 0, + search_terms: vec![], } } } @@ -66,6 +68,15 @@ impl Match { pub fn cause_description(&self) -> Option<&str> { self.cause.description() } + + pub fn search_terms(&self) -> Vec<&str> { + self + .search_terms + .iter() + .map(|term| term.as_str()) + .chain(self.cause.search_terms()) + .collect() + } } // Causes @@ -100,6 +111,14 @@ impl MatchCause { // TODO: insert rendering for hotkey/shortcut // TODO: insert rendering for regex? I'm worried it might be too long } + + pub fn search_terms(&self) -> Vec<&str> { + if let MatchCause::Trigger(trigger_cause) = &self { + trigger_cause.triggers.iter().map(|s| s.as_str()).collect() + } else { + vec![] + } + } } #[derive(Debug, Clone, PartialEq, Eq, Hash)]