From e42747e8fef36fb9f7930d2af3786cb66ff94ca1 Mon Sep 17 00:00:00 2001 From: Kaniel Kirby Date: Thu, 4 Jul 2024 16:31:32 -0500 Subject: [PATCH 1/2] Add changes before insert mode undo Fixes #11077 --- helix-view/src/document.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index a56cbc2ffae5..82d4f23d9e7a 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -1410,6 +1410,7 @@ impl Document { } fn undo_redo_impl(&mut self, view: &mut View, undo: bool) -> bool { + self.append_changes_to_history(view); let mut history = self.history.take(); let txn = if undo { history.undo() } else { history.redo() }; let success = if let Some(txn) = txn { @@ -1490,6 +1491,7 @@ impl Document { } fn earlier_later_impl(&mut self, view: &mut View, uk: UndoKind, earlier: bool) -> bool { + self.append_changes_to_history(view); let txns = if earlier { self.history.get_mut().earlier(uk) } else { From 7d6e47b856267ae03c3dc7632f7502ad3eb091f0 Mon Sep 17 00:00:00 2001 From: Kaniel Kirby Date: Sat, 6 Jul 2024 12:04:06 -0500 Subject: [PATCH 2/2] Address edge cases for undo like Kakoune does --- helix-view/src/document.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 82d4f23d9e7a..ccf2fa8c387c 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -1410,7 +1410,11 @@ impl Document { } fn undo_redo_impl(&mut self, view: &mut View, undo: bool) -> bool { - self.append_changes_to_history(view); + 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 { @@ -1491,7 +1495,11 @@ impl Document { } fn earlier_later_impl(&mut self, view: &mut View, uk: UndoKind, earlier: bool) -> bool { - self.append_changes_to_history(view); + 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 {