WIP: remove cursor_at

This commit is contained in:
sxyazi 2024-01-15 18:02:29 +08:00
parent 3879e228e9
commit 9bd7b52697
No known key found for this signature in database
4 changed files with 16 additions and 16 deletions

View file

@ -5,11 +5,11 @@ use crate::{INPUT, SELECT};
pub struct InputCfg { pub struct InputCfg {
pub title: String, pub title: String,
pub value: String, pub value: String,
pub cursor: Option<usize>,
pub position: Position, pub position: Position,
pub realtime: bool, pub realtime: bool,
pub completion: bool, pub completion: bool,
pub highlight: bool, pub highlight: bool,
pub cursor_at: Option<usize>,
} }
#[derive(Default)] #[derive(Default)]
@ -133,8 +133,8 @@ impl InputCfg {
} }
#[inline] #[inline]
pub fn with_cursor_at(mut self, cursor_at: Option<usize>) -> Self { pub fn with_cursor(mut self, cursor: usize) -> Self {
self.cursor_at = cursor_at; self.cursor = Some(cursor);
self self
} }
} }

View file

@ -41,7 +41,13 @@ impl Input {
self.highlight = opt.cfg.highlight; self.highlight = opt.cfg.highlight;
// Reset snaps // 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!(); render!();
} }
} }

View file

@ -11,15 +11,11 @@ pub(super) struct InputSnaps {
impl InputSnaps { impl InputSnaps {
#[inline] #[inline]
pub(super) fn reset(&mut self, value: String, limit: usize, cursor_at: Option<usize>) { pub(super) fn reset(&mut self, value: String, limit: usize) {
self.idx = 0; self.idx = 0;
self.versions.clear(); self.versions.clear();
self.versions.push(InputSnap::new(value, limit)); self.versions.push(InputSnap::new(value, limit));
self.current = self.versions[0].clone(); 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 { pub(super) fn tag(&mut self, limit: usize) -> bool {

View file

@ -10,16 +10,16 @@ use yazi_shared::{event::Exec, fs::{max_common_root, File, FilesOp, Url}, term::
use crate::{input::Input, manager::Manager}; use crate::{input::Input, manager::Manager};
pub struct Opt { pub struct Opt {
force: bool, force: bool,
replace: bool, replace: bool,
keep_ext: bool, keep_ext: bool,
} }
impl From<&Exec> for Opt { impl From<&Exec> for Opt {
fn from(e: &Exec) -> Self { fn from(e: &Exec) -> Self {
Self { Self {
force: e.named.contains_key("force"), force: e.named.contains_key("force"),
replace: e.named.contains_key("replace"), replace: e.named.contains_key("replace"),
keep_ext: e.named.contains_key("keep-ext"), keep_ext: e.named.contains_key("keep-ext"),
} }
} }
@ -60,9 +60,7 @@ impl Manager {
(opt.replace.then(|| "").unwrap_or(&full_name).into(), None) (opt.replace.then(|| "").unwrap_or(&full_name).into(), None)
}; };
let mut result = let mut result = Input::_show(InputCfg::rename().with_value(initial_value));
Input::_show(InputCfg::rename().with_value(initial_value).with_cursor_at(cursor_start));
let Some(Ok(name)) = result.recv().await else { let Some(Ok(name)) = result.recv().await else {
return; return;
}; };