From 67264366747a893299fb0f966e4c6e60102b2ba3 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Tue, 24 Aug 2021 19:54:02 +0200 Subject: [PATCH] feat(engine): refactor match detected event to support configurable hint --- espanso-engine/src/event/internal.rs | 1 + espanso-engine/src/process/middleware/hotkey.rs | 1 + espanso-engine/src/process/middleware/match_select.rs | 4 ++-- espanso-engine/src/process/middleware/matcher.rs | 1 + espanso-engine/src/process/middleware/search.rs | 1 + 5 files changed, 6 insertions(+), 2 deletions(-) diff --git a/espanso-engine/src/event/internal.rs b/espanso-engine/src/event/internal.rs index 0ffb83d..51c73e2 100644 --- a/espanso-engine/src/event/internal.rs +++ b/espanso-engine/src/event/internal.rs @@ -22,6 +22,7 @@ use std::collections::HashMap; #[derive(Debug, Clone, PartialEq)] pub struct MatchesDetectedEvent { pub matches: Vec, + pub is_search: bool, } #[derive(Debug, Clone, PartialEq, Default)] diff --git a/espanso-engine/src/process/middleware/hotkey.rs b/espanso-engine/src/process/middleware/hotkey.rs index e606ff6..9f34fc2 100644 --- a/espanso-engine/src/process/middleware/hotkey.rs +++ b/espanso-engine/src/process/middleware/hotkey.rs @@ -45,6 +45,7 @@ impl Middleware for HotKeyMiddleware { id: m_event.hotkey_id, ..Default::default() }], + is_search: false, }), ); } diff --git a/espanso-engine/src/process/middleware/match_select.rs b/espanso-engine/src/process/middleware/match_select.rs index 46e9003..5fe0461 100644 --- a/espanso-engine/src/process/middleware/match_select.rs +++ b/espanso-engine/src/process/middleware/match_select.rs @@ -27,7 +27,7 @@ pub trait MatchFilter { } pub trait MatchSelector { - fn select(&self, matches_ids: &[i32]) -> Option; + fn select(&self, matches_ids: &[i32], is_search: bool) -> Option; } 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 - 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); if let Some(m) = m { Event::caused_by( diff --git a/espanso-engine/src/process/middleware/matcher.rs b/espanso-engine/src/process/middleware/matcher.rs index e3e6e14..7b3e666 100644 --- a/espanso-engine/src/process/middleware/matcher.rs +++ b/espanso-engine/src/process/middleware/matcher.rs @@ -143,6 +143,7 @@ impl<'a, State> Middleware for MatcherMiddleware<'a, State> { args: result.args, }) .collect(), + is_search: false, }), ); } diff --git a/espanso-engine/src/process/middleware/search.rs b/espanso-engine/src/process/middleware/search.rs index e7d27ea..7b2168b 100644 --- a/espanso-engine/src/process/middleware/search.rs +++ b/espanso-engine/src/process/middleware/search.rs @@ -61,6 +61,7 @@ impl<'a> Middleware for SearchMiddleware<'a> { args: HashMap::new(), }) .collect(), + is_search: true, }), ); dispatch(detected_matches);