fix(core): fix bug that prevented a matcher state invalidation on mouse clicks

This commit is contained in:
Federico Terzi 2021-05-05 22:02:12 +02:00
parent eeec734d32
commit 10d37d1fe6

View File

@ -68,15 +68,15 @@ impl<'a, State> Middleware for MatcherMiddleware<'a, State> {
matcher_states.pop_back();
return event;
}
}
// Some keys (such as the arrow keys) prevent espanso from building
// Some keys (such as the arrow keys) and mouse clicks prevent espanso from building
// an accurate key buffer, so we need to invalidate it.
if is_invalidating_key(&keyboard_event.key) {
if is_invalidating_event(&event.etype) {
trace!("invalidating event detected, clearing matching state");
matcher_states.clear();
return event;
}
}
let mut all_results = Vec::new();
@ -158,8 +158,9 @@ fn convert_to_matcher_event(event_type: &EventType) -> Option<MatcherEvent> {
}
}
fn is_invalidating_key(key: &Key) -> bool {
match key {
fn is_invalidating_event(event_type: &EventType) -> bool {
match event_type {
EventType::Keyboard(keyboard_event) => match keyboard_event.key {
Key::ArrowDown => true,
Key::ArrowLeft => true,
Key::ArrowRight => true,
@ -170,6 +171,9 @@ fn is_invalidating_key(key: &Key) -> bool {
Key::PageUp => true,
Key::Escape => true,
_ => false,
},
EventType::Mouse(_) => true,
_ => false,
}
}