From 42e37a571e75aaf4feb1717dfebe8cf215e535dd Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Tue, 22 Nov 2022 21:28:49 -0600 Subject: Apply transactions to all views (#4733) * Add a test case for updating jumplists across windows * Apply transactions to all views on history changes This ensures that jumplist selections follow changes in documents, even when there are multiple views (for example a split where both windows edit the same document). * Leave TODOs for cleaning up View::apply * Use Iterator::reduce to compose history transactions Co-authored-by: Blaž Hrastnik Co-authored-by: Blaž Hrastnik --- helix-view/src/lib.rs | 8 +++----- helix-view/src/macros.rs | 2 +- helix-view/src/view.rs | 1 + 3 files changed, 5 insertions(+), 6 deletions(-) (limited to 'helix-view') diff --git a/helix-view/src/lib.rs b/helix-view/src/lib.rs index 4c32b356..9cf36ae0 100644 --- a/helix-view/src/lib.rs +++ b/helix-view/src/lib.rs @@ -71,12 +71,10 @@ pub fn align_view(doc: &Document, view: &mut View, align: Align) { pub fn apply_transaction( transaction: &helix_core::Transaction, doc: &mut Document, - view: &mut View, + view: &View, ) -> bool { - // This is a short function but it's easy to call `Document::apply` - // without calling `View::apply` or in the wrong order. The transaction - // must be applied to the document before the view. - doc.apply(transaction, view.id) && view.apply(transaction, doc) + // TODO remove this helper function. Just call Document::apply everywhere directly. + doc.apply(transaction, view.id) } pub use document::Document; diff --git a/helix-view/src/macros.rs b/helix-view/src/macros.rs index 53ab4346..ee9cd411 100644 --- a/helix-view/src/macros.rs +++ b/helix-view/src/macros.rs @@ -67,7 +67,7 @@ macro_rules! view { #[macro_export] macro_rules! doc { ($editor:expr, $id:expr) => {{ - $editor.documents[$id] + &$editor.documents[$id] }}; ($editor:expr) => {{ $crate::current_ref!($editor).1 diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index 8aa4760d..c917a1ab 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -351,6 +351,7 @@ impl View { /// which applies a transaction to the [`Document`] and view together. pub fn apply(&mut self, transaction: &Transaction, doc: &Document) -> bool { self.jumps.apply(transaction, doc); + // TODO: remove the boolean return. This is unused. true } } -- cgit v1.2.3-70-g09d2