feat(engine): refactor match detected event to support configurable hint

This commit is contained in:
Federico Terzi 2021-08-24 19:54:02 +02:00
parent 96ce9090f8
commit 6726436674
5 changed files with 6 additions and 2 deletions

View File

@ -22,6 +22,7 @@ use std::collections::HashMap;
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
pub struct MatchesDetectedEvent { pub struct MatchesDetectedEvent {
pub matches: Vec<DetectedMatch>, pub matches: Vec<DetectedMatch>,
pub is_search: bool,
} }
#[derive(Debug, Clone, PartialEq, Default)] #[derive(Debug, Clone, PartialEq, Default)]

View File

@ -45,6 +45,7 @@ impl Middleware for HotKeyMiddleware {
id: m_event.hotkey_id, id: m_event.hotkey_id,
..Default::default() ..Default::default()
}], }],
is_search: false,
}), }),
); );
} }

View File

@ -27,7 +27,7 @@ pub trait MatchFilter {
} }
pub trait MatchSelector { pub trait MatchSelector {
fn select(&self, matches_ids: &[i32]) -> Option<i32>; fn select(&self, matches_ids: &[i32], is_search: bool) -> Option<i32>;
} }
pub struct MatchSelectMiddleware<'a> { pub struct MatchSelectMiddleware<'a> {
@ -76,7 +76,7 @@ impl<'a> Middleware for MatchSelectMiddleware<'a> {
} }
_ => { _ => {
// Multiple matches, we need to ask the user which one to use // Multiple matches, we need to ask the user which one to use
if let Some(selected_id) = self.match_selector.select(&valid_ids) { if let Some(selected_id) = self.match_selector.select(&valid_ids, m_event.is_search) {
let m = m_event.matches.into_iter().find(|m| m.id == selected_id); let m = m_event.matches.into_iter().find(|m| m.id == selected_id);
if let Some(m) = m { if let Some(m) = m {
Event::caused_by( Event::caused_by(

View File

@ -143,6 +143,7 @@ impl<'a, State> Middleware for MatcherMiddleware<'a, State> {
args: result.args, args: result.args,
}) })
.collect(), .collect(),
is_search: false,
}), }),
); );
} }

View File

@ -61,6 +61,7 @@ impl<'a> Middleware for SearchMiddleware<'a> {
args: HashMap::new(), args: HashMap::new(),
}) })
.collect(), .collect(),
is_search: true,
}), }),
); );
dispatch(detected_matches); dispatch(detected_matches);