feat(core): wire up configurable search bar hint

This commit is contained in:
Federico Terzi 2021-08-24 19:54:26 +02:00
parent 6726436674
commit 9b52a06a8b
3 changed files with 12 additions and 4 deletions

View File

@ -50,7 +50,7 @@ impl<'a> MatchSelectorAdapter<'a> {
}
impl<'a> MatchSelector for MatchSelectorAdapter<'a> {
fn select(&self, matches_ids: &[i32]) -> Option<i32> {
fn select(&self, matches_ids: &[i32], is_search: bool) -> Option<i32> {
let matches = self.match_provider.get_matches(&matches_ids);
let search_items: Vec<SearchItem> = matches
.into_iter()
@ -65,8 +65,14 @@ impl<'a> MatchSelector for MatchSelectorAdapter<'a> {
}
})
.collect();
let hint = if is_search {
Some("Search matches by content or trigger (or type > to see commands)")
} else {
None
};
match self.search_ui.show(&search_items) {
match self.search_ui.show(&search_items, hint) {
Ok(Some(selected_id)) => match selected_id.parse::<i32>() {
Ok(id) => Some(id),
Err(err) => {

View File

@ -24,7 +24,7 @@ use anyhow::Result;
pub mod modulo;
pub trait SearchUI {
fn show(&self, items: &[SearchItem]) -> Result<Option<String>>;
fn show(&self, items: &[SearchItem], hint: Option<&str>) -> Result<Option<String>>;
}
#[derive(Debug)]

View File

@ -38,9 +38,10 @@ impl<'a> ModuloSearchUI<'a> {
}
impl<'a> SearchUI for ModuloSearchUI<'a> {
fn show(&self, items: &[SearchItem]) -> anyhow::Result<Option<String>> {
fn show(&self, items: &[SearchItem], hint: Option<&str>) -> anyhow::Result<Option<String>> {
let modulo_config = ModuloSearchConfig {
title: "espanso",
hint,
items: convert_items(&items),
};
@ -67,6 +68,7 @@ impl<'a> SearchUI for ModuloSearchUI<'a> {
#[derive(Debug, Serialize)]
struct ModuloSearchConfig<'a> {
title: &'a str,
hint: Option<&'a str>,
items: Vec<ModuloSearchItemConfig<'a>>,
}