From a9f286c52b2252a03db68323c0655404fd676f93 Mon Sep 17 00:00:00 2001 From: Reinis Mazeiks Date: Wed, 29 Jun 2022 07:44:19 +0300 Subject: [PATCH] Fix bug in TUI key repeat handling --- packages/tui/src/hooks.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/tui/src/hooks.rs b/packages/tui/src/hooks.rs index bb5f81dfb..59aa7a7e3 100644 --- a/packages/tui/src/hooks.rs +++ b/packages/tui/src/hooks.rs @@ -146,14 +146,16 @@ impl InnerInputState { .last_key_pressed .as_ref() // heuristic for guessing which presses are auto-repeating. not necessarily accurate - .filter(|k2| k2.0.key() == k.key() && k2.1.elapsed() < MAX_REPEAT_TIME) + .filter(|(last_data, last_instant)| { + last_data.key() == k.key() && last_instant.elapsed() < MAX_REPEAT_TIME + }) .is_some(); - if is_repeating { - let new = k.clone(); - self.last_key_pressed = Some((new, Instant::now())); + if is_repeating { *k = KeyboardData::new(k.key(), k.code(), k.location(), true, k.modifiers()); } + + self.last_key_pressed = Some((k.clone(), Instant::now())); } } }