on master help sign in
Don't apply transactions to Views in undo/redo
fd00f3aMichael Davis
helix-term/src/commands.rs+4−4
@@ -3302,7 +3302,7 @@ fn undo(cx: &mut Context) {
3302 let count = cx.count();
3302 let count = cx.count();
3303 let (view, doc) = current!(cx.editor);
3303 let (view, doc) = current!(cx.editor);
3304 for _ in 0..count {
3304 for _ in 0..count {
3305− if !doc.undo(view) {
3305+ if !doc.undo(view.id) {
3306 cx.editor.set_status("Already at oldest change");
3306 cx.editor.set_status("Already at oldest change");
3307 break;
3307 break;
3308 }
3308 }
@@ -3313,7 +3313,7 @@ fn redo(cx: &mut Context) {
3313 let count = cx.count();
3313 let count = cx.count();
3314 let (view, doc) = current!(cx.editor);
3314 let (view, doc) = current!(cx.editor);
3315 for _ in 0..count {
3315 for _ in 0..count {
3316− if !doc.redo(view) {
3316+ if !doc.redo(view.id) {
3317 cx.editor.set_status("Already at newest change");
3317 cx.editor.set_status("Already at newest change");
3318 break;
3318 break;
3319 }
3319 }
@@ -3325,7 +3325,7 @@ fn earlier(cx: &mut Context) {
3325 let (view, doc) = current!(cx.editor);
3325 let (view, doc) = current!(cx.editor);
3326 for _ in 0..count {
3326 for _ in 0..count {
3327 // rather than doing in batch we do this so get error halfway
3327 // rather than doing in batch we do this so get error halfway
3328− if !doc.earlier(view, UndoKind::Steps(1)) {
3328+ if !doc.earlier(view.id, UndoKind::Steps(1)) {
3329 cx.editor.set_status("Already at oldest change");
3329 cx.editor.set_status("Already at oldest change");
3330 break;
3330 break;
3331 }
3331 }
@@ -3337,7 +3337,7 @@ fn later(cx: &mut Context) {
3337 let (view, doc) = current!(cx.editor);
3337 let (view, doc) = current!(cx.editor);
3338 for _ in 0..count {
3338 for _ in 0..count {
3339 // rather than doing in batch we do this so get error halfway
3339 // rather than doing in batch we do this so get error halfway
3340− if !doc.later(view, UndoKind::Steps(1)) {
3340+ if !doc.later(view.id, UndoKind::Steps(1)) {
3341 cx.editor.set_status("Already at newest change");
3341 cx.editor.set_status("Already at newest change");
3342 break;
3342 break;
3343 }
3343 }
helix-term/src/commands/typed.rs+2−2
@@ -481,7 +481,7 @@ fn earlier(
481 let uk = args.join(" ").parse::<UndoKind>().map_err(|s| anyhow!(s))?;
481 let uk = args.join(" ").parse::<UndoKind>().map_err(|s| anyhow!(s))?;
482
482
483 let (view, doc) = current!(cx.editor);
483 let (view, doc) = current!(cx.editor);
484− let success = doc.earlier(view, uk);
484+ let success = doc.earlier(view.id, uk);
485 if !success {
485 if !success {
486 cx.editor.set_status("Already at oldest change");
486 cx.editor.set_status("Already at oldest change");
487 }
487 }
@@ -500,7 +500,7 @@ fn later(
500
500
501 let uk = args.join(" ").parse::<UndoKind>().map_err(|s| anyhow!(s))?;
501 let uk = args.join(" ").parse::<UndoKind>().map_err(|s| anyhow!(s))?;
502 let (view, doc) = current!(cx.editor);
502 let (view, doc) = current!(cx.editor);
503− let success = doc.later(view, uk);
503+ let success = doc.later(view.id, uk);
504 if !success {
504 if !success {
505 cx.editor.set_status("Already at newest change");
505 cx.editor.set_status("Already at newest change");
506 }
506 }
helix-view/src/document.rs+12−12
@@ -857,11 +857,11 @@ impl Document {
857 success
857 success
858 }
858 }
859
859
860− fn undo_redo_impl(&mut self, view: &mut View, undo: bool) -> bool {
860+ fn undo_redo_impl(&mut self, view_id: ViewId, undo: bool) -> bool {
861 let mut history = self.history.take();
861 let mut history = self.history.take();
862 let txn = if undo { history.undo() } else { history.redo() };
862 let txn = if undo { history.undo() } else { history.redo() };
863 let success = if let Some(txn) = txn {
863 let success = if let Some(txn) = txn {
864− self.apply_impl(txn, view.id) && view.apply(txn, self)
864+ self.apply_impl(txn, view_id)
865 } else {
865 } else {
866 false
866 false
867 };
867 };
@@ -875,13 +875,13 @@ impl Document {
875 }
875 }
876
876
877 /// Undo the last modification to the [`Document`]. Returns whether the undo was successful.
877 /// Undo the last modification to the [`Document`]. Returns whether the undo was successful.
878− pub fn undo(&mut self, view: &mut View) -> bool {
878+ pub fn undo(&mut self, view_id: ViewId) -> bool {
879− self.undo_redo_impl(view, true)
879+ self.undo_redo_impl(view_id, true)
880 }
880 }
881
881
882 /// Redo the last modification to the [`Document`]. Returns whether the redo was successful.
882 /// Redo the last modification to the [`Document`]. Returns whether the redo was successful.
883− pub fn redo(&mut self, view: &mut View) -> bool {
883+ pub fn redo(&mut self, view_id: ViewId) -> bool {
884− self.undo_redo_impl(view, false)
884+ self.undo_redo_impl(view_id, false)
885 }
885 }
886
886
887 pub fn savepoint(&mut self) {
887 pub fn savepoint(&mut self) {
@@ -894,7 +894,7 @@ impl Document {
894 }
894 }
895 }
895 }
896
896
897− fn earlier_later_impl(&mut self, view: &mut View, uk: UndoKind, earlier: bool) -> bool {
897+ fn earlier_later_impl(&mut self, view_id: ViewId, uk: UndoKind, earlier: bool) -> bool {
898 let txns = if earlier {
898 let txns = if earlier {
899 self.history.get_mut().earlier(uk)
899 self.history.get_mut().earlier(uk)
900 } else {
900 } else {
@@ -902,7 +902,7 @@ impl Document {
902 };
902 };
903 let mut success = false;
903 let mut success = false;
904 for txn in txns {
904 for txn in txns {
905− if self.apply_impl(&txn, view.id) && view.apply(&txn, self) {
905+ if self.apply_impl(&txn, view_id) {
906 success = true;
906 success = true;
907 }
907 }
908 }
908 }
@@ -914,13 +914,13 @@ impl Document {
914 }
914 }
915
915
916 /// Undo modifications to the [`Document`] according to `uk`.
916 /// Undo modifications to the [`Document`] according to `uk`.
917− pub fn earlier(&mut self, view: &mut View, uk: UndoKind) -> bool {
917+ pub fn earlier(&mut self, view_id: ViewId, uk: UndoKind) -> bool {
918− self.earlier_later_impl(view, uk, true)
918+ self.earlier_later_impl(view_id, uk, true)
919 }
919 }
920
920
921 /// Redo modifications to the [`Document`] according to `uk`.
921 /// Redo modifications to the [`Document`] according to `uk`.
922− pub fn later(&mut self, view: &mut View, uk: UndoKind) -> bool {
922+ pub fn later(&mut self, view_id: ViewId, uk: UndoKind) -> bool {
923− self.earlier_later_impl(view, uk, false)
923+ self.earlier_later_impl(view_id, uk, false)
924 }
924 }
925
925
926 /// Commit pending changes to history
926 /// Commit pending changes to history