This commit is contained in:
sxyazi 2025-03-19 21:25:38 +08:00
parent 5cddad4e53
commit a4a869464a
No known key found for this signature in database
4 changed files with 17 additions and 12 deletions

View file

@ -46,7 +46,7 @@ pub struct Input {
} }
impl Input { impl Input {
pub const fn border(&self) -> u16 { 2 } pub const fn border(&self) -> u16 { 1 }
} }
impl FromStr for Input { impl FromStr for Input {

View file

@ -21,9 +21,9 @@ impl Input {
self.visible = false; self.visible = false;
self.ticket.next(); self.ticket.next();
if let Some(cb) = self.tx.take() { if let Some(tx) = self.tx.take() {
let value = self.snap().value.clone(); 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(); CmpProxy::close();

View file

@ -1,7 +1,8 @@
use tokio::sync::mpsc; use tokio::sync::mpsc;
use yazi_config::popup::InputCfg; use yazi_config::{INPUT, popup::InputCfg};
use yazi_macro::render; use yazi_macro::render;
use yazi_shared::{errors::InputError, event::CmdCow}; use yazi_shared::{errors::InputError, event::CmdCow};
use yazi_widgets::input::InputCallback;
use crate::input::Input; use crate::input::Input;
@ -29,22 +30,24 @@ impl Input {
// Typing // Typing
self.tx = Some(opt.tx.clone()); self.tx = Some(opt.tx.clone());
let ticket = self.ticket.clone();
// Shell // Shell
self.highlight = opt.cfg.highlight; self.highlight = opt.cfg.highlight;
// Reset input // Reset input
let ticket = self.ticket.clone(); let cb: InputCallback = Box::new(move |before, after| {
let cb: Box<dyn Fn(&str, &str)> = Box::new(move |before, after| {
if opt.cfg.realtime { if opt.cfg.realtime {
opt.tx.send(Err(InputError::Typed(format!("{before}{after}")))).ok(); opt.tx.send(Err(InputError::Typed(format!("{before}{after}")))).ok();
} } else if opt.cfg.completion {
if opt.cfg.completion {
opt.tx.send(Err(InputError::Completed(before.to_owned(), ticket.current()))).ok(); 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 // Set cursor after reset
// TODO: remove this // TODO: remove this

View file

@ -5,15 +5,17 @@ use yazi_plugin::CLIPBOARD;
use super::{InputSnap, InputSnaps, mode::InputMode, op::InputOp}; use super::{InputSnap, InputSnaps, mode::InputMode, op::InputOp};
pub type InputCallback = Box<dyn Fn(&str, &str)>;
#[derive(Default)] #[derive(Default)]
pub struct Input { pub struct Input {
pub snaps: InputSnaps, pub snaps: InputSnaps,
pub limit: usize, pub limit: usize,
pub callback: Option<Box<dyn Fn(&str, &str)>>, pub callback: Option<InputCallback>,
} }
impl Input { impl Input {
pub fn new(value: String, limit: usize, callback: Box<dyn Fn(&str, &str)>) -> Self { pub fn new(value: String, limit: usize, callback: InputCallback) -> Self {
Self { snaps: InputSnaps::new(value, limit), limit, callback: Some(callback) } Self { snaps: InputSnaps::new(value, limit), limit, callback: Some(callback) }
} }