fix(engine): prevent other keys from interfering with toggle_key. Fix #815
This commit is contained in:
parent
8bab0f5e42
commit
21bc75bc31
|
@ -64,8 +64,9 @@ impl Middleware for DisableMiddleware {
|
|||
|
||||
match &event.etype {
|
||||
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();
|
||||
if is_toggle_key(m_event, &self.options) {
|
||||
if let Some(previous_press) = *last_toggle_press {
|
||||
if previous_press.elapsed() < self.options.toggle_key_maximum_window {
|
||||
*enabled = !*enabled;
|
||||
|
@ -77,6 +78,11 @@ impl Middleware for DisableMiddleware {
|
|||
} else {
|
||||
*last_toggle_press = Some(Instant::now());
|
||||
}
|
||||
} else {
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
EventType::EnableRequest => {
|
||||
|
@ -115,10 +121,6 @@ impl Middleware for DisableMiddleware {
|
|||
}
|
||||
|
||||
fn is_toggle_key(event: &KeyboardEvent, options: &DisableOptions) -> bool {
|
||||
if event.status != Status::Released {
|
||||
return false;
|
||||
}
|
||||
|
||||
if options
|
||||
.toggle_key
|
||||
.as_ref()
|
||||
|
|
Loading…
Reference in New Issue
Block a user