diff --git a/yazi-core/src/mgr/commands/tab_close.rs b/yazi-core/src/mgr/commands/tab_close.rs index 0f699b61..59cc62df 100644 --- a/yazi-core/src/mgr/commands/tab_close.rs +++ b/yazi-core/src/mgr/commands/tab_close.rs @@ -27,7 +27,7 @@ impl Tabs { if opt.idx > self.cursor { self.set_idx(self.cursor); } else { - self.set_idx(self.absolute(1)); + self.set_idx(usize::min(self.cursor + 1, self.items.len() - 1)); } render!(); diff --git a/yazi-core/src/mgr/commands/tab_swap.rs b/yazi-core/src/mgr/commands/tab_swap.rs index 33888ec2..11c111ca 100644 --- a/yazi-core/src/mgr/commands/tab_swap.rs +++ b/yazi-core/src/mgr/commands/tab_swap.rs @@ -14,7 +14,7 @@ impl From for Opt { impl Tabs { #[yazi_codegen::command] pub fn swap(&mut self, opt: Opt) { - let idx = self.absolute(opt.step); + let idx = opt.step.saturating_add_unsigned(self.cursor).rem_euclid(self.items.len() as _) as _; if idx == self.cursor { return; } diff --git a/yazi-core/src/mgr/commands/tab_switch.rs b/yazi-core/src/mgr/commands/tab_switch.rs index 9bb6c78c..c174ebdf 100644 --- a/yazi-core/src/mgr/commands/tab_switch.rs +++ b/yazi-core/src/mgr/commands/tab_switch.rs @@ -18,7 +18,7 @@ impl Tabs { #[yazi_codegen::command] pub fn switch(&mut self, opt: Opt) { let idx = if opt.relative { - (self.cursor as isize + opt.step).rem_euclid(self.items.len() as isize) as usize + opt.step.saturating_add_unsigned(self.cursor).rem_euclid(self.items.len() as _) as _ } else { opt.step as usize }; diff --git a/yazi-core/src/mgr/tabs.rs b/yazi-core/src/mgr/tabs.rs index 5e9e4875..9c53e657 100644 --- a/yazi-core/src/mgr/tabs.rs +++ b/yazi-core/src/mgr/tabs.rs @@ -29,14 +29,6 @@ impl Tabs { tabs } - pub(super) fn absolute(&self, rel: isize) -> usize { - if rel > 0 { - (self.cursor + rel as usize).min(self.items.len() - 1) - } else { - self.cursor.saturating_sub(rel.unsigned_abs()) - } - } - pub(super) fn set_idx(&mut self, idx: usize) { // Reset the preview of the last active tab if let Some(active) = self.items.get_mut(self.cursor) {