refactor: remove unnecessary code

This commit is contained in:
sxyazi 2023-11-17 09:17:30 +08:00
parent 027c7a79c1
commit ab7acfec5c
No known key found for this signature in database
4 changed files with 27 additions and 34 deletions

View file

@ -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<bool> for Opt {
impl Input {
pub fn insert(&mut self, opt: impl Into<Opt>) -> 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;
}

View file

@ -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<Opt>) -> bool { self.snap_mut().visual() }
pub fn visual(&mut self, _: impl Into<Opt>) -> 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
}
}

View file

@ -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 {

View file

@ -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 {