diff --git a/yazi-core/src/input/commands/insert.rs b/yazi-core/src/input/commands/insert.rs index 4e1c8758..ba7b87f0 100644 --- a/yazi-core/src/input/commands/insert.rs +++ b/yazi-core/src/input/commands/insert.rs @@ -1,6 +1,6 @@ use yazi_config::keymap::Exec; -use crate::input::Input; +use crate::input::{op::InputOp, Input, InputMode}; pub struct Opt { append: bool, @@ -15,7 +15,11 @@ impl From for Opt { impl Input { pub fn insert(&mut self, opt: impl Into) -> bool { - if !self.snap_mut().insert() { + let snap = self.snap_mut(); + if snap.mode == InputMode::Normal { + snap.op = InputOp::None; + snap.mode = InputMode::Insert; + } else { return false; } diff --git a/yazi-core/src/input/commands/visual.rs b/yazi-core/src/input/commands/visual.rs index 509dc084..81d1d7c0 100644 --- a/yazi-core/src/input/commands/visual.rs +++ b/yazi-core/src/input/commands/visual.rs @@ -1,6 +1,6 @@ use yazi_config::keymap::Exec; -use crate::input::Input; +use crate::input::{op::InputOp, Input, InputMode}; pub struct Opt; @@ -10,5 +10,15 @@ impl From<&Exec> for Opt { impl Input { #[inline] - pub fn visual(&mut self, _: impl Into) -> bool { self.snap_mut().visual() } + pub fn visual(&mut self, _: impl Into) -> bool { + let snap = self.snap_mut(); + if snap.mode != InputMode::Normal { + return false; + } else if snap.value.is_empty() { + return false; + } + + snap.op = InputOp::Select(snap.cursor); + true + } } diff --git a/yazi-core/src/input/snap.rs b/yazi-core/src/input/snap.rs index a5a9b510..21c06f2d 100644 --- a/yazi-core/src/input/snap.rs +++ b/yazi-core/src/input/snap.rs @@ -36,27 +36,6 @@ impl InputSnap { self.offset = self.offset.min(self.cursor.saturating_sub(Self::find_window(&self.rev(), 0).end)); } - - pub(super) fn insert(&mut self) -> bool { - if self.mode != InputMode::Normal { - return false; - } - - self.op = InputOp::None; - self.mode = InputMode::Insert; - true - } - - pub fn visual(&mut self) -> bool { - if self.mode != InputMode::Normal { - return false; - } else if self.value.is_empty() { - return false; - } - - self.op = InputOp::Select(self.cursor); - true - } } impl InputSnap { diff --git a/yazi-core/src/input/snaps.rs b/yazi-core/src/input/snaps.rs index 0dc203df..f1721c0b 100644 --- a/yazi-core/src/input/snaps.rs +++ b/yazi-core/src/input/snaps.rs @@ -39,7 +39,15 @@ impl InputSnaps { } pub(super) fn tag(&mut self) -> bool { - self.catch(); + // Sync *current* cursor position to the *last* version: + // Save offset/cursor/ect. of the *current* as the last version, + // while keeping the *last* value unchanged. + let value = mem::take(&mut self.versions[self.idx].value); + self.versions[self.idx] = self.current.clone(); + self.versions[self.idx].value = value; + self.versions[self.idx].reset(); + + // If the *current* value is the same as the *last* version if self.versions[self.idx].value == self.current.value { return false; } @@ -49,14 +57,6 @@ impl InputSnaps { self.idx += 1; true } - - #[inline] - pub(super) fn catch(&mut self) { - let value = mem::take(&mut self.versions[self.idx].value); - self.versions[self.idx] = self.current.clone(); - self.versions[self.idx].value = value; - self.versions[self.idx].reset(); - } } impl InputSnaps {