yazi_core/tab/commands/
update_peeked.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
use yazi_macro::render;
use yazi_plugin::utils::PreviewLock;
use yazi_shared::event::CmdCow;

use crate::tab::Tab;

pub struct Opt {
	lock: PreviewLock,
}

impl TryFrom<CmdCow> for Opt {
	type Error = ();

	fn try_from(mut c: CmdCow) -> Result<Self, Self::Error> {
		Ok(Self { lock: c.take_any("lock").ok_or(())? })
	}
}

impl Tab {
	pub fn update_peeked(&mut self, opt: impl TryInto<Opt>) {
		let Some(hovered) = self.hovered().map(|h| &h.url) else {
			return self.preview.reset();
		};

		let Ok(opt) = opt.try_into() else {
			return;
		};

		if opt.lock.url != *hovered {
			return;
		}

		self.preview.lock = Some(opt.lock);
		render!();
	}
}