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 title: String,
pub value: String,
pub cursor: Option<usize>,
pub position: Position,
pub realtime: bool,
pub completion: bool,
pub highlight: bool,
pub cursor_at: Option<usize>,
}
#[derive(Default)]
@ -133,8 +133,8 @@ impl InputCfg {
}
#[inline]
pub fn with_cursor_at(mut self, cursor_at: Option<usize>) -> Self {
self.cursor_at = cursor_at;
pub fn with_cursor(mut self, cursor: usize) -> Self {
self.cursor = Some(cursor);
self
}
}

View file

@ -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!();
}
}

View file

@ -11,15 +11,11 @@ pub(super) struct InputSnaps {
impl InputSnaps {
#[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.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 {

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};
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;
};