yazi_core/tasks/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
use yazi_macro::render;
use yazi_shared::event::{CmdCow, Data};

use crate::tasks::Tasks;

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 From<isize> for Opt {
	fn from(step: isize) -> Self { Self { step } }
}

impl Tasks {
	#[yazi_codegen::command]
	pub fn arrow(&mut self, opt: Opt) {
		let old = self.cursor;
		if opt.step > 0 {
			self.cursor += 1;
		} else {
			self.cursor = self.cursor.saturating_sub(1);
		}

		let max = Self::limit().min(self.summaries.len());
		self.cursor = self.cursor.min(max.saturating_sub(1));
		render!(self.cursor != old);
	}
}