From ec1680eb2de3e3c68346cc75a3c08f4b1fcec75c Mon Sep 17 00:00:00 2001 From: micielski <73398428+micielski@users.noreply.github.com> Date: Sun, 8 Sep 2024 08:57:40 +0200 Subject: [PATCH] fix: being stuck in filtering bar, default keymap (#113) --- rm-config/defaults/keymap.toml | 3 +-- 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 ++-- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/rm-config/defaults/keymap.toml b/rm-config/defaults/keymap.toml index 73f7b95..83500ad 100644 --- a/rm-config/defaults/keymap.toml +++ b/rm-config/defaults/keymap.toml @@ -44,8 +44,7 @@ keybindings = [ { on = "f", action = "ShowFiles" }, { on = "s", action = "ShowStats" }, - { on = "d", action = "DeleteWithoutFiles" }, - { on = "D", action = "DeleteWithFiles" }, + { on = "d", action = "Delete" }, ] [search_tab] 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..009708d 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 }