diff --git a/espanso/src/engine/process/default.rs b/espanso/src/engine/process/default.rs
index e38132f..7430357 100644
--- a/espanso/src/engine/process/default.rs
+++ b/espanso/src/engine/process/default.rs
@@ -64,11 +64,11 @@ impl<'a> DefaultProcessor<'a> {
};
for middleware in self.middleware.iter() {
- trace!("middleware received event: {:?}", current_event);
+ trace!("middleware '{}' received event: {:?}", middleware.name(), current_event);
current_event = middleware.next(current_event, &mut dispatch);
- trace!("middleware produced event: {:?}", current_event);
+ trace!("middleware '{}' produced event: {:?}", middleware.name(), current_event);
}
while let Some(event) = current_queue.pop_back() {
diff --git a/espanso/src/engine/process/middleware/action.rs b/espanso/src/engine/process/middleware/action.rs
index a81c030..bb2f2d1 100644
--- a/espanso/src/engine/process/middleware/action.rs
+++ b/espanso/src/engine/process/middleware/action.rs
@@ -17,10 +17,8 @@
* along with espanso. If not, see .
*/
-use log::{debug, error};
-
use super::super::Middleware;
-use crate::engine::{event::{Event, keyboard::{Key, KeySequenceInjectRequest}, matches::MatchSelectedEvent, text::{TextInjectMode, TextInjectRequest}}, process::{MatchFilter, MatchSelector, Multiplexer}};
+use crate::engine::{event::{Event, keyboard::{Key, KeySequenceInjectRequest}, text::{TextInjectMode, TextInjectRequest}}, process::{MatchFilter, MatchSelector, Multiplexer}};
pub struct ActionMiddleware {
}
@@ -32,19 +30,26 @@ impl ActionMiddleware {
}
impl Middleware for ActionMiddleware {
+ fn name(&self) -> &'static str {
+ "action"
+ }
+
fn next(&self, event: Event, dispatch: &mut dyn FnMut(Event)) -> Event {
if let Event::Rendered(m_event) = &event {
- let delete_count = m_event.trigger.len();
- let delete_sequence: Vec<_> = (0..delete_count).map(|_| Key::Backspace).collect();
-
dispatch(Event::TextInject(TextInjectRequest {
text: m_event.body.clone(),
force_mode: Some(TextInjectMode::Keys), // TODO: determine this one dynamically
}));
+ if let Some(cursor_hint_back_count) = m_event.cursor_hint_back_count {
+ dispatch(Event::KeySequenceInject(KeySequenceInjectRequest {
+ keys: (0..cursor_hint_back_count).map(|_| Key::ArrowLeft).collect(),
+ }))
+ }
+
// This is executed before the dispatched event
return Event::KeySequenceInject(KeySequenceInjectRequest {
- keys: delete_sequence
+ keys: (0..m_event.trigger.chars().count()).map(|_| Key::Backspace).collect()
})
}
diff --git a/espanso/src/engine/process/middleware/match_select.rs b/espanso/src/engine/process/middleware/match_select.rs
index 6edb5b6..82c46a8 100644
--- a/espanso/src/engine/process/middleware/match_select.rs
+++ b/espanso/src/engine/process/middleware/match_select.rs
@@ -43,6 +43,10 @@ impl<'a> MatchSelectMiddleware<'a> {
}
impl<'a> Middleware for MatchSelectMiddleware<'a> {
+ fn name(&self) -> &'static str {
+ "match_select"
+ }
+
fn next(&self, event: Event, _: &mut dyn FnMut(Event)) -> Event {
if let Event::MatchesDetected(m_event) = event {
let matches_ids: Vec = m_event.matches.iter().map(|m| m.id).collect();
diff --git a/espanso/src/engine/process/middleware/matcher.rs b/espanso/src/engine/process/middleware/matcher.rs
index 026dcd0..abcea53 100644
--- a/espanso/src/engine/process/middleware/matcher.rs
+++ b/espanso/src/engine/process/middleware/matcher.rs
@@ -48,6 +48,10 @@ impl<'a, State> MatchMiddleware<'a, State> {
}
impl<'a, State> Middleware for MatchMiddleware<'a, State> {
+ fn name(&self) -> &'static str {
+ "match"
+ }
+
fn next(&self, event: Event, _: &mut dyn FnMut(Event)) -> Event {
if is_event_of_interest(&event) {
let mut matcher_states = self.matcher_states.borrow_mut();
diff --git a/espanso/src/engine/process/middleware/multiplex.rs b/espanso/src/engine/process/middleware/multiplex.rs
index 890e91c..649566c 100644
--- a/espanso/src/engine/process/middleware/multiplex.rs
+++ b/espanso/src/engine/process/middleware/multiplex.rs
@@ -17,10 +17,10 @@
* along with espanso. If not, see .
*/
-use log::{debug, error};
+use log::{error};
use super::super::Middleware;
-use crate::engine::{event::{Event, text::{TextInjectRequest, TextInjectMode}, matches::MatchSelectedEvent}, process::{MatchFilter, MatchSelector, Multiplexer}};
+use crate::engine::{event::Event, process::Multiplexer};
pub struct MultiplexMiddleware<'a> {
multiplexer: &'a dyn Multiplexer,
@@ -33,6 +33,10 @@ impl<'a> MultiplexMiddleware<'a> {
}
impl<'a> Middleware for MultiplexMiddleware<'a> {
+ fn name(&self) -> &'static str {
+ "multiplex"
+ }
+
fn next(&self, event: Event, _: &mut dyn FnMut(Event)) -> Event {
if let Event::MatchSelected(m_event) = event {
return match self.multiplexer.convert(m_event.chosen.id, m_event.chosen.trigger, m_event.chosen.args) {
diff --git a/espanso/src/engine/process/mod.rs b/espanso/src/engine/process/mod.rs
index 490e3b4..012c627 100644
--- a/espanso/src/engine/process/mod.rs
+++ b/espanso/src/engine/process/mod.rs
@@ -26,6 +26,7 @@ mod default;
mod middleware;
pub trait Middleware {
+ fn name(&self) -> &'static str;
fn next(&self, event: Event, dispatch: &mut dyn FnMut(Event)) -> Event;
}