From 93604362d7bc3ab210941e3b395b2226414bbef8 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Thu, 12 Mar 2026 16:11:32 +0800 Subject: [PATCH] .. --- CHANGELOG.md | 3 ++- yazi-plugin/preset/plugins/folder.lua | 7 ++++++- yazi-plugin/preset/plugins/multi.lua | 2 +- yazi-plugin/src/utils/sync.rs | 6 +++--- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fcc1df6..ccecb23f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,7 +31,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/): - New `ind-which-activate` DDS event to change the which component behavior ([#3608]) - New `hey` DDS event fires when static messages are restored from persistence ([#3725]) - New `cx.which` API to access the which component state ([#3617]) -- New experimental `ya.co()` API that creates a coroutine ([#1234]) +- New experimental `ya.co()` API that creates a coroutine ([#3757]) ### Changed @@ -1681,3 +1681,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/): [#3733]: https://github.com/sxyazi/yazi/pull/3733 [#3744]: https://github.com/sxyazi/yazi/pull/3744 [#3748]: https://github.com/sxyazi/yazi/pull/3748 +[#3757]: https://github.com/sxyazi/yazi/pull/3757 diff --git a/yazi-plugin/preset/plugins/folder.lua b/yazi-plugin/preset/plugins/folder.lua index 761e3d23..43d75ab2 100644 --- a/yazi-plugin/preset/plugins/folder.lua +++ b/yazi-plugin/preset/plugins/folder.lua @@ -50,7 +50,7 @@ function M:seek(job) end function M:spot(job) - local i = 0 + local i, url = 0, job.file.url for rows in self:spot_base(job) do i, rows[#rows + 1] = i + 1, ui.Row {} ya.spot_table( @@ -64,6 +64,9 @@ function M:spot(job) :widths { ui.Constraint.Length(14), ui.Constraint.Fill(1) } ) end + if self.size then + ya.emit("update_files", { op = fs.op("size", { url = url.parent, sizes = { [url.urn] = self.size } }) }) + end end function M:spot_base(job) @@ -74,6 +77,7 @@ function M:spot_base(job) } end + self.size = nil return ya.co(function() yield("0B (?)") @@ -94,6 +98,7 @@ function M:spot_base(job) end end + self.size = size yield(ya.readable_size(size)) end) end diff --git a/yazi-plugin/preset/plugins/multi.lua b/yazi-plugin/preset/plugins/multi.lua index 1c3f3b5c..9951140f 100644 --- a/yazi-plugin/preset/plugins/multi.lua +++ b/yazi-plugin/preset/plugins/multi.lua @@ -45,7 +45,7 @@ function M:spot_base(_, selected) while it do local next, now = it:recv(), ya.time() if not next then - self.sizes[url] = it.cha.is_dir and size + self.sizes[url] = it.cha.is_dir and size or nil break elseif now >= last + 0.1 then last, size, sum = now, size + next, sum + next diff --git a/yazi-plugin/src/utils/sync.rs b/yazi-plugin/src/utils/sync.rs index 47cf1e65..d6b7ed54 100644 --- a/yazi-plugin/src/utils/sync.rs +++ b/yazi-plugin/src/utils/sync.rs @@ -15,15 +15,15 @@ impl Utils { pub(super) fn co(lua: &Lua) -> mlua::Result { lua.create_function(|lua, f: Function| { let thread = lua.create_thread(f)?; - lua.create_async_function(move |lua, args: MultiValue| { + lua.create_async_function(move |lua, mut args: MultiValue| { let thread = thread.clone(); async move { loop { - let values: MultiValue = thread.resume(&args)?; + let values: MultiValue = thread.resume(args)?; if let Some(Value::LightUserData(ud)) = values.get(0) && *ud == Lua::poll_pending() { - lua.yield_with::<()>(values).await?; + args = lua.yield_with(values).await?; } else { return Ok(values); }