From 6c226065b7f95f8fff439ea8240cb3578e49060d Mon Sep 17 00:00:00 2001 From: sxyazi Date: Tue, 12 May 2026 00:53:14 +0800 Subject: [PATCH] Refactor --- yazi-actor/src/mgr/bulk_rename.rs | 2 +- yazi-config/preset/keymap-default.toml | 4 ++-- yazi-config/preset/yazi-default.toml | 4 ++-- yazi-fm/src/executor.rs | 2 +- yazi-fs/src/op.rs | 12 ++++++++++++ yazi-shim/src/lib.rs | 2 +- yazi-shim/src/path/mod.rs | 1 + yazi-shim/src/path/separator.rs | 5 +++++ yazi-widgets/src/input/actor/complete.rs | 9 +++++---- yazi-widgets/src/input/input.rs | 5 +++-- yazi-widgets/src/input/mod.rs | 2 +- yazi-widgets/src/input/separator.rs | 5 ----- 12 files changed, 34 insertions(+), 19 deletions(-) create mode 100644 yazi-shim/src/path/mod.rs create mode 100644 yazi-shim/src/path/separator.rs delete mode 100644 yazi-widgets/src/input/separator.rs diff --git a/yazi-actor/src/mgr/bulk_rename.rs b/yazi-actor/src/mgr/bulk_rename.rs index 0e46be3d..9e48fe82 100644 --- a/yazi-actor/src/mgr/bulk_rename.rs +++ b/yazi-actor/src/mgr/bulk_rename.rs @@ -45,7 +45,7 @@ impl Actor for BulkRename { let cwd = cx.cwd().clone(); let batcher = cx.core.mgr.batcher.clone(); tokio::spawn(async move { - let tmp = YAZI.preview.tmpfile("bulk"); + let tmp = YAZI.preview.tmpfile("bulk-rename"); Gate::default() .write(true) diff --git a/yazi-config/preset/keymap-default.toml b/yazi-config/preset/keymap-default.toml index ca8ac7aa..7d621ec0 100644 --- a/yazi-config/preset/keymap-default.toml +++ b/yazi-config/preset/keymap-default.toml @@ -1,5 +1,5 @@ -# A TOML linter such as https://github.com/tombi-toml/tombi can use this schema to validate your config. -# If you encounter any problems, please make an issue at https://github.com/yazi-rs/schemas. +# A TOML linter such as Tombi can use this schema to validate your config. +# If you encounter any problems, please file an issue at https://github.com/yazi-rs/schemas. #:schema https://yazi-rs.github.io/schemas/keymap.json diff --git a/yazi-config/preset/yazi-default.toml b/yazi-config/preset/yazi-default.toml index 80e9726f..1fc65c7f 100644 --- a/yazi-config/preset/yazi-default.toml +++ b/yazi-config/preset/yazi-default.toml @@ -1,5 +1,5 @@ -# A TOML linter such as https://github.com/tombi-toml/tombi can use this schema to validate your config. -# If you encounter any issues, please make an issue at https://github.com/yazi-rs/schemas. +# A TOML linter such as Tombi can use this schema to validate your config. +# If you encounter any problems, please file an issue at https://github.com/yazi-rs/schemas. #:schema https://yazi-rs.github.io/schemas/yazi.json diff --git a/yazi-fm/src/executor.rs b/yazi-fm/src/executor.rs index 33007da0..3a8c461f 100644 --- a/yazi-fm/src/executor.rs +++ b/yazi-fm/src/executor.rs @@ -122,7 +122,6 @@ impl<'a> Executor<'a> { on!(hardlink); on!(remove); on!(remove_do); - on!(bulk_create); on!(create); on!(rename); on!(copy); @@ -133,6 +132,7 @@ impl<'a> Executor<'a> { on!(search_do); on!(bulk_exit); on!(bulk_rename); + on!(bulk_create); // Filter on!(filter); diff --git a/yazi-fs/src/op.rs b/yazi-fs/src/op.rs index 779f2ae7..ad4eb92e 100644 --- a/yazi-fs/src/op.rs +++ b/yazi-fs/src/op.rs @@ -51,6 +51,18 @@ impl FilesOp { ticket } + pub fn create(files: Vec) { + let mut parents: HashMap> = Default::default(); + for file in files { + if let Some(p) = file.url.parent() { + parents.get_or_insert_default(p).push(file); + } + } + for (p, files) in parents { + Self::Creating(p, files).emit(); + } + } + pub fn rename(map: HashMap) { let mut parents: HashMap, HashMap<_, _>)> = Default::default(); for (o, n) in map { diff --git a/yazi-shim/src/lib.rs b/yazi-shim/src/lib.rs index db58fed4..cfabeb98 100644 --- a/yazi-shim/src/lib.rs +++ b/yazi-shim/src/lib.rs @@ -1,3 +1,3 @@ -yazi_macro::mod_pub!(arc_swap cell crossterm mlua ratatui serde strum toml vec); +yazi_macro::mod_pub!(arc_swap cell crossterm mlua path ratatui serde strum toml vec); yazi_macro::mod_flat!(twox); diff --git a/yazi-shim/src/path/mod.rs b/yazi-shim/src/path/mod.rs new file mode 100644 index 00000000..2122106c --- /dev/null +++ b/yazi-shim/src/path/mod.rs @@ -0,0 +1 @@ +yazi_macro::mod_flat!(separator); diff --git a/yazi-shim/src/path/separator.rs b/yazi-shim/src/path/separator.rs new file mode 100644 index 00000000..1b4fa75d --- /dev/null +++ b/yazi-shim/src/path/separator.rs @@ -0,0 +1,5 @@ +#[cfg(windows)] +pub const CROSS_SEPARATOR: [char; 2] = ['/', '\\']; + +#[cfg(not(windows))] +pub const CROSS_SEPARATOR: char = std::path::MAIN_SEPARATOR; diff --git a/yazi-widgets/src/input/actor/complete.rs b/yazi-widgets/src/input/actor/complete.rs index f07c8d0b..00884ecb 100644 --- a/yazi-widgets/src/input/actor/complete.rs +++ b/yazi-widgets/src/input/actor/complete.rs @@ -3,16 +3,17 @@ use std::path::MAIN_SEPARATOR_STR; use anyhow::Result; use yazi_macro::{act, render, succ}; use yazi_shared::data::Data; +use yazi_shim::path::CROSS_SEPARATOR; -use crate::input::{Input, SEPARATOR, parser::CompleteOpt}; +use crate::input::{Input, parser::CompleteOpt}; impl Input { pub fn complete(&mut self, opt: CompleteOpt) -> Result { let (before, after) = self.partition(); - let new = if let Some((prefix, _)) = before.rsplit_once(SEPARATOR) { - format!("{prefix}/{}{after}", opt.completable()).replace(SEPARATOR, MAIN_SEPARATOR_STR) + let new = if let Some((prefix, _)) = before.rsplit_once(CROSS_SEPARATOR) { + format!("{prefix}/{}{after}", opt.completable()).replace(CROSS_SEPARATOR, MAIN_SEPARATOR_STR) } else { - format!("{}{after}", opt.completable()).replace(SEPARATOR, MAIN_SEPARATOR_STR) + format!("{}{after}", opt.completable()).replace(CROSS_SEPARATOR, MAIN_SEPARATOR_STR) }; let snap = self.snap_mut(); diff --git a/yazi-widgets/src/input/input.rs b/yazi-widgets/src/input/input.rs index d62edd0f..936fbda6 100644 --- a/yazi-widgets/src/input/input.rs +++ b/yazi-widgets/src/input/input.rs @@ -6,9 +6,10 @@ use tokio::sync::mpsc; use yazi_config::YAZI; use yazi_macro::act; use yazi_shared::Ids; +use yazi_shim::path::CROSS_SEPARATOR; use super::{InputSnap, InputSnaps, mode::InputMode, op::InputOp}; -use crate::{CLIPBOARD, input::{InputEvent, InputOpt, SEPARATOR}}; +use crate::{CLIPBOARD, input::{InputEvent, InputOpt}}; #[derive(Default)] pub struct Input { @@ -152,7 +153,7 @@ impl Input { let snap = self.snap(); let idx = snap.idx(snap.cursor).unwrap(); - if let Some(sep) = snap.value[idx..].find(SEPARATOR).map(|i| idx + i) { + if let Some(sep) = snap.value[idx..].find(CROSS_SEPARATOR).map(|i| idx + i) { (&snap.value[..sep], &snap.value[sep + 1..]) } else { (&snap.value, "") diff --git a/yazi-widgets/src/input/mod.rs b/yazi-widgets/src/input/mod.rs index 67838f22..dde2b4e8 100644 --- a/yazi-widgets/src/input/mod.rs +++ b/yazi-widgets/src/input/mod.rs @@ -1,3 +1,3 @@ yazi_macro::mod_pub!(actor parser); -yazi_macro::mod_flat!(event input mode op option separator snap snaps widget); +yazi_macro::mod_flat!(event input mode op option snap snaps widget); diff --git a/yazi-widgets/src/input/separator.rs b/yazi-widgets/src/input/separator.rs deleted file mode 100644 index 07e410a1..00000000 --- a/yazi-widgets/src/input/separator.rs +++ /dev/null @@ -1,5 +0,0 @@ -#[cfg(windows)] -pub(super) const SEPARATOR: [char; 2] = ['/', '\\']; - -#[cfg(not(windows))] -pub(super) const SEPARATOR: char = std::path::MAIN_SEPARATOR;