on master help sign in
Apply transactions to the jumplist for undo/redo (#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.

commite16c63276082f1cf79c57ff2ed2d301fe3333a0e authorMichael Davis <mcarsondavis@gmail.com> dateWed 12 Oct 2022, 10:57 (4 years ago) parent7f75458
3 files changed+18−18
helix-term/src/commands.rs+4−4 helix-term/src/commands/typed.rs+2−2 helix-view/src/document.rs+12−12
helix-term/src/commands.rs+4−4
@@ -3258,7 +3258,7 @@ fn undo(cx: &mut Context) {
32583258 let count = cx.count();
32593259 let (view, doc) = current!(cx.editor);
32603260 for _ in 0..count {
3261− if !doc.undo(view.id) {
3261+ if !doc.undo(view) {
32623262 cx.editor.set_status("Already at oldest change");
32633263 break;
32643264 }
@@ -3269,7 +3269,7 @@ fn redo(cx: &mut Context) {
32693269 let count = cx.count();
32703270 let (view, doc) = current!(cx.editor);
32713271 for _ in 0..count {
3272− if !doc.redo(view.id) {
3272+ if !doc.redo(view) {
32733273 cx.editor.set_status("Already at newest change");
32743274 break;
32753275 }
@@ -3281,7 +3281,7 @@ fn earlier(cx: &mut Context) {
32813281 let (view, doc) = current!(cx.editor);
32823282 for _ in 0..count {
32833283 // rather than doing in batch we do this so get error halfway
3284− if !doc.earlier(view.id, UndoKind::Steps(1)) {
3284+ if !doc.earlier(view, UndoKind::Steps(1)) {
32853285 cx.editor.set_status("Already at oldest change");
32863286 break;
32873287 }
@@ -3293,7 +3293,7 @@ fn later(cx: &mut Context) {
32933293 let (view, doc) = current!(cx.editor);
32943294 for _ in 0..count {
32953295 // rather than doing in batch we do this so get error halfway
3296− if !doc.later(view.id, UndoKind::Steps(1)) {
3296+ if !doc.later(view, UndoKind::Steps(1)) {
32973297 cx.editor.set_status("Already at newest change");
32983298 break;
32993299 }
helix-term/src/commands/typed.rs+2−2
@@ -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
@@ -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,7 +871,7 @@ 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 {
@@ -879,7 +879,7 @@ impl Document {
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