From 86e4b51416b6f966858522890003fa6c58451891 Mon Sep 17 00:00:00 2001 From: kanielrkirby <77940607+kanielrkirby@users.noreply.github.com> Date: Tue, 9 Jul 2024 22:38:50 -0500 Subject: [PATCH] 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 Co-authored-by: Michael Davis --- helix-view/src/document.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index a56cbc2ff..ccf2fa8c3 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -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 {