diff --git a/yazi-core/src/mgr/commands/watch.rs b/yazi-core/src/mgr/commands/watch.rs index 48fcd16b..07fe2ad4 100644 --- a/yazi-core/src/mgr/commands/watch.rs +++ b/yazi-core/src/mgr/commands/watch.rs @@ -1,4 +1,4 @@ -use std::collections::HashSet; +use std::iter; use yazi_parser::mgr::WatchOpt; @@ -6,17 +6,11 @@ use crate::mgr::Mgr; impl Mgr { #[yazi_codegen::command] - pub fn watch(&mut self, _: WatchOpt) { - let mut to_watch = HashSet::with_capacity(3 * self.tabs.len()); - for tab in self.tabs.iter() { - to_watch.insert(tab.cwd()); - if let Some(ref p) = tab.parent { - to_watch.insert(&p.url); - } - if let Some(h) = tab.hovered().filter(|&h| h.is_dir()) { - to_watch.insert(&h.url); - } - } - self.watcher.watch(to_watch); + pub fn watch(&mut self, _: Opt) { + let it = iter::once(self.tabs.active().cwd()) + .chain(self.tabs.parent().map(|p| &p.url)) + .chain(self.tabs.hovered().filter(|h| h.is_dir()).map(|h| &h.url)); + + self.watcher.watch(it); } } diff --git a/yazi-core/src/mgr/tabs.rs b/yazi-core/src/mgr/tabs.rs index a1c23563..86827dbd 100644 --- a/yazi-core/src/mgr/tabs.rs +++ b/yazi-core/src/mgr/tabs.rs @@ -51,6 +51,9 @@ impl Tabs { #[inline] pub(super) fn active_mut(&mut self) -> &mut Tab { &mut self.items[self.cursor] } + #[inline] + pub fn parent(&self) -> Option<&Folder> { self.active().parent.as_ref() } + #[inline] pub fn current(&self) -> &Folder { &self.active().current } diff --git a/yazi-core/src/mgr/watcher.rs b/yazi-core/src/mgr/watcher.rs index 4943350b..c8577692 100644 --- a/yazi-core/src/mgr/watcher.rs +++ b/yazi-core/src/mgr/watcher.rs @@ -51,9 +51,8 @@ impl Watcher { Self { in_tx, out_tx } } - pub(super) fn watch(&mut self, mut new: HashSet<&Url>) { - new.retain(|&u| u.is_regular()); - self.in_tx.send(new.into_iter().cloned().collect()).ok(); + pub(super) fn watch<'a>(&mut self, it: impl Iterator) { + self.in_tx.send(it.into_iter().filter(|u| u.is_regular()).cloned().collect()).ok(); } pub(super) fn push_files(&self, urls: Vec) { diff --git a/yazi-plugin/preset/plugins/archive.lua b/yazi-plugin/preset/plugins/archive.lua index 72c081d9..231d41ff 100644 --- a/yazi-plugin/preset/plugins/archive.lua +++ b/yazi-plugin/preset/plugins/archive.lua @@ -8,7 +8,7 @@ function M:peek(job) return require("empty").msg( job, code == 2 and "File list in this archive is encrypted" - or "Failed to start both `7zz` and `7z`. Do you have 7-zip installed?" + or "Failed to start either `7zz` or `7z`. Do you have 7-zip installed?" ) end @@ -65,7 +65,7 @@ function M.spawn_7z(args) local child = try("7zz") or try("7z") if not child then - return ya.err("Failed to start both `7zz` and `7z`, error: " .. last_err) + return ya.err("Failed to start either `7zz` or `7z`, error: " .. last_err) end return child, last_err end diff --git a/yazi-plugin/preset/plugins/extract.lua b/yazi-plugin/preset/plugins/extract.lua index a4d2d717..c7f68919 100644 --- a/yazi-plugin/preset/plugins/extract.lua +++ b/yazi-plugin/preset/plugins/extract.lua @@ -53,7 +53,7 @@ function M:try_with(from, pwd, to) local archive = require("archive") local child, err = archive.spawn_7z { "x", "-aou", "-sccUTF-8", "-p" .. pwd, "-o" .. tostring(tmp), tostring(from) } if not child then - fail("Failed to start both `7zz` and `7z`, error: " .. err) + fail("Failed to start either `7zz` or `7z`, error: " .. err) end local output, err = child:wait_with_output()