From 82096ad9fac8063291ad8c03e3b55eddfacc9353 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Sun, 18 Apr 2021 12:33:53 +0200 Subject: [PATCH] fix(core): improve continuous word matches detection --- espanso/src/engine/event/mod.rs | 1 + .../src/engine/process/middleware/action.rs | 12 ++++++--- .../src/engine/process/middleware/matcher.rs | 26 ++++++++----------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/espanso/src/engine/event/mod.rs b/espanso/src/engine/event/mod.rs index 4d9e698..f8df790 100644 --- a/espanso/src/engine/event/mod.rs +++ b/espanso/src/engine/event/mod.rs @@ -40,6 +40,7 @@ pub enum Event { RenderingRequested(render::RenderingRequestedEvent), Rendered(render::RenderedEvent), + MatchInjected, // Effects TriggerCompensation(effect::TriggerCompensationEvent), diff --git a/espanso/src/engine/process/middleware/action.rs b/espanso/src/engine/process/middleware/action.rs index 4c99871..23b5ae9 100644 --- a/espanso/src/engine/process/middleware/action.rs +++ b/espanso/src/engine/process/middleware/action.rs @@ -50,10 +50,14 @@ impl<'a> Middleware for ActionMiddleware<'a> { fn next(&self, event: Event, dispatch: &mut dyn FnMut(Event)) -> Event { match &event { - Event::Rendered(m_event) => Event::TextInject(TextInjectRequest { - text: m_event.body.clone(), - force_mode: self.match_info_provider.get_force_mode(m_event.match_id), - }), + Event::Rendered(m_event) => { + dispatch(Event::MatchInjected); + + Event::TextInject(TextInjectRequest { + text: m_event.body.clone(), + force_mode: self.match_info_provider.get_force_mode(m_event.match_id), + }) + } Event::CursorHintCompensation(m_event) => { Event::KeySequenceInject(KeySequenceInjectRequest { keys: (0..m_event.cursor_hint_back_count) diff --git a/espanso/src/engine/process/middleware/matcher.rs b/espanso/src/engine/process/middleware/matcher.rs index 827c6e7..aca712f 100644 --- a/espanso/src/engine/process/middleware/matcher.rs +++ b/espanso/src/engine/process/middleware/matcher.rs @@ -120,28 +120,24 @@ impl<'a, State> Middleware for MatcherMiddleware<'a, State> { } fn is_event_of_interest(event: &Event) -> bool { - if let Event::Keyboard(keyboard_event) = &event { - if keyboard_event.status == Status::Pressed { - return true; - } + match event { + Event::Keyboard(keyboard_event) if keyboard_event.status == Status::Pressed => true, + // TODO: handle mouse + Event::MatchInjected => true, + _ => false, } - - // TODO: handle mouse - - false } fn convert_to_matcher_event(event: &Event) -> Option { - if let Event::Keyboard(keyboard_event) = event { - return Some(MatcherEvent::Key { + match event { + Event::Keyboard(keyboard_event) => Some(MatcherEvent::Key { key: keyboard_event.key.clone(), chars: keyboard_event.value.clone(), - }); + }), + Event::MatchInjected => Some(MatcherEvent::VirtualSeparator), + // TODO: mouse event should act as separator + _ => None, } - - // TODO: mouse event should act as separator - - None } fn is_invalidating_key(key: &Key) -> bool {