yazi_core/manager/commands/
tab_swap.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use yazi_macro::render;
use yazi_shared::event::{CmdCow, Data};

use crate::manager::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 = self.absolute(opt.step);
		if idx == self.cursor {
			return;
		}

		self.items.swap(self.cursor, idx);
		self.set_idx(idx);
		render!();
	}
}