Skip to content

Commit

Permalink
Add changes for undo in insert mode (helix-editor#11090)
Browse files Browse the repository at this point in the history
* Add changes before insert mode undo
Fixes helix-editor#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>
  • Loading branch information
3 people authored and Schuyler Mortimer committed Jul 10, 2024
1 parent fbfc39a commit 025e452
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions helix-view/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 025e452

Please sign in to comment.