mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
35 lines
661 B
Rust
35 lines
661 B
Rust
use yazi_shared::{event::Cmd, render};
|
|
|
|
use crate::manager::Tabs;
|
|
|
|
pub struct Opt {
|
|
step: isize,
|
|
relative: bool,
|
|
}
|
|
|
|
impl From<Cmd> for Opt {
|
|
fn from(mut c: Cmd) -> Self {
|
|
Self {
|
|
step: c.take_first().and_then(|s| s.parse().ok()).unwrap_or(0),
|
|
relative: c.named.contains_key("relative"),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Tabs {
|
|
pub fn switch(&mut self, opt: impl Into<Opt>) {
|
|
let opt = opt.into() as Opt;
|
|
let idx = if opt.relative {
|
|
(self.idx as isize + opt.step).rem_euclid(self.items.len() as isize) as usize
|
|
} else {
|
|
opt.step as usize
|
|
};
|
|
|
|
if idx == self.idx || idx >= self.items.len() {
|
|
return;
|
|
}
|
|
|
|
self.set_idx(idx);
|
|
render!();
|
|
}
|
|
}
|