浏览代码

Fix bug in TUI key repeat handling

Reinis Mazeiks 3 年之前
父节点
当前提交
a9f286c52b
共有 1 个文件被更改,包括 6 次插入4 次删除
  1. 6 4
      packages/tui/src/hooks.rs

+ 6 - 4
packages/tui/src/hooks.rs

@@ -146,14 +146,16 @@ impl InnerInputState {
                     .last_key_pressed
                     .last_key_pressed
                     .as_ref()
                     .as_ref()
                     // heuristic for guessing which presses are auto-repeating. not necessarily accurate
                     // 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();
                     .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());
                     *k = KeyboardData::new(k.key(), k.code(), k.location(), true, k.modifiers());
                 }
                 }
+
+                self.last_key_pressed = Some((k.clone(), Instant::now()));
             }
             }
         }
         }
     }
     }