yazi_core/completion/
completion.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
use std::{collections::HashMap, path::PathBuf};

#[derive(Default)]
pub struct Completion {
	pub(super) caches: HashMap<PathBuf, Vec<String>>,
	pub(super) cands:  Vec<String>,
	pub(super) offset: usize,
	pub cursor:        usize,

	pub(super) ticket: usize,
	pub visible:       bool,
}

impl Completion {
	// --- Cands
	#[inline]
	pub fn window(&self) -> &[String] {
		let end = (self.offset + self.limit()).min(self.cands.len());
		&self.cands[self.offset..end]
	}

	#[inline]
	pub fn limit(&self) -> usize { self.cands.len().min(10) }

	#[inline]
	pub fn selected(&self) -> Option<&String> { self.cands.get(self.cursor) }

	// --- Cursor
	#[inline]
	pub fn rel_cursor(&self) -> usize { self.cursor - self.offset }
}