feat(core): wire up additional search terms and fix multiple triggers search. Fix #796 Fix #789

This commit is contained in:
Federico Terzi 2022-01-04 21:19:09 +01:00
parent b31617a2f3
commit f07d297ce0
5 changed files with 20 additions and 0 deletions

View File

@ -32,6 +32,7 @@ pub struct MatchSummary<'a> {
pub id: i32,
pub label: &'a str,
pub tag: Option<&'a str>,
pub additional_search_terms: Vec<&'a str>,
pub is_builtin: bool,
}
@ -65,6 +66,11 @@ impl<'a> MatchSelector for MatchSelectorAdapter<'a> {
id: m.id.to_string(),
label: clipped_label,
tag: m.tag.map(String::from),
additional_search_terms: m
.additional_search_terms
.into_iter()
.map(String::from)
.collect(),
is_builtin: m.is_builtin,
}
})

View File

@ -49,6 +49,7 @@ fn convert_items(choices: &[espanso_render::extension::choice::Choice]) -> Vec<S
id: choice.id.to_string(),
label: choice.label.to_string(),
tag: None,
additional_search_terms: vec![],
is_builtin: false,
})
.collect()

View File

@ -129,12 +129,14 @@ impl<'a> super::engine::process::middleware::match_select::MatchProvider<'a>
id: m.id,
label: m.description(),
tag: m.cause_description(),
additional_search_terms: m.search_terms(),
is_builtin: false,
},
MatchVariant::Builtin(m) => MatchSummary {
id: m.id,
label: m.label,
tag: m.triggers.first().map(String::as_ref),
additional_search_terms: vec![],
is_builtin: true,
},
})

View File

@ -32,6 +32,7 @@ pub struct SearchItem {
pub id: String,
pub label: String,
pub tag: Option<String>,
pub additional_search_terms: Vec<String>,
pub is_builtin: bool,
}

View File

@ -73,6 +73,7 @@ struct ModuloSearchItemConfig<'a> {
id: &'a str,
label: &'a str,
trigger: Option<&'a str>,
search_terms: Vec<&'a str>,
is_builtin: bool,
}
@ -84,6 +85,15 @@ fn convert_items(items: &[SearchItem]) -> Vec<ModuloSearchItemConfig> {
id: &item.id,
label: &item.label,
trigger: item.tag.as_deref(),
search_terms: if item.additional_search_terms.is_empty() {
vec![]
} else {
item
.additional_search_terms
.iter()
.map(|term| term.as_str())
.collect()
},
is_builtin: item.is_builtin,
})
.collect()