mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
26 lines
534 B
Rust
26 lines
534 B
Rust
use yazi_macro::render;
|
|
use yazi_shared::event::{CmdCow, Data};
|
|
|
|
use crate::mgr::Tabs;
|
|
|
|
struct Opt {
|
|
step: isize,
|
|
}
|
|
|
|
impl From<CmdCow> for Opt {
|
|
fn from(c: CmdCow) -> Self { Self { step: c.first().and_then(Data::as_isize).unwrap_or(0) } }
|
|
}
|
|
|
|
impl Tabs {
|
|
#[yazi_codegen::command]
|
|
pub fn swap(&mut self, opt: Opt) {
|
|
let idx = opt.step.saturating_add_unsigned(self.cursor).rem_euclid(self.items.len() as _) as _;
|
|
if idx == self.cursor {
|
|
return;
|
|
}
|
|
|
|
self.items.swap(self.cursor, idx);
|
|
self.set_idx(idx);
|
|
render!();
|
|
}
|
|
}
|