From a4a869464a85fa54af0ee15d646c95cbd314d854 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Wed, 19 Mar 2025 21:25:38 +0800 Subject: [PATCH] .. --- yazi-config/src/popup/input.rs | 2 +- yazi-core/src/input/commands/close.rs | 4 ++-- yazi-core/src/input/commands/show.rs | 17 ++++++++++------- yazi-widgets/src/input/input.rs | 6 ++++-- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/yazi-config/src/popup/input.rs b/yazi-config/src/popup/input.rs index f2c05c37..71c87ba0 100644 --- a/yazi-config/src/popup/input.rs +++ b/yazi-config/src/popup/input.rs @@ -46,7 +46,7 @@ pub struct Input { } impl Input { - pub const fn border(&self) -> u16 { 2 } + pub const fn border(&self) -> u16 { 1 } } impl FromStr for Input { diff --git a/yazi-core/src/input/commands/close.rs b/yazi-core/src/input/commands/close.rs index d792e8d2..816c012f 100644 --- a/yazi-core/src/input/commands/close.rs +++ b/yazi-core/src/input/commands/close.rs @@ -21,9 +21,9 @@ impl Input { self.visible = false; self.ticket.next(); - if let Some(cb) = self.tx.take() { + if let Some(tx) = self.tx.take() { let value = self.snap().value.clone(); - _ = cb.send(if opt.submit { Ok(value) } else { Err(InputError::Canceled(value)) }); + _ = tx.send(if opt.submit { Ok(value) } else { Err(InputError::Canceled(value)) }); } CmpProxy::close(); diff --git a/yazi-core/src/input/commands/show.rs b/yazi-core/src/input/commands/show.rs index a13ff121..0c3ea1f2 100644 --- a/yazi-core/src/input/commands/show.rs +++ b/yazi-core/src/input/commands/show.rs @@ -1,7 +1,8 @@ use tokio::sync::mpsc; -use yazi_config::popup::InputCfg; +use yazi_config::{INPUT, popup::InputCfg}; use yazi_macro::render; use yazi_shared::{errors::InputError, event::CmdCow}; +use yazi_widgets::input::InputCallback; use crate::input::Input; @@ -29,22 +30,24 @@ impl Input { // Typing self.tx = Some(opt.tx.clone()); + let ticket = self.ticket.clone(); // Shell self.highlight = opt.cfg.highlight; // Reset input - let ticket = self.ticket.clone(); - let cb: Box = Box::new(move |before, after| { + let cb: InputCallback = Box::new(move |before, after| { if opt.cfg.realtime { opt.tx.send(Err(InputError::Typed(format!("{before}{after}")))).ok(); - } - - if opt.cfg.completion { + } else if opt.cfg.completion { opt.tx.send(Err(InputError::Completed(before.to_owned(), ticket.current()))).ok(); } }); - self.inner = yazi_widgets::input::Input::new(opt.cfg.value, self.limit, cb); + self.inner = yazi_widgets::input::Input::new( + opt.cfg.value, + opt.cfg.position.offset.width.saturating_sub(INPUT.border()) as usize, + cb, + ); // Set cursor after reset // TODO: remove this diff --git a/yazi-widgets/src/input/input.rs b/yazi-widgets/src/input/input.rs index 63308f09..77a5943b 100644 --- a/yazi-widgets/src/input/input.rs +++ b/yazi-widgets/src/input/input.rs @@ -5,15 +5,17 @@ use yazi_plugin::CLIPBOARD; use super::{InputSnap, InputSnaps, mode::InputMode, op::InputOp}; +pub type InputCallback = Box; + #[derive(Default)] pub struct Input { pub snaps: InputSnaps, pub limit: usize, - pub callback: Option>, + pub callback: Option, } impl Input { - pub fn new(value: String, limit: usize, callback: Box) -> Self { + pub fn new(value: String, limit: usize, callback: InputCallback) -> Self { Self { snaps: InputSnaps::new(value, limit), limit, callback: Some(callback) } }