on master help sign in
Revert "Don't apply transactions to Views in undo/redo"

This reverts commit fd00f3a70eb626242bb2fcc9bddf2c4d94580a9a.

commit4d1f5389f99013be99b9498fd3fee78eec6217f3 authorMichael Davis <mcarsondavis@gmail.com> dateSun 27 Nov 2022, 10:46 (4 years ago) parentdf5457a
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
@@ -3321,7 +3321,7 @@ fn undo(cx: &mut Context) {
33213321 let count = cx.count();
33223322 let (view, doc) = current!(cx.editor);
33233323 for _ in 0..count {
3324− if !doc.undo(view.id) {
3324+ if !doc.undo(view) {
33253325 cx.editor.set_status("Already at oldest change");
33263326 break;
33273327 }
@@ -3332,7 +3332,7 @@ fn redo(cx: &mut Context) {
33323332 let count = cx.count();
33333333 let (view, doc) = current!(cx.editor);
33343334 for _ in 0..count {
3335− if !doc.redo(view.id) {
3335+ if !doc.redo(view) {
33363336 cx.editor.set_status("Already at newest change");
33373337 break;
33383338 }
@@ -3344,7 +3344,7 @@ fn earlier(cx: &mut Context) {
33443344 let (view, doc) = current!(cx.editor);
33453345 for _ in 0..count {
33463346 // rather than doing in batch we do this so get error halfway
3347− if !doc.earlier(view.id, UndoKind::Steps(1)) {
3347+ if !doc.earlier(view, UndoKind::Steps(1)) {
33483348 cx.editor.set_status("Already at oldest change");
33493349 break;
33503350 }
@@ -3356,7 +3356,7 @@ fn later(cx: &mut Context) {
33563356 let (view, doc) = current!(cx.editor);
33573357 for _ in 0..count {
33583358 // rather than doing in batch we do this so get error halfway
3359− if !doc.later(view.id, UndoKind::Steps(1)) {
3359+ if !doc.later(view, UndoKind::Steps(1)) {
33603360 cx.editor.set_status("Already at newest change");
33613361 break;
33623362 }
helix-term/src/commands/typed.rs+2−2
@@ -481,7 +481,7 @@ fn earlier(
481481 let uk = args.join(" ").parse::<UndoKind>().map_err(|s| anyhow!(s))?;
482482
483483 let (view, doc) = current!(cx.editor);
484− let success = doc.earlier(view.id, uk);
484+ let success = doc.earlier(view, uk);
485485 if !success {
486486 cx.editor.set_status("Already at oldest change");
487487 }
@@ -500,7 +500,7 @@ fn later(
500500
501501 let uk = args.join(" ").parse::<UndoKind>().map_err(|s| anyhow!(s))?;
502502 let (view, doc) = current!(cx.editor);
503− let success = doc.later(view.id, uk);
503+ let success = doc.later(view, uk);
504504 if !success {
505505 cx.editor.set_status("Already at newest change");
506506 }
helix-view/src/document.rs+12−12
@@ -857,11 +857,11 @@ impl Document {
857857 success
858858 }
859859
860− fn undo_redo_impl(&mut self, view_id: ViewId, undo: bool) -> bool {
860+ fn undo_redo_impl(&mut self, view: &mut View, undo: bool) -> bool {
861861 let mut history = self.history.take();
862862 let txn = if undo { history.undo() } else { history.redo() };
863863 let success = if let Some(txn) = txn {
864− self.apply_impl(txn, view_id)
864+ self.apply_impl(txn, view.id) && view.apply(txn, self)
865865 } else {
866866 false
867867 };
@@ -875,13 +875,13 @@ impl Document {
875875 }
876876
877877 /// Undo the last modification to the [`Document`]. Returns whether the undo was successful.
878− pub fn undo(&mut self, view_id: ViewId) -> bool {
879− self.undo_redo_impl(view_id, true)
878+ pub fn undo(&mut self, view: &mut View) -> bool {
879+ self.undo_redo_impl(view, true)
880880 }
881881
882882 /// Redo the last modification to the [`Document`]. Returns whether the redo was successful.
883− pub fn redo(&mut self, view_id: ViewId) -> bool {
884− self.undo_redo_impl(view_id, false)
883+ pub fn redo(&mut self, view: &mut View) -> bool {
884+ self.undo_redo_impl(view, false)
885885 }
886886
887887 pub fn savepoint(&mut self) {
@@ -894,7 +894,7 @@ impl Document {
894894 }
895895 }
896896
897− fn earlier_later_impl(&mut self, view_id: ViewId, uk: UndoKind, earlier: bool) -> bool {
897+ fn earlier_later_impl(&mut self, view: &mut View, uk: UndoKind, earlier: bool) -> bool {
898898 let txns = if earlier {
899899 self.history.get_mut().earlier(uk)
900900 } else {
@@ -902,7 +902,7 @@ impl Document {
902902 };
903903 let mut success = false;
904904 for txn in txns {
905− if self.apply_impl(&txn, view_id) {
905+ if self.apply_impl(&txn, view.id) && view.apply(&txn, self) {
906906 success = true;
907907 }
908908 }
@@ -914,13 +914,13 @@ impl Document {
914914 }
915915
916916 /// Undo modifications to the [`Document`] according to `uk`.
917− pub fn earlier(&mut self, view_id: ViewId, uk: UndoKind) -> bool {
918− self.earlier_later_impl(view_id, uk, true)
917+ pub fn earlier(&mut self, view: &mut View, uk: UndoKind) -> bool {
918+ self.earlier_later_impl(view, uk, true)
919919 }
920920
921921 /// Redo modifications to the [`Document`] according to `uk`.
922− pub fn later(&mut self, view_id: ViewId, uk: UndoKind) -> bool {
923− self.earlier_later_impl(view_id, uk, false)
922+ pub fn later(&mut self, view: &mut View, uk: UndoKind) -> bool {
923+ self.earlier_later_impl(view, uk, false)
924924 }
925925
926926 /// Commit pending changes to history