on master help sign in
Apply transactions to the jumplist for undo/redo (#4227)
e16c632Michael Davis
helix-term/src/commands.rs+4−4
@@ -3258,7 +3258,7 @@ fn undo(cx: &mut Context) {
3258 let count = cx.count();
3258 let count = cx.count();
3259 let (view, doc) = current!(cx.editor);
3259 let (view, doc) = current!(cx.editor);
3260 for _ in 0..count {
3260 for _ in 0..count {
3261− if !doc.undo(view.id) {
3261+ if !doc.undo(view) {
3262 cx.editor.set_status("Already at oldest change");
3262 cx.editor.set_status("Already at oldest change");
3263 break;
3263 break;
3264 }
3264 }
@@ -3269,7 +3269,7 @@ fn redo(cx: &mut Context) {
3269 let count = cx.count();
3269 let count = cx.count();
3270 let (view, doc) = current!(cx.editor);
3270 let (view, doc) = current!(cx.editor);
3271 for _ in 0..count {
3271 for _ in 0..count {
3272− if !doc.redo(view.id) {
3272+ if !doc.redo(view) {
3273 cx.editor.set_status("Already at newest change");
3273 cx.editor.set_status("Already at newest change");
3274 break;
3274 break;
3275 }
3275 }
@@ -3281,7 +3281,7 @@ fn earlier(cx: &mut Context) {
3281 let (view, doc) = current!(cx.editor);
3281 let (view, doc) = current!(cx.editor);
3282 for _ in 0..count {
3282 for _ in 0..count {
3283 // rather than doing in batch we do this so get error halfway
3283 // 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)) {
3285 cx.editor.set_status("Already at oldest change");
3285 cx.editor.set_status("Already at oldest change");
3286 break;
3286 break;
3287 }
3287 }
@@ -3293,7 +3293,7 @@ fn later(cx: &mut Context) {
3293 let (view, doc) = current!(cx.editor);
3293 let (view, doc) = current!(cx.editor);
3294 for _ in 0..count {
3294 for _ in 0..count {
3295 // rather than doing in batch we do this so get error halfway
3295 // 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)) {
3297 cx.editor.set_status("Already at newest change");
3297 cx.editor.set_status("Already at newest change");
3298 break;
3298 break;
3299 }
3299 }
helix-term/src/commands/typed.rs+2−2
@@ -483,7 +483,7 @@ fn earlier(
483 let uk = args.join(" ").parse::<UndoKind>().map_err(|s| anyhow!(s))?;
483 let uk = args.join(" ").parse::<UndoKind>().map_err(|s| anyhow!(s))?;
484
484
485 let (view, doc) = current!(cx.editor);
485 let (view, doc) = current!(cx.editor);
486− let success = doc.earlier(view.id, uk);
486+ let success = doc.earlier(view, uk);
487 if !success {
487 if !success {
488 cx.editor.set_status("Already at oldest change");
488 cx.editor.set_status("Already at oldest change");
489 }
489 }
@@ -502,7 +502,7 @@ fn later(
502
502
503 let uk = args.join(" ").parse::<UndoKind>().map_err(|s| anyhow!(s))?;
503 let uk = args.join(" ").parse::<UndoKind>().map_err(|s| anyhow!(s))?;
504 let (view, doc) = current!(cx.editor);
504 let (view, doc) = current!(cx.editor);
505− let success = doc.later(view.id, uk);
505+ let success = doc.later(view, uk);
506 if !success {
506 if !success {
507 cx.editor.set_status("Already at newest change");
507 cx.editor.set_status("Already at newest change");
508 }
508 }
helix-view/src/document.rs+12−12
@@ -834,11 +834,11 @@ impl Document {
834 success
834 success
835 }
835 }
836
836
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 {
838 let mut history = self.history.take();
838 let mut history = self.history.take();
839 let txn = if undo { history.undo() } else { history.redo() };
839 let txn = if undo { history.undo() } else { history.redo() };
840 let success = if let Some(txn) = txn {
840 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)
842 } else {
842 } else {
843 false
843 false
844 };
844 };
@@ -852,13 +852,13 @@ impl Document {
852 }
852 }
853
853
854 /// Undo the last modification to the [`Document`]. Returns whether the undo was successful.
854 /// Undo the last modification to the [`Document`]. Returns whether the undo was successful.
855− pub fn undo(&mut self, view_id: ViewId) -> bool {
855+ pub fn undo(&mut self, view: &mut View) -> bool {
856− self.undo_redo_impl(view_id, true)
856+ self.undo_redo_impl(view, true)
857 }
857 }
858
858
859 /// Redo the last modification to the [`Document`]. Returns whether the redo was successful.
859 /// Redo the last modification to the [`Document`]. Returns whether the redo was successful.
860− pub fn redo(&mut self, view_id: ViewId) -> bool {
860+ pub fn redo(&mut self, view: &mut View) -> bool {
861− self.undo_redo_impl(view_id, false)
861+ self.undo_redo_impl(view, false)
862 }
862 }
863
863
864 pub fn savepoint(&mut self) {
864 pub fn savepoint(&mut self) {
@@ -871,7 +871,7 @@ impl Document {
871 }
871 }
872 }
872 }
873
873
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 {
875 let txns = if earlier {
875 let txns = if earlier {
876 self.history.get_mut().earlier(uk)
876 self.history.get_mut().earlier(uk)
877 } else {
877 } else {
@@ -879,7 +879,7 @@ impl Document {
879 };
879 };
880 let mut success = false;
880 let mut success = false;
881 for txn in txns {
881 for txn in txns {
882− if self.apply_impl(&txn, view_id) {
882+ if self.apply_impl(&txn, view.id) && view.apply(&txn, self) {
883 success = true;
883 success = true;
884 }
884 }
885 }
885 }
@@ -891,13 +891,13 @@ impl Document {
891 }
891 }
892
892
893 /// Undo modifications to the [`Document`] according to `uk`.
893 /// Undo modifications to the [`Document`] according to `uk`.
894− pub fn earlier(&mut self, view_id: ViewId, uk: UndoKind) -> bool {
894+ pub fn earlier(&mut self, view: &mut View, uk: UndoKind) -> bool {
895− self.earlier_later_impl(view_id, uk, true)
895+ self.earlier_later_impl(view, uk, true)
896 }
896 }
897
897
898 /// Redo modifications to the [`Document`] according to `uk`.
898 /// Redo modifications to the [`Document`] according to `uk`.
899− pub fn later(&mut self, view_id: ViewId, uk: UndoKind) -> bool {
899+ pub fn later(&mut self, view: &mut View, uk: UndoKind) -> bool {
900− self.earlier_later_impl(view_id, uk, false)
900+ self.earlier_later_impl(view, uk, false)
901 }
901 }
902
902
903 /// Commit pending changes to history
903 /// Commit pending changes to history