From 219a17eb9406978912e876b671799132a4a4a097 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Wed, 21 Aug 2024 21:32:15 +0800 Subject: [PATCH] Rebase --- yazi-core/src/lib.rs | 1 + yazi-core/src/manager/commands/remove.rs | 18 +++++++----------- yazi-core/src/manager/commands/rename.rs | 18 ++++++------------ yazi-fm/src/confirm/confirm.rs | 2 +- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/yazi-core/src/lib.rs b/yazi-core/src/lib.rs index 88bdc2b0..e8c1106d 100644 --- a/yazi-core/src/lib.rs +++ b/yazi-core/src/lib.rs @@ -7,6 +7,7 @@ )] pub mod completion; +pub mod confirm; pub mod help; pub mod input; pub mod manager; diff --git a/yazi-core/src/manager/commands/remove.rs b/yazi-core/src/manager/commands/remove.rs index e67c135d..af383722 100644 --- a/yazi-core/src/manager/commands/remove.rs +++ b/yazi-core/src/manager/commands/remove.rs @@ -1,5 +1,5 @@ -use yazi_config::popup::InputCfg; -use yazi_proxy::{InputProxy, ManagerProxy}; +use yazi_config::popup::ConfirmCfg; +use yazi_proxy::{ConfirmProxy, ManagerProxy}; use yazi_shared::{event::Cmd, fs::Url}; use crate::{manager::Manager, tasks::Tasks}; @@ -35,7 +35,7 @@ impl Manager { opt.targets = if opt.hovered { vec![hovered.clone()] } else { - self.selected_or_hovered(false).cloned().collect() + self.selected_or_hovered(true).cloned().collect() }; if opt.force { @@ -43,17 +43,13 @@ impl Manager { } tokio::spawn(async move { - let mut result = InputProxy::show(if opt.permanently { - InputCfg::delete(opt.targets.len()) + let result = ConfirmProxy::show(if opt.permanently { + ConfirmCfg::delete(&opt.targets) } else { - InputCfg::trash(opt.targets.len()) + ConfirmCfg::trash(&opt.targets) }); - if let Some(Ok(choice)) = result.recv().await { - if choice != "y" && choice != "Y" { - return; - } - + if result.await { ManagerProxy::remove_do(opt.targets, opt.permanently); } }); diff --git a/yazi-core/src/manager/commands/rename.rs b/yazi-core/src/manager/commands/rename.rs index 3fd5efc9..a15773c9 100644 --- a/yazi-core/src/manager/commands/rename.rs +++ b/yazi-core/src/manager/commands/rename.rs @@ -2,9 +2,9 @@ use std::collections::HashMap; use anyhow::Result; use tokio::fs; -use yazi_config::popup::InputCfg; +use yazi_config::popup::{ConfirmCfg, InputCfg}; use yazi_dds::Pubsub; -use yazi_proxy::{InputProxy, TabProxy, WATCHER}; +use yazi_proxy::{ConfirmProxy, InputProxy, TabProxy, WATCHER}; use yazi_shared::{event::Cmd, fs::{maybe_exists, ok_or_not_found, paths_to_same_file, symlink_realpath, File, FilesOp, Url}}; use crate::manager::Manager; @@ -64,18 +64,12 @@ impl Manager { return; } - let new = hovered.parent().unwrap().join(name); + let new = Url::from(hovered.parent().unwrap().join(name)); if opt.force || !maybe_exists(&new).await || paths_to_same_file(&hovered, &new).await { - Self::rename_do(tab, hovered, Url::from(new)).await.ok(); - return; + Self::rename_do(tab, hovered, new).await.ok(); + } else if ConfirmProxy::show(ConfirmCfg::overwrite(&new)).await { + Self::rename_do(tab, hovered, new).await.ok(); } - - let mut result = InputProxy::show(InputCfg::overwrite()); - if let Some(Ok(choice)) = result.recv().await { - if choice == "y" || choice == "Y" { - Self::rename_do(tab, hovered, Url::from(new)).await.ok(); - } - }; }); } diff --git a/yazi-fm/src/confirm/confirm.rs b/yazi-fm/src/confirm/confirm.rs index 5cbd9d17..cfeded61 100644 --- a/yazi-fm/src/confirm/confirm.rs +++ b/yazi-fm/src/confirm/confirm.rs @@ -52,7 +52,7 @@ impl<'a> Widget for Confirm<'a> { .position(confirm.offset); Scrollbar::new(ScrollbarOrientation::VerticalRight).render( - popup_layout[0].inner(&Margin { vertical: 1, horizontal: 0 }), + popup_layout[0].inner(Margin { vertical: 1, horizontal: 0 }), buf, &mut scrollbar_state, );