From 2770e0259cc83d91b7877b412a27db2dcb1c9427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20=C2=B7=20Misaki=20Masa?= Date: Sat, 28 Dec 2024 00:58:54 +0800 Subject: [PATCH] fix: don't check if has a hovered file in advance, only do so when `--hovered` is explicitly specified (#2105) --- yazi-core/src/manager/commands/remove.rs | 9 ++++----- yazi-core/src/manager/commands/rename.rs | 7 +++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/yazi-core/src/manager/commands/remove.rs b/yazi-core/src/manager/commands/remove.rs index 8a391710e..a59c6ca63 100644 --- a/yazi-core/src/manager/commands/remove.rs +++ b/yazi-core/src/manager/commands/remove.rs @@ -28,17 +28,16 @@ impl Manager { if !self.active_mut().try_escape_visual() { return; } - let Some(hovered) = self.hovered().map(|h| &h.url) else { - return; - }; opt.targets = if opt.hovered { - vec![hovered.clone()] + self.hovered().map_or(vec![], |h| vec![h.url.clone()]) } else { self.selected_or_hovered(true).cloned().collect() }; - if opt.force { + if opt.targets.is_empty() { + return; + } else if opt.force { return self.remove_do(opt, tasks); } diff --git a/yazi-core/src/manager/commands/rename.rs b/yazi-core/src/manager/commands/rename.rs index c43c9153e..c8da01573 100644 --- a/yazi-core/src/manager/commands/rename.rs +++ b/yazi-core/src/manager/commands/rename.rs @@ -33,15 +33,14 @@ impl Manager { pub fn rename(&mut self, opt: Opt) { if !self.active_mut().try_escape_visual() { return; + } else if !opt.hovered && !self.active().selected.is_empty() { + return self.bulk_rename(); } + let Some(hovered) = self.hovered().map(|h| h.url_owned()) else { return; }; - if !opt.hovered && !self.active().selected.is_empty() { - return self.bulk_rename(); - } - let name = Self::empty_url_part(&hovered, &opt.empty); let cursor = match opt.cursor.as_ref() { "start" => Some(0),