From b229c8a5e32a6c667c46448020b43bbd2c2d9097 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Sat, 6 Jan 2024 05:14:54 +0800 Subject: [PATCH] fix: `sort` and `hidden` commands should update `mime-type` for paged files promptly --- yazi-core/src/folder/folder.rs | 2 +- yazi-core/src/manager/commands/mod.rs | 2 +- yazi-core/src/manager/commands/refresh.rs | 2 +- yazi-core/src/manager/commands/update_files.rs | 2 +- .../commands/{update_pages.rs => update_paged.rs} | 10 +++++----- yazi-core/src/tab/commands/hidden.rs | 1 + yazi-core/src/tab/commands/sort.rs | 3 ++- yazi-fm/src/executor.rs | 2 +- 8 files changed, 13 insertions(+), 11 deletions(-) rename yazi-core/src/manager/commands/{update_pages.rs => update_paged.rs} (75%) diff --git a/yazi-core/src/folder/folder.rs b/yazi-core/src/folder/folder.rs index 3c28dd27..bbf36441 100644 --- a/yazi-core/src/folder/folder.rs +++ b/yazi-core/src/folder/folder.rs @@ -94,7 +94,7 @@ impl Folder { let new = self.cursor / limit; if mem::replace(&mut self.page, new) != new || force { - Manager::_update_pages_by(new, &self.cwd); + Manager::_update_paged_by(new, &self.cwd); } } diff --git a/yazi-core/src/manager/commands/mod.rs b/yazi-core/src/manager/commands/mod.rs index 7966ee2d..e6e4c093 100644 --- a/yazi-core/src/manager/commands/mod.rs +++ b/yazi-core/src/manager/commands/mod.rs @@ -17,5 +17,5 @@ mod tab_swap; mod tab_switch; mod update_files; mod update_mimetype; -mod update_pages; +mod update_paged; mod yank; diff --git a/yazi-core/src/manager/commands/refresh.rs b/yazi-core/src/manager/commands/refresh.rs index ab455d2f..1702e6cf 100644 --- a/yazi-core/src/manager/commands/refresh.rs +++ b/yazi-core/src/manager/commands/refresh.rs @@ -23,6 +23,6 @@ impl Manager { } self.hover(None); - self.update_pages((), tasks); + self.update_paged((), tasks); } } diff --git a/yazi-core/src/manager/commands/update_files.rs b/yazi-core/src/manager/commands/update_files.rs index 7a7aafce..37b01e2a 100644 --- a/yazi-core/src/manager/commands/update_files.rs +++ b/yazi-core/src/manager/commands/update_files.rs @@ -34,7 +34,7 @@ impl Manager { if self.current_mut().update(op) { self.current_mut().repos(hovered.as_ref()); Self::_hover(None); // Re-hover in next loop - Self::_update_pages(); // Update for paged files in next loop + Self::_update_paged(); // Update for paged files in next loop } if calc { diff --git a/yazi-core/src/manager/commands/update_pages.rs b/yazi-core/src/manager/commands/update_paged.rs similarity index 75% rename from yazi-core/src/manager/commands/update_pages.rs rename to yazi-core/src/manager/commands/update_paged.rs index 12c8a413..ebb43758 100644 --- a/yazi-core/src/manager/commands/update_pages.rs +++ b/yazi-core/src/manager/commands/update_paged.rs @@ -23,19 +23,19 @@ impl From<()> for Opt { impl Manager { #[inline] - pub fn _update_pages() { - emit!(Call(Exec::call("update_pages", vec![]).vec(), Layer::Manager)); + pub fn _update_paged() { + emit!(Call(Exec::call("update_paged", vec![]).vec(), Layer::Manager)); } #[inline] - pub fn _update_pages_by(page: usize, only_if: &Url) { + pub fn _update_paged_by(page: usize, only_if: &Url) { emit!(Call( - Exec::call("update_pages", vec![page.to_string()]).with("only-if", only_if.to_string()).vec(), + Exec::call("update_paged", vec![page.to_string()]).with("only-if", only_if.to_string()).vec(), Layer::Manager )); } - pub fn update_pages(&mut self, opt: impl TryInto, tasks: &Tasks) { + pub fn update_paged(&mut self, opt: impl TryInto, tasks: &Tasks) { let Ok(opt) = opt.try_into() else { return; }; diff --git a/yazi-core/src/tab/commands/hidden.rs b/yazi-core/src/tab/commands/hidden.rs index b3fa7df6..8dd8f6e5 100644 --- a/yazi-core/src/tab/commands/hidden.rs +++ b/yazi-core/src/tab/commands/hidden.rs @@ -18,5 +18,6 @@ impl Tab { } else if self.current.hovered().is_some_and(|f| f.is_dir()) { Manager::_peek(true); } + Manager::_update_paged(); } } diff --git a/yazi-core/src/tab/commands/sort.rs b/yazi-core/src/tab/commands/sort.rs index 20dbd96c..fdf0b270 100644 --- a/yazi-core/src/tab/commands/sort.rs +++ b/yazi-core/src/tab/commands/sort.rs @@ -3,7 +3,7 @@ use std::str::FromStr; use yazi_config::manager::SortBy; use yazi_shared::event::Exec; -use crate::tab::Tab; +use crate::{manager::Manager, tab::Tab}; impl Tab { pub fn sort(&mut self, e: &Exec) { @@ -15,5 +15,6 @@ impl Tab { self.conf.sort_dir_first = e.named.contains_key("dir-first"); self.apply_files_attrs(); + Manager::_update_paged(); } } diff --git a/yazi-fm/src/executor.rs b/yazi-fm/src/executor.rs index a569b5c1..bd367ef9 100644 --- a/yazi-fm/src/executor.rs +++ b/yazi-fm/src/executor.rs @@ -108,7 +108,7 @@ impl<'a> Executor<'a> { on!(MANAGER, update_files, &self.app.cx.tasks); on!(MANAGER, update_mimetype, &self.app.cx.tasks); - on!(MANAGER, update_pages, &self.app.cx.tasks); + on!(MANAGER, update_paged, &self.app.cx.tasks); on!(MANAGER, hover); on!(MANAGER, peek); on!(MANAGER, seek);