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

View::apply should only be called by EditorView after 42e37a571e75aaf4feb1717dfebe8cf215e535dd. This change removes the duplicate calls within undo/redo which could cause a panic.

commitfd00f3a70eb626242bb2fcc9bddf2c4d94580a9a authorMichael Davis <mcarsondavis@gmail.com> dateWed 23 Nov 2022, 08:57 (4 years ago) parent94eb3de
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
@@ -3302,7 +3302,7 @@ fn undo(cx: &mut Context) {
33023302 let count = cx.count();
33033303 let (view, doc) = current!(cx.editor);
33043304 for _ in 0..count {
3305− if !doc.undo(view) {
3305+ if !doc.undo(view.id) {
33063306 cx.editor.set_status("Already at oldest change");
33073307 break;
33083308 }
@@ -3313,7 +3313,7 @@ fn redo(cx: &mut Context) {
33133313 let count = cx.count();
33143314 let (view, doc) = current!(cx.editor);
33153315 for _ in 0..count {
3316− if !doc.redo(view) {
3316+ if !doc.redo(view.id) {
33173317 cx.editor.set_status("Already at newest change");
33183318 break;
33193319 }
@@ -3325,7 +3325,7 @@ fn earlier(cx: &mut Context) {
33253325 let (view, doc) = current!(cx.editor);
33263326 for _ in 0..count {
33273327 // 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)) {
33293329 cx.editor.set_status("Already at oldest change");
33303330 break;
33313331 }
@@ -3337,7 +3337,7 @@ fn later(cx: &mut Context) {
33373337 let (view, doc) = current!(cx.editor);
33383338 for _ in 0..count {
33393339 // 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)) {
33413341 cx.editor.set_status("Already at newest change");
33423342 break;
33433343 }
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, uk);
484+ let success = doc.earlier(view.id, 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, uk);
503+ let success = doc.later(view.id, 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: &mut View, undo: bool) -> bool {
860+ fn undo_redo_impl(&mut self, view_id: ViewId, 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) && view.apply(txn, self)
864+ self.apply_impl(txn, view_id)
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: &mut View) -> bool {
879− self.undo_redo_impl(view, true)
878+ pub fn undo(&mut self, view_id: ViewId) -> bool {
879+ self.undo_redo_impl(view_id, true)
880880 }
881881
882882 /// Redo the last modification to the [`Document`]. Returns whether the redo was successful.
883− pub fn redo(&mut self, view: &mut View) -> bool {
884− self.undo_redo_impl(view, false)
883+ pub fn redo(&mut self, view_id: ViewId) -> bool {
884+ self.undo_redo_impl(view_id, 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: &mut View, uk: UndoKind, earlier: bool) -> bool {
897+ fn earlier_later_impl(&mut self, view_id: ViewId, 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) && view.apply(&txn, self) {
905+ if self.apply_impl(&txn, view_id) {
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: &mut View, uk: UndoKind) -> bool {
918− self.earlier_later_impl(view, uk, true)
917+ pub fn earlier(&mut self, view_id: ViewId, uk: UndoKind) -> bool {
918+ self.earlier_later_impl(view_id, uk, true)
919919 }
920920
921921 /// Redo modifications to the [`Document`] according to `uk`.
922− pub fn later(&mut self, view: &mut View, uk: UndoKind) -> bool {
923− self.earlier_later_impl(view, uk, false)
922+ pub fn later(&mut self, view_id: ViewId, uk: UndoKind) -> bool {
923+ self.earlier_later_impl(view_id, uk, false)
924924 }
925925
926926 /// Commit pending changes to history