mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
refactor: remove unnecessary code
This commit is contained in:
parent
027c7a79c1
commit
ab7acfec5c
4 changed files with 27 additions and 34 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_config::keymap::Exec;
|
||||||
|
|
||||||
use crate::input::Input;
|
use crate::input::{op::InputOp, Input, InputMode};
|
||||||
|
|
||||||
pub struct Opt {
|
pub struct Opt {
|
||||||
append: bool,
|
append: bool,
|
||||||
|
|
@ -15,7 +15,11 @@ impl From<bool> for Opt {
|
||||||
|
|
||||||
impl Input {
|
impl Input {
|
||||||
pub fn insert(&mut self, opt: impl Into<Opt>) -> bool {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_config::keymap::Exec;
|
||||||
|
|
||||||
use crate::input::Input;
|
use crate::input::{op::InputOp, Input, InputMode};
|
||||||
|
|
||||||
pub struct Opt;
|
pub struct Opt;
|
||||||
|
|
||||||
|
|
@ -10,5 +10,15 @@ impl From<&Exec> for Opt {
|
||||||
|
|
||||||
impl Input {
|
impl Input {
|
||||||
#[inline]
|
#[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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,27 +36,6 @@ impl InputSnap {
|
||||||
self.offset =
|
self.offset =
|
||||||
self.offset.min(self.cursor.saturating_sub(Self::find_window(&self.rev(), 0).end));
|
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 {
|
impl InputSnap {
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,15 @@ impl InputSnaps {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn tag(&mut self) -> bool {
|
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 {
|
if self.versions[self.idx].value == self.current.value {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -49,14 +57,6 @@ impl InputSnaps {
|
||||||
self.idx += 1;
|
self.idx += 1;
|
||||||
true
|
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 {
|
impl InputSnaps {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue