fix: tui lag keyboard navigation

This commit is contained in:
Michel de Graaf
2026-07-20 10:25:42 +02:00
parent 9b0199fbbc
commit 17864ac9b0
+15 -2
View File
@@ -113,8 +113,12 @@ impl MainTui {
// Update spinner // Update spinner
self.spinner_state = (self.spinner_state + 1) % 10; self.spinner_state = (self.spinner_state + 1) % 10;
// Poll for input events // Drain every queued input event before the next draw: key
// autorepeat outpaces the frame time, and handling one event per
// frame makes the backlog keep scrolling for seconds after the
// key is released.
if poll(Duration::from_millis(100))? { if poll(Duration::from_millis(100))? {
loop {
match event::read()? { match event::read()? {
Event::Key(key) if key.kind == KeyEventKind::Press => { Event::Key(key) if key.kind == KeyEventKind::Press => {
self.handle_key_event(key); self.handle_key_event(key);
@@ -124,6 +128,10 @@ impl MainTui {
} }
_ => {} _ => {}
} }
if self.state.should_exit || !poll(Duration::ZERO)? {
break;
}
}
} }
} }
@@ -1715,7 +1723,12 @@ impl MainTui {
// Now update state without holding any client locks // Now update state without holding any client locks
for (idx, search_results) in all_results { for (idx, search_results) in all_results {
if let Some(search) = self.state.searches.get_mut(idx) { if let Some(search) = self.state.searches.get_mut(idx) {
if !search_results.is_empty() { // Results only accumulate, so an unchanged file count means
// nothing new arrived: skip the rebuild, which clones the
// full result list several times and dominates frame time.
let total_files: usize =
search_results.iter().map(|r| r.files.len()).sum();
if total_files != search.results.len() {
search.results.clear(); search.results.clear();
for result in search_results { for result in search_results {
for file in result.files { for file in result.files {