fix(engine): prevent other keys from interfering with toggle_key. Fix #815
This commit is contained in:
parent
8bab0f5e42
commit
21bc75bc31
|
@ -64,18 +64,24 @@ impl Middleware for DisableMiddleware {
|
||||||
|
|
||||||
match &event.etype {
|
match &event.etype {
|
||||||
EventType::Keyboard(m_event) => {
|
EventType::Keyboard(m_event) => {
|
||||||
if is_toggle_key(m_event, &self.options) {
|
if m_event.status == Status::Released {
|
||||||
let mut last_toggle_press = self.last_toggle_press.borrow_mut();
|
let mut last_toggle_press = self.last_toggle_press.borrow_mut();
|
||||||
if let Some(previous_press) = *last_toggle_press {
|
if is_toggle_key(m_event, &self.options) {
|
||||||
if previous_press.elapsed() < self.options.toggle_key_maximum_window {
|
if let Some(previous_press) = *last_toggle_press {
|
||||||
*enabled = !*enabled;
|
if previous_press.elapsed() < self.options.toggle_key_maximum_window {
|
||||||
*last_toggle_press = None;
|
*enabled = !*enabled;
|
||||||
has_status_changed = true;
|
*last_toggle_press = None;
|
||||||
|
has_status_changed = true;
|
||||||
|
} else {
|
||||||
|
*last_toggle_press = Some(Instant::now());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
*last_toggle_press = Some(Instant::now());
|
*last_toggle_press = Some(Instant::now());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
*last_toggle_press = Some(Instant::now());
|
// If another key is pressed (not the toggle key), we should reset the window
|
||||||
|
// For more information, see: https://github.com/federico-terzi/espanso/issues/815
|
||||||
|
*last_toggle_press = None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,10 +121,6 @@ impl Middleware for DisableMiddleware {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_toggle_key(event: &KeyboardEvent, options: &DisableOptions) -> bool {
|
fn is_toggle_key(event: &KeyboardEvent, options: &DisableOptions) -> bool {
|
||||||
if event.status != Status::Released {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if options
|
if options
|
||||||
.toggle_key
|
.toggle_key
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user