Skip to content

Commit 7169e19

Browse files
authored
feat: fine-grained peek and watch (#2655)
1 parent 8327826 commit 7169e19

File tree

16 files changed

+60
-30
lines changed

16 files changed

+60
-30
lines changed

yazi-core/src/mgr/commands/hover.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::collections::HashSet;
2-
31
use yazi_dds::Pubsub;
42
use yazi_macro::render;
53
use yazi_shared::{Id, event::{CmdCow, Data}, url::{Url, Urn}};
@@ -29,21 +27,8 @@ impl Mgr {
2927
self.current_or_mut(opt.tab).arrow(0);
3028
}
3129

32-
// Repeek
33-
self.peek(false);
34-
3530
// Refresh watcher
36-
let mut to_watch = HashSet::with_capacity(3 * self.tabs.len());
37-
for tab in self.tabs.iter() {
38-
to_watch.insert(tab.cwd());
39-
if let Some(ref p) = tab.parent {
40-
to_watch.insert(&p.url);
41-
}
42-
if let Some(h) = tab.hovered().filter(|&h| h.is_dir()) {
43-
to_watch.insert(&h.url);
44-
}
45-
}
46-
self.watcher.watch(to_watch);
31+
self.watch(());
4732

4833
// Publish through DDS
4934
Pubsub::pub_from_hover(self.active().id, self.hovered().map(|h| &h.url));

yazi-core/src/mgr/commands/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ yazi_macro::mod_flat!(
2525
update_paged
2626
update_tasks
2727
update_yanked
28+
watch
2829
yank
2930
);

yazi-core/src/mgr/commands/refresh.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ impl Mgr {
2121
self.watcher.trigger_dirs(&[self.current()]);
2222
}
2323

24-
self.hover(None);
24+
self.watch(());
25+
self.peek(false);
2526
self.update_paged((), tasks);
2627

2728
tasks.prework_sorted(&self.current().files);

yazi-core/src/mgr/commands/update_files.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,20 @@ impl Mgr {
2222
return;
2323
};
2424

25+
let revision = self.current().files.revision;
2526
let linked: Vec<_> = LINKED.read().from_dir(opt.op.cwd()).map(|u| opt.op.rebase(u)).collect();
2627
for op in [opt.op].into_iter().chain(linked) {
2728
self.yanked.apply_op(&op);
2829
self.update_tab(op, tasks);
2930
}
3031

3132
render!(self.yanked.catchup_revision(false));
32-
self.active_mut().apply_files_attrs();
33+
if revision != self.current().files.revision {
34+
self.active_mut().apply_files_attrs();
35+
self.hover(None);
36+
self.peek(false);
37+
self.update_paged((), tasks);
38+
}
3339
}
3440

3541
fn update_tab(&mut self, op: FilesOp, tasks: &Tasks) {
@@ -71,8 +77,6 @@ impl Mgr {
7177
return;
7278
}
7379

74-
self.hover(None); // Re-hover
75-
self.update_paged((), tasks); // Update for paged files
7680
if calc {
7781
tasks.prework_sorted(&self.current().files);
7882
}

yazi-core/src/mgr/commands/update_paged.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl From<()> for Opt {
2020

2121
impl Mgr {
2222
pub fn update_paged(&mut self, opt: impl TryInto<Opt>, tasks: &Tasks) {
23-
let Ok(opt) = opt.try_into() else {
23+
let Ok(opt): Result<Opt, _> = opt.try_into() else {
2424
return;
2525
};
2626

@@ -29,7 +29,9 @@ impl Mgr {
2929
}
3030

3131
let targets = self.current().paginate(opt.page.unwrap_or(self.current().page));
32-
tasks.fetch_paged(targets, &self.mimetype);
33-
tasks.preload_paged(targets, &self.mimetype);
32+
if !targets.is_empty() {
33+
tasks.fetch_paged(targets, &self.mimetype);
34+
tasks.preload_paged(targets, &self.mimetype);
35+
}
3436
}
3537
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use std::collections::HashSet;
2+
3+
use yazi_shared::event::CmdCow;
4+
5+
use crate::mgr::Mgr;
6+
7+
struct Opt;
8+
9+
impl From<CmdCow> for Opt {
10+
fn from(_: CmdCow) -> Self { Self }
11+
}
12+
impl From<()> for Opt {
13+
fn from((): ()) -> Self { Self }
14+
}
15+
16+
impl Mgr {
17+
#[yazi_codegen::command]
18+
pub fn watch(&mut self, _: Opt) {
19+
let mut to_watch = HashSet::with_capacity(3 * self.tabs.len());
20+
for tab in self.tabs.iter() {
21+
to_watch.insert(tab.cwd());
22+
if let Some(ref p) = tab.parent {
23+
to_watch.insert(&p.url);
24+
}
25+
if let Some(h) = tab.hovered().filter(|&h| h.is_dir()) {
26+
to_watch.insert(&h.url);
27+
}
28+
}
29+
self.watcher.watch(to_watch);
30+
}
31+
}

yazi-core/src/tab/commands/arrow.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ impl Tab {
3737
}
3838

3939
MgrProxy::hover(None, self.id);
40+
MgrProxy::peek(false);
4041
render!();
4142
}
4243
}

yazi-core/src/tab/commands/filter_do.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ impl Tab {
2828
self.current.repos(hovered.as_ref());
2929
if self.hovered().map(|f| f.urn()) != hovered.as_ref().map(|u| u.as_urn()) {
3030
MgrProxy::hover(None, self.id);
31+
MgrProxy::peek(false);
3132
}
3233

3334
render!();

yazi-core/src/tab/commands/hidden.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ impl Tab {
1616

1717
if hovered.as_ref() != self.hovered().map(|f| &f.url) {
1818
MgrProxy::hover(hovered, self.id);
19+
MgrProxy::peek(false);
1920
} else if self.hovered().is_some_and(|f| f.is_dir()) {
2021
MgrProxy::peek(true);
2122
}

yazi-core/src/tab/commands/reveal.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ impl Tab {
3030
};
3131

3232
self.cd(parent.clone());
33+
// TODO
3334
FilesOp::Creating(parent, vec![File::from_dummy(opt.target.clone(), None)]).emit();
3435
MgrProxy::hover(Some(opt.target), self.id);
36+
MgrProxy::peek(false);
3537
}
3638
}

0 commit comments

Comments
 (0)