From ed46456f8c9e9796bfe8fc3e651a54916e80f900 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Fri, 9 Feb 2024 12:37:46 +0800 Subject: [PATCH] feat: merge wildcard preloader and previewer rules via `append_preloaders` and `append_previewers` --- yazi-config/src/pattern.rs | 3 +++ yazi-config/src/plugin/plugin.rs | 7 +++++++ yazi-core/src/tasks/commands/cancel.rs | 4 ++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/yazi-config/src/pattern.rs b/yazi-config/src/pattern.rs index a171d758..3a428dbf 100644 --- a/yazi-config/src/pattern.rs +++ b/yazi-config/src/pattern.rs @@ -35,6 +35,9 @@ impl Pattern { path.file_name().map_or_else(|| path.to_string_lossy(), |n| n.to_string_lossy()) }) } + + #[inline] + pub fn is_wildcard(&self) -> bool { self.inner.as_str() == "*" || self.inner.as_str() == "*/" } } impl TryFrom<&str> for Pattern { diff --git a/yazi-config/src/plugin/plugin.rs b/yazi-config/src/plugin/plugin.rs index dc5228f0..91ae8d73 100644 --- a/yazi-config/src/plugin/plugin.rs +++ b/yazi-config/src/plugin/plugin.rs @@ -52,6 +52,13 @@ impl Default for Plugin { } let mut shadow = toml::from_str::(&MERGED_YAZI).unwrap().plugin; + if shadow.append_preloaders.iter().any(|r| r.name.as_ref().is_some_and(|p| p.is_wildcard())) { + shadow.preloaders.retain(|r| !r.name.as_ref().is_some_and(|p| p.is_wildcard())); + } + if shadow.append_previewers.iter().any(|r| r.name.as_ref().is_some_and(|p| p.is_wildcard())) { + shadow.previewers.retain(|r| !r.name.as_ref().is_some_and(|p| p.is_wildcard())); + } + Preset::mix(&mut shadow.preloaders, shadow.prepend_preloaders, shadow.append_preloaders); Preset::mix(&mut shadow.previewers, shadow.prepend_previewers, shadow.append_previewers); diff --git a/yazi-core/src/tasks/commands/cancel.rs b/yazi-core/src/tasks/commands/cancel.rs index a7e6b4fa..815b58cd 100644 --- a/yazi-core/src/tasks/commands/cancel.rs +++ b/yazi-core/src/tasks/commands/cancel.rs @@ -9,8 +9,8 @@ impl Tasks { return; } - let len = self.scheduler.running.lock().len(); - self.cursor = self.cursor.min(len.saturating_sub(1)); + self.summaries = self.paginate(); + self.arrow(0); render!(); } }