mirror of
https://github.com/sxyazi/yazi.git
synced 2026-05-13 08:16:40 +00:00
feat: allow tab_swap to cycle tabs (#2456)
This commit is contained in:
parent
a2bbd29289
commit
ece635d6b8
4 changed files with 3 additions and 11 deletions
|
|
@ -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!();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue