Skip to content

Commit b394693

Browse files
the-mikedavisShekhinah Memmel
authored and
Shekhinah Memmel
committed
Apply transactions to the jumplist for undo/redo (helix-editor#4227)
Undo/redo/earlier/later call `Document::apply_impl` which applies transactions to the document. These transactions also need to be applied to the view as in 0aedef0.
1 parent 68c9bdd commit b394693

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

helix-term/src/commands.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3298,7 +3298,7 @@ fn undo(cx: &mut Context) {
32983298
let count = cx.count();
32993299
let (view, doc) = current!(cx.editor);
33003300
for _ in 0..count {
3301-
if !doc.undo(view.id) {
3301+
if !doc.undo(view) {
33023302
cx.editor.set_status("Already at oldest change");
33033303
break;
33043304
}
@@ -3309,7 +3309,7 @@ fn redo(cx: &mut Context) {
33093309
let count = cx.count();
33103310
let (view, doc) = current!(cx.editor);
33113311
for _ in 0..count {
3312-
if !doc.redo(view.id) {
3312+
if !doc.redo(view) {
33133313
cx.editor.set_status("Already at newest change");
33143314
break;
33153315
}
@@ -3321,7 +3321,7 @@ fn earlier(cx: &mut Context) {
33213321
let (view, doc) = current!(cx.editor);
33223322
for _ in 0..count {
33233323
// rather than doing in batch we do this so get error halfway
3324-
if !doc.earlier(view.id, UndoKind::Steps(1)) {
3324+
if !doc.earlier(view, UndoKind::Steps(1)) {
33253325
cx.editor.set_status("Already at oldest change");
33263326
break;
33273327
}
@@ -3333,7 +3333,7 @@ fn later(cx: &mut Context) {
33333333
let (view, doc) = current!(cx.editor);
33343334
for _ in 0..count {
33353335
// rather than doing in batch we do this so get error halfway
3336-
if !doc.later(view.id, UndoKind::Steps(1)) {
3336+
if !doc.later(view, UndoKind::Steps(1)) {
33373337
cx.editor.set_status("Already at newest change");
33383338
break;
33393339
}

helix-term/src/commands/typed.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ fn earlier(
483483
let uk = args.join(" ").parse::<UndoKind>().map_err(|s| anyhow!(s))?;
484484

485485
let (view, doc) = current!(cx.editor);
486-
let success = doc.earlier(view.id, uk);
486+
let success = doc.earlier(view, uk);
487487
if !success {
488488
cx.editor.set_status("Already at oldest change");
489489
}
@@ -502,7 +502,7 @@ fn later(
502502

503503
let uk = args.join(" ").parse::<UndoKind>().map_err(|s| anyhow!(s))?;
504504
let (view, doc) = current!(cx.editor);
505-
let success = doc.later(view.id, uk);
505+
let success = doc.later(view, uk);
506506
if !success {
507507
cx.editor.set_status("Already at newest change");
508508
}

helix-view/src/document.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -834,11 +834,11 @@ impl Document {
834834
success
835835
}
836836

837-
fn undo_redo_impl(&mut self, view_id: ViewId, undo: bool) -> bool {
837+
fn undo_redo_impl(&mut self, view: &mut View, undo: bool) -> bool {
838838
let mut history = self.history.take();
839839
let txn = if undo { history.undo() } else { history.redo() };
840840
let success = if let Some(txn) = txn {
841-
self.apply_impl(txn, view_id)
841+
self.apply_impl(txn, view.id) && view.apply(txn, self)
842842
} else {
843843
false
844844
};
@@ -852,13 +852,13 @@ impl Document {
852852
}
853853

854854
/// Undo the last modification to the [`Document`]. Returns whether the undo was successful.
855-
pub fn undo(&mut self, view_id: ViewId) -> bool {
856-
self.undo_redo_impl(view_id, true)
855+
pub fn undo(&mut self, view: &mut View) -> bool {
856+
self.undo_redo_impl(view, true)
857857
}
858858

859859
/// Redo the last modification to the [`Document`]. Returns whether the redo was successful.
860-
pub fn redo(&mut self, view_id: ViewId) -> bool {
861-
self.undo_redo_impl(view_id, false)
860+
pub fn redo(&mut self, view: &mut View) -> bool {
861+
self.undo_redo_impl(view, false)
862862
}
863863

864864
pub fn savepoint(&mut self) {
@@ -871,15 +871,15 @@ impl Document {
871871
}
872872
}
873873

874-
fn earlier_later_impl(&mut self, view_id: ViewId, uk: UndoKind, earlier: bool) -> bool {
874+
fn earlier_later_impl(&mut self, view: &mut View, uk: UndoKind, earlier: bool) -> bool {
875875
let txns = if earlier {
876876
self.history.get_mut().earlier(uk)
877877
} else {
878878
self.history.get_mut().later(uk)
879879
};
880880
let mut success = false;
881881
for txn in txns {
882-
if self.apply_impl(&txn, view_id) {
882+
if self.apply_impl(&txn, view.id) && view.apply(&txn, self) {
883883
success = true;
884884
}
885885
}
@@ -891,13 +891,13 @@ impl Document {
891891
}
892892

893893
/// Undo modifications to the [`Document`] according to `uk`.
894-
pub fn earlier(&mut self, view_id: ViewId, uk: UndoKind) -> bool {
895-
self.earlier_later_impl(view_id, uk, true)
894+
pub fn earlier(&mut self, view: &mut View, uk: UndoKind) -> bool {
895+
self.earlier_later_impl(view, uk, true)
896896
}
897897

898898
/// Redo modifications to the [`Document`] according to `uk`.
899-
pub fn later(&mut self, view_id: ViewId, uk: UndoKind) -> bool {
900-
self.earlier_later_impl(view_id, uk, false)
899+
pub fn later(&mut self, view: &mut View, uk: UndoKind) -> bool {
900+
self.earlier_later_impl(view, uk, false)
901901
}
902902

903903
/// Commit pending changes to history

0 commit comments

Comments
 (0)