parent
90be91d1e9
commit
b31617a2f3
|
@ -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,
|
||||
))
|
||||
|
|
|
@ -114,6 +114,9 @@ pub struct YAMLMatch {
|
|||
|
||||
#[serde(default)]
|
||||
pub html: Option<String>,
|
||||
|
||||
#[serde(default)]
|
||||
pub search_terms: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
|
||||
|
|
|
@ -35,6 +35,7 @@ pub struct Match {
|
|||
|
||||
// Metadata
|
||||
pub label: Option<String>,
|
||||
pub search_terms: Vec<String>,
|
||||
}
|
||||
|
||||
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)]
|
||||
|
|
Loading…
Reference in New Issue
Block a user