From 98359c4d8b5c4582b2902006ad1fbed724893b48 Mon Sep 17 00:00:00 2001 From: Remigiusz Micielski Date: Sat, 7 Sep 2024 12:39:19 +0200 Subject: [PATCH] fix: being stuck in filtering bar --- rm-main/src/tui/components/table.rs | 2 +- rm-main/src/tui/tabs/torrents/mod.rs | 2 +- rm-main/src/tui/tabs/torrents/table_manager.rs | 5 +++++ rm-main/src/tui/tabs/torrents/task_manager.rs | 4 ++-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/rm-main/src/tui/components/table.rs b/rm-main/src/tui/components/table.rs index 7917205..8db48f1 100644 --- a/rm-main/src/tui/components/table.rs +++ b/rm-main/src/tui/components/table.rs @@ -83,7 +83,7 @@ impl GenericTable { let new_selection = state.selected().unwrap_or_default() + amount; if new_selection > self.get_len() { - state.select(Some(self.get_len() - 1)); + state.select(Some(self.get_len().saturating_sub(1))); } else { state.select(Some(new_selection)); }; diff --git a/rm-main/src/tui/tabs/torrents/mod.rs b/rm-main/src/tui/tabs/torrents/mod.rs index a07abce..52e7930 100644 --- a/rm-main/src/tui/tabs/torrents/mod.rs +++ b/rm-main/src/tui/tabs/torrents/mod.rs @@ -226,7 +226,7 @@ impl Component for TorrentsTab { self.popup_manager.handle_update_action(action) } UpdateAction::CancelTorrentTask => { - if !self.task_manager.is_finished_status_task() { + if self.task_manager.is_status_task_in_progress() { return; } diff --git a/rm-main/src/tui/tabs/torrents/table_manager.rs b/rm-main/src/tui/tabs/torrents/table_manager.rs index 5845205..7f6ddd3 100644 --- a/rm-main/src/tui/tabs/torrents/table_manager.rs +++ b/rm-main/src/tui/tabs/torrents/table_manager.rs @@ -276,6 +276,11 @@ impl TableManager { self.widths = self.header_widths(&self.table.items); self.update_rows_number(); self.sort(); + + // let mut state = self.table.state.borrow_mut(); + // if state.selected().is_none() && !self.table.items.is_empty() { + // state.select(Some(0)); + // } } pub fn set_filter(&mut self, filter: String) { diff --git a/rm-main/src/tui/tabs/torrents/task_manager.rs b/rm-main/src/tui/tabs/torrents/task_manager.rs index 6eacca3..e11a515 100644 --- a/rm-main/src/tui/tabs/torrents/task_manager.rs +++ b/rm-main/src/tui/tabs/torrents/task_manager.rs @@ -206,9 +206,9 @@ impl TaskManager { self.ctx.send_update_action(UpdateAction::CancelTorrentTask); } - pub fn is_finished_status_task(&self) -> bool { + pub fn is_status_task_in_progress(&self) -> bool { if let CurrentTask::Status(task) = &self.current_task { - !matches!(task.task_status, CurrentTaskState::Loading(_)) + matches!(task.task_status, CurrentTaskState::Loading(_)) } else { false }