yazi_core/tab/commands/
arrow.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use yazi_fs::Step;
use yazi_macro::render;
use yazi_proxy::ManagerProxy;
use yazi_shared::event::CmdCow;

use crate::tab::Tab;

struct Opt {
	step: Step,
}

impl From<CmdCow> for Opt {
	fn from(c: CmdCow) -> Self {
		Self { step: c.first().and_then(|d| d.try_into().ok()).unwrap_or_default() }
	}
}

impl From<isize> for Opt {
	fn from(n: isize) -> Self { Self { step: n.into() } }
}

impl Tab {
	#[yazi_codegen::command]
	pub fn arrow(&mut self, opt: Opt) {
		// TODO: remove this
		if let Step::Fixed(n) = opt.step {
			if n <= -999 || n >= 999 {
				yazi_proxy::AppProxy::notify_warn(
					"Deprecated command",
					"`arrow -99999999` and `arrow 99999999` have been deprecated, please use `arrow top` and `arrow bot` instead.

See #2294 for more details: https://github.com/sxyazi/yazi/pull/2294",
				);
			}
		}

		if !self.current.arrow(opt.step) {
			return;
		}

		// Visual selection
		if let Some((start, items)) = self.mode.visual_mut() {
			let after = self.current.cursor;

			items.clear();
			for i in start.min(after)..=after.max(start) {
				items.insert(i);
			}
		}

		ManagerProxy::hover(None, self.id);
		render!();
	}
}