Add changes for undo in insert mode (#11090)

* Add changes before insert mode undo
Fixes #11077

* Address edge cases for undo like Kakoune does

---------

Co-authored-by: Kaniel Kirby <pirate7007@runbox.com>
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
This commit is contained in:
kanielrkirby 2024-07-09 22:38:50 -05:00 committed by GitHub
parent 71df2428ee
commit 86e4b51416
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1410,6 +1410,11 @@ impl Document {
}
fn undo_redo_impl(&mut self, view: &mut View, undo: bool) -> bool {
if undo {
self.append_changes_to_history(view);
} else if !self.changes.is_empty() {
return false;
}
let mut history = self.history.take();
let txn = if undo { history.undo() } else { history.redo() };
let success = if let Some(txn) = txn {
@ -1490,6 +1495,11 @@ impl Document {
}
fn earlier_later_impl(&mut self, view: &mut View, uk: UndoKind, earlier: bool) -> bool {
if earlier {
self.append_changes_to_history(view);
} else if !self.changes.is_empty() {
return false;
}
let txns = if earlier {
self.history.get_mut().earlier(uk)
} else {