Skip to content

Commit

Permalink
feat(core): wire up additional search terms and fix multiple triggers…
Browse files Browse the repository at this point in the history
… search. Fix #796 Fix #789
  • Loading branch information
federico-terzi committed Jan 4, 2022
1 parent b31617a commit f07d297
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
Expand Up @@ -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,
}

Expand Down Expand Up @@ -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,
}
})
Expand Down
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions espanso/src/cli/worker/match_cache.rs
Expand Up @@ -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,
},
})
Expand Down
1 change: 1 addition & 0 deletions espanso/src/gui/mod.rs
Expand Up @@ -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,
}

Expand Down
10 changes: 10 additions & 0 deletions espanso/src/gui/modulo/search.rs
Expand Up @@ -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,
}

Expand All @@ -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()
Expand Down

0 comments on commit f07d297

Please sign in to comment.