feat: restore original cursor on undoing

This commit is contained in:
sxyazi 2023-07-23 08:08:43 +08:00
parent 43e731b9a1
commit 0f76923a4d
No known key found for this signature in database
2 changed files with 24 additions and 8 deletions

View File

@ -97,19 +97,25 @@ impl Input {
}
#[inline]
pub fn visual(&mut self) -> bool {
self.snap_mut().visual();
self.escape()
}
pub fn visual(&mut self) -> bool { self.snap_mut().visual() }
#[inline]
pub fn undo(&mut self) -> bool {
self.snaps.undo();
self.escape()
if !self.snaps.undo() {
return false;
}
self.escape();
true
}
#[inline]
pub fn redo(&mut self) -> bool { self.snaps.redo() }
pub fn redo(&mut self) -> bool {
if !self.snaps.redo() {
return false;
}
self.escape();
true
}
pub fn move_(&mut self, step: isize) -> bool {
let snap = self.snap();

View File

@ -1,3 +1,5 @@
use std::mem;
use super::InputSnap;
#[derive(Default, PartialEq, Eq)]
@ -37,7 +39,8 @@ impl InputSnaps {
}
pub(super) fn tag(&mut self) -> bool {
if self.current.value == self.versions[self.idx].value {
self.catch();
if self.versions[self.idx].value == self.current.value {
return false;
}
@ -46,6 +49,13 @@ impl InputSnaps {
self.idx += 1;
true
}
#[inline]
pub(super) fn catch(&mut self) {
let value = mem::replace(&mut self.versions[self.idx].value, String::new());
self.versions[self.idx] = self.current.clone();
self.versions[self.idx].value = value;
}
}
impl InputSnaps {