From 9bd7b52697c6b4b86eeac48b943c47e62e517840 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Mon, 15 Jan 2024 18:02:29 +0800 Subject: [PATCH] WIP: remove `cursor_at` --- yazi-config/src/popup/options.rs | 6 +++--- yazi-core/src/input/commands/show.rs | 8 +++++++- yazi-core/src/input/snaps.rs | 6 +----- yazi-core/src/manager/commands/rename.rs | 12 +++++------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/yazi-config/src/popup/options.rs b/yazi-config/src/popup/options.rs index b96050ad..8383ae0d 100644 --- a/yazi-config/src/popup/options.rs +++ b/yazi-config/src/popup/options.rs @@ -5,11 +5,11 @@ use crate::{INPUT, SELECT}; pub struct InputCfg { pub title: String, pub value: String, + pub cursor: Option, pub position: Position, pub realtime: bool, pub completion: bool, pub highlight: bool, - pub cursor_at: Option, } #[derive(Default)] @@ -133,8 +133,8 @@ impl InputCfg { } #[inline] - pub fn with_cursor_at(mut self, cursor_at: Option) -> Self { - self.cursor_at = cursor_at; + pub fn with_cursor(mut self, cursor: usize) -> Self { + self.cursor = Some(cursor); self } } diff --git a/yazi-core/src/input/commands/show.rs b/yazi-core/src/input/commands/show.rs index 946482ad..cdb3b87b 100644 --- a/yazi-core/src/input/commands/show.rs +++ b/yazi-core/src/input/commands/show.rs @@ -41,7 +41,13 @@ impl Input { self.highlight = opt.cfg.highlight; // Reset snaps - self.snaps.reset(opt.cfg.value, self.limit(), opt.cfg.cursor_at); + self.snaps.reset(opt.cfg.value, self.limit()); + + // Set cursor after reset + if let Some(cursor) = opt.cfg.cursor { + self.snaps.current_mut().cursor = cursor; + } + render!(); } } diff --git a/yazi-core/src/input/snaps.rs b/yazi-core/src/input/snaps.rs index 04fc4ef0..14b8b444 100644 --- a/yazi-core/src/input/snaps.rs +++ b/yazi-core/src/input/snaps.rs @@ -11,15 +11,11 @@ pub(super) struct InputSnaps { impl InputSnaps { #[inline] - pub(super) fn reset(&mut self, value: String, limit: usize, cursor_at: Option) { + pub(super) fn reset(&mut self, value: String, limit: usize) { self.idx = 0; self.versions.clear(); self.versions.push(InputSnap::new(value, limit)); self.current = self.versions[0].clone(); - - if let Some(cursor) = cursor_at { - self.current.cursor = cursor; - } } pub(super) fn tag(&mut self, limit: usize) -> bool { diff --git a/yazi-core/src/manager/commands/rename.rs b/yazi-core/src/manager/commands/rename.rs index 4581671c..ed5640f8 100644 --- a/yazi-core/src/manager/commands/rename.rs +++ b/yazi-core/src/manager/commands/rename.rs @@ -10,16 +10,16 @@ use yazi_shared::{event::Exec, fs::{max_common_root, File, FilesOp, Url}, term:: use crate::{input::Input, manager::Manager}; pub struct Opt { - force: bool, - replace: bool, + force: bool, + replace: bool, keep_ext: bool, } impl From<&Exec> for Opt { fn from(e: &Exec) -> Self { Self { - force: e.named.contains_key("force"), - replace: e.named.contains_key("replace"), + force: e.named.contains_key("force"), + replace: e.named.contains_key("replace"), keep_ext: e.named.contains_key("keep-ext"), } } @@ -60,9 +60,7 @@ impl Manager { (opt.replace.then(|| "").unwrap_or(&full_name).into(), None) }; - let mut result = - Input::_show(InputCfg::rename().with_value(initial_value).with_cursor_at(cursor_start)); - + let mut result = Input::_show(InputCfg::rename().with_value(initial_value)); let Some(Ok(name)) = result.recv().await else { return; };