From d225dda6465fc92e94542e0c0fe9938b1b157fe3 Mon Sep 17 00:00:00 2001 From: Remigiusz Micielski Date: Mon, 12 Aug 2024 10:44:58 +0200 Subject: [PATCH] get rid of some bugs related to table scrolling --- rm-main/src/ui/components/table.rs | 4 ++++ rm-main/src/ui/tabs/search/mod.rs | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/rm-main/src/ui/components/table.rs b/rm-main/src/ui/components/table.rs index 824515a..6b5177c 100644 --- a/rm-main/src/ui/components/table.rs +++ b/rm-main/src/ui/components/table.rs @@ -50,6 +50,8 @@ impl GenericTable { } else { state.select(Some(curr + 1)); } + } else { + state.select(Some(0)); } } @@ -67,6 +69,8 @@ impl GenericTable { } else { state.select(Some(curr - 1)); } + } else { + state.select(Some(0)); } } diff --git a/rm-main/src/ui/tabs/search/mod.rs b/rm-main/src/ui/tabs/search/mod.rs index 79c0d5a..f9d11c5 100644 --- a/rm-main/src/ui/tabs/search/mod.rs +++ b/rm-main/src/ui/tabs/search/mod.rs @@ -1,7 +1,10 @@ mod bottom_bar; mod popups; -use std::{borrow::Cow, sync::Arc}; +use std::{ + borrow::{BorrowMut, Cow}, + sync::Arc, +}; use bottom_bar::BottomBar; use crossterm::event::{KeyCode, KeyEvent}; @@ -269,6 +272,7 @@ impl Component for SearchTab { self.providers_searching(); self.table.items.drain(..); + self.table.state.borrow_mut().select(None); self.bottom_bar .handle_update_action(UpdateAction::SearchStarted); @@ -287,6 +291,11 @@ impl Component for SearchTab { self.table.items.extend(response.magnets); self.table.items.sort_by(|a, b| b.seeders.cmp(&a.seeders)); + + let mut state = self.table.state.borrow_mut(); + if !self.table.items.is_empty() && state.selected().is_none() { + state.select(Some(0)) + } } UpdateAction::ProviderError(e) => { self.provider_state_error(e.provider, e.kind);