From 823157a362da33022325247dfd82a6440a0a932b Mon Sep 17 00:00:00 2001 From: Remigiusz Micielski Date: Mon, 19 Aug 2024 09:10:27 +0200 Subject: [PATCH] simplify the code a bit --- rm-main/src/tui/components/table.rs | 16 ++++------------ rm-main/src/tui/tabs/search/mod.rs | 4 ++-- rm-main/src/tui/tabs/torrents/mod.rs | 8 ++++---- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/rm-main/src/tui/components/table.rs b/rm-main/src/tui/components/table.rs index 6b5177c..0e126ad 100644 --- a/rm-main/src/tui/components/table.rs +++ b/rm-main/src/tui/components/table.rs @@ -100,19 +100,11 @@ impl GenericTable { } } - pub fn scroll_to_home(&mut self) { - let mut state = self.state.borrow_mut(); - if !self.items.is_empty() { - state.select(Some(0)); - } + pub fn select_first(&mut self) { + self.state.borrow_mut().select_first(); } - pub fn scroll_to_end(&mut self) { - if self.items.is_empty() { - return; - } - - let mut state = self.state.borrow_mut(); - state.select(Some(self.items.len() - 1)); + pub fn select_last(&mut self) { + self.state.borrow_mut().select_last(); } } diff --git a/rm-main/src/tui/tabs/search/mod.rs b/rm-main/src/tui/tabs/search/mod.rs index a3e8474..019712b 100644 --- a/rm-main/src/tui/tabs/search/mod.rs +++ b/rm-main/src/tui/tabs/search/mod.rs @@ -200,12 +200,12 @@ impl SearchTab { } fn scroll_to_end(&mut self) { - self.table.scroll_to_end(); + self.table.select_last(); self.ctx.send_action(Action::Render); } fn scroll_to_home(&mut self) { - self.table.scroll_to_home(); + self.table.select_first(); self.ctx.send_action(Action::Render); } diff --git a/rm-main/src/tui/tabs/torrents/mod.rs b/rm-main/src/tui/tabs/torrents/mod.rs index e350b4a..1e1fd8d 100644 --- a/rm-main/src/tui/tabs/torrents/mod.rs +++ b/rm-main/src/tui/tabs/torrents/mod.rs @@ -110,7 +110,7 @@ impl Component for TorrentsTab { self.task_manager.move_torrent(torrent); } } - A::XdgOpen => self.open_current_torrent(), + A::XdgOpen => self.xdg_open_current_torrent(), other => { self.task_manager.handle_actions(other); } @@ -263,14 +263,14 @@ impl TorrentsTab { } fn scroll_to_home(&mut self) { - self.table_manager.table.scroll_to_home(); + self.table_manager.table.select_first(); self.bottom_stats .update_selected_indicator(&self.table_manager); self.ctx.send_action(Action::Render); } fn scroll_to_end(&mut self) { - self.table_manager.table.scroll_to_end(); + self.table_manager.table.select_last(); self.bottom_stats .update_selected_indicator(&self.table_manager); self.ctx.send_action(Action::Render); @@ -296,7 +296,7 @@ impl TorrentsTab { } } - fn open_current_torrent(&mut self) { + fn xdg_open_current_torrent(&mut self) { if let Some(torrent) = self.table_manager.current_torrent() { let torrent_location = torrent.torrent_location(); match open::that_detached(&torrent_location) {