mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-24 08:11:04 +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 {
|
if opt.idx > self.cursor {
|
||||||
self.set_idx(self.cursor);
|
self.set_idx(self.cursor);
|
||||||
} else {
|
} else {
|
||||||
self.set_idx(self.absolute(1));
|
self.set_idx(usize::min(self.cursor + 1, self.items.len() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
render!();
|
render!();
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ impl From<CmdCow> for Opt {
|
||||||
impl Tabs {
|
impl Tabs {
|
||||||
#[yazi_codegen::command]
|
#[yazi_codegen::command]
|
||||||
pub fn swap(&mut self, opt: Opt) {
|
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 {
|
if idx == self.cursor {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ impl Tabs {
|
||||||
#[yazi_codegen::command]
|
#[yazi_codegen::command]
|
||||||
pub fn switch(&mut self, opt: Opt) {
|
pub fn switch(&mut self, opt: Opt) {
|
||||||
let idx = if opt.relative {
|
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 {
|
} else {
|
||||||
opt.step as usize
|
opt.step as usize
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -29,14 +29,6 @@ impl Tabs {
|
||||||
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) {
|
pub(super) fn set_idx(&mut self, idx: usize) {
|
||||||
// Reset the preview of the last active tab
|
// Reset the preview of the last active tab
|
||||||
if let Some(active) = self.items.get_mut(self.cursor) {
|
if let Some(active) = self.items.get_mut(self.cursor) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue