feat(engine): refactor match detected event to support configurable hint
This commit is contained in:
parent
96ce9090f8
commit
6726436674
|
@ -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)]
|
||||||
|
|
|
@ -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,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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(
|
||||||
|
|
|
@ -143,6 +143,7 @@ impl<'a, State> Middleware for MatcherMiddleware<'a, State> {
|
||||||
args: result.args,
|
args: result.args,
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
|
is_search: false,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user