Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
git: Disable folding in side-by-side diff (#48108)
Cole Millerc2959a7f7e37
diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rsindex 88e5e84a5c3..329205859ba 100644--- a/crates/editor/src/display_map.rs+++ b/crates/editor/src/display_map.rs@@ -350,53 +350,56 @@ impl DisplayMap {companion: Option<(WeakEntity<DisplayMap>, Entity<Companion>)>,cx: &mut Context<Self>,) {- if let Some((_, ref companion_entity)) = companion {- let c = companion_entity.read(cx);- if self.entity_id != c.rhs_display_map_id {- let buffer_mapping = c.buffer_to_companion_buffer(c.rhs_display_map_id);- self.block_map.folded_buffers = c- .rhs_folded_buffers- .iter()- .filter_map(|id| buffer_mapping.get(id).copied())- .collect();- }+ let Some((companion_display_map, companion)) = companion else {+ self.companion = None;+ let (snapshot, edits) = self.sync_through_wrap(cx);+ let edits = edits.compose([text::Edit {+ old: WrapRow(0)..snapshot.max_point().row(),+ new: WrapRow(0)..snapshot.max_point().row(),+ }]);+ self.block_map.read(snapshot, edits, None, None);+ return;+ };++ let rhs_display_map_id = companion.read(cx).rhs_display_map_id;+ if self.entity_id != rhs_display_map_id {+ let buffer_mapping = companion+ .read(cx)+ .buffer_to_companion_buffer(rhs_display_map_id);+ self.block_map.folded_buffers = companion+ .read(cx)+ .rhs_folded_buffers+ .iter()+ .filter_map(|id| buffer_mapping.get(id).copied())+ .collect();}- self.companion = companion;+ let snapshot = self.unfold_intersecting([Anchor::min()..Anchor::max()], true, cx);- let buffer_snapshot = self.buffer.read(cx).snapshot(cx);- let edits = self.buffer_subscription.consume().into_inner();- let tab_size = Self::tab_size(&self.buffer, cx);- let edits = Patch::new(edits)- .compose([text::Edit {- old: MultiBufferOffset(0)..buffer_snapshot.len(),- new: MultiBufferOffset(0)..buffer_snapshot.len(),- }])- .into_inner();+ self.companion = Some((companion_display_map.clone(), companion));- let (snapshot, edits) = self.inlay_map.sync(buffer_snapshot, edits);- let (snapshot, edits) = self.fold_map.read(snapshot, edits);- let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);- let (snapshot, edits) = self- .wrap_map- .update(cx, |map, cx| map.sync(snapshot, edits, cx));-- let companion_wrap_data = self.companion.as_ref().and_then(|(companion_dm, _)| {- companion_dm- .update(cx, |dm, cx| dm.sync_through_wrap(cx))- .ok()- });+ let companion_wrap_data = companion_display_map+ .update(cx, |dm, cx| dm.sync_through_wrap(cx))+ .ok();let companion_wrap_edits = companion_wrap_data.as_ref().map(|(snapshot, edits)| (snapshot, edits));- let companion_ref = self.companion.as_ref().map(|(_, c)| c.read(cx));+ let companion = self.companion.as_ref().map(|(_, c)| c.read(cx));+ let edits = Patch::new(+ [text::Edit {+ old: WrapRow(0)..snapshot.max_point().row(),+ new: WrapRow(0)..snapshot.max_point().row(),+ }]+ .into_iter()+ .collect(),+ );self.block_map.read(snapshot.clone(),edits.clone(),companion_wrap_edits,- companion_ref.map(|c| (c, self.entity_id)),+ companion.map(|c| (c, self.entity_id)),);if let Some((companion_dm, _)) = &self.companion {@@ -541,6 +544,10 @@ impl DisplayMap {/// Creates folds for the given creases.#[instrument(skip_all)]pub fn fold<T: Clone + ToOffset>(&mut self, creases: Vec<Crease<T>>, cx: &mut Context<Self>) {+ if self.companion().is_some() {+ return;+ }+let buffer_snapshot = self.buffer.read(cx).snapshot(cx);let edits = self.buffer_subscription.consume().into_inner();let tab_size = Self::tab_size(&self.buffer, cx);@@ -733,7 +740,7 @@ impl DisplayMap {ranges: impl IntoIterator<Item = Range<T>>,inclusive: bool,cx: &mut Context<Self>,- ) {+ ) -> WrapSnapshot {let snapshot = self.buffer.read(cx).snapshot(cx);let offset_ranges = ranges.into_iter()@@ -783,7 +790,7 @@ impl DisplayMap {let companion_ref = self.companion.as_ref().map(|(_, c)| c.read(cx));let mut block_map = self.block_map.write(- self_new_wrap_snapshot,+ self_new_wrap_snapshot.clone(),self_new_wrap_edits,companion_wrap_edits,companion_ref.map(|c| (c, self.entity_id)),@@ -803,6 +810,8 @@ impl DisplayMap {}});}++ self_new_wrap_snapshot}#[instrument(skip_all)]diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex f70e39fc1cf..ae5c94af410 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -20111,7 +20111,7 @@ impl Editor {cx: &mut Context<Self>,) {self.remove_folds_with(ranges, auto_scroll, cx, |map, cx| {- map.unfold_intersecting(ranges.iter().cloned(), inclusive, cx)+ map.unfold_intersecting(ranges.iter().cloned(), inclusive, cx);});self.folds_did_change(cx);}