feat: allow tab_swap to cycle tabs (#2456)

This commit is contained in:
三咲雅 · Misaki Masa 2025-03-08 09:50:38 +08:00 committed by GitHub
parent a2bbd29289
commit ece635d6b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 3 additions and 11 deletions

View file

@ -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!();

View file

@ -14,7 +14,7 @@ impl From<CmdCow> 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;
}

View file

@ -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
};

View file

@ -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) {