From 31ce354a4247f1d96e20b4a02e8dc1ed2676dd64 Mon Sep 17 00:00:00 2001 From: Ryan Aidan Date: Thu, 20 Jun 2024 22:40:43 +0800 Subject: [PATCH] fix: next/previous incorrect index (#14) --- rm-main/src/ui/components/table.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rm-main/src/ui/components/table.rs b/rm-main/src/ui/components/table.rs index a27176a..c394a7c 100644 --- a/rm-main/src/ui/components/table.rs +++ b/rm-main/src/ui/components/table.rs @@ -40,7 +40,8 @@ impl GenericTable { pub fn next(&mut self) { let mut state = self.state.borrow_mut(); if let Some(curr) = state.selected() { - if curr == self.get_len() { + let last_idx = self.get_len() - 1; + if curr == last_idx { state.select(Some(0)); } else { state.select(Some(curr + 1)); @@ -52,8 +53,9 @@ impl GenericTable { let mut state = self.state.borrow_mut(); if let Some(curr) = state.selected() { + let last_idx = self.get_len() - 1; if curr == 0 { - state.select(Some(self.get_len())); + state.select(Some(last_idx)); } else { state.select(Some(curr - 1)); }