@@ -3,7 +3,10 @@ use helix_core::{
3 pos_at_visual_coords, visual_coords_at_pos, Position, RopeSlice, Selection, Transaction,
3 pos_at_visual_coords, visual_coords_at_pos, Position, RopeSlice, Selection, Transaction,
6−use std::{collections::VecDeque, fmt};
7+ collections::{HashMap, VecDeque},
8const JUMP_LIST_CAPACITY: usize = 30;
11const JUMP_LIST_CAPACITY: usize = 30;
@@ -102,6 +105,11 @@ pub struct View {
102 pub object_selections: Vec<Selection>,
105 pub object_selections: Vec<Selection>,
103 /// GutterTypes used to fetch Gutter (constructor) and width for rendering
106 /// GutterTypes used to fetch Gutter (constructor) and width for rendering
104 gutters: Vec<GutterType>,
107 gutters: Vec<GutterType>,
108+ /// A mapping between documents and the last history revision the view was updated at.
109+ /// Changes between documents and views are synced lazily when switching windows. This
110+ /// mapping keeps track of the last applied history revision so that only new changes
112+ doc_revisions: HashMap<DocumentId, usize>,
107impl fmt::Debug for View {
115impl fmt::Debug for View {
@@ -126,6 +134,7 @@ impl View {
126 last_modified_docs: [None, None],
134 last_modified_docs: [None, None],
127 object_selections: Vec::new(),
135 object_selections: Vec::new(),
128 gutters: gutter_types,
136 gutters: gutter_types,
137+ doc_revisions: HashMap::new(),
@@ -349,10 +358,33 @@ impl View {
349 /// Applies a [`Transaction`] to the view.
358 /// Applies a [`Transaction`] to the view.
350 /// Instead of calling this function directly, use [crate::apply_transaction]
359 /// Instead of calling this function directly, use [crate::apply_transaction]
351 /// which applies a transaction to the [`Document`] and view together.
360 /// which applies a transaction to the [`Document`] and view together.
352− pub fn apply(&mut self, transaction: &Transaction, doc: &Document) -> bool {
361+ pub fn apply(&mut self, transaction: &Transaction, doc: &mut Document) {
353 self.jumps.apply(transaction, doc);
362 self.jumps.apply(transaction, doc);
354− // TODO: remove the boolean return. This is unused.
363+ self.doc_revisions
355− true
364+ .insert(doc.id(), doc.get_current_revision());
367+ pub fn sync_changes(&mut self, doc: &mut Document) {
368+ let latest_revision = doc.get_current_revision();
369+ let current_revision = *self
372+ .or_insert(latest_revision);
374+ if current_revision == latest_revision {
379+ "Syncing view {:?} between {} and {}",
385+ if let Some(transaction) = doc.history.get_mut().changes_since(current_revision) {
386+ self.apply(&transaction, doc);