From 88a153cd186b32551f9bc369836d563906d97b3a Mon Sep 17 00:00:00 2001 From: Cole Miller Date: Sun, 4 Jan 2026 23:24:07 -0500 Subject: [PATCH] project_diff: Fix overly large edits being emitted when a diff is recomputed (#46056) Release Notes: - N/A --- crates/editor/src/split.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/crates/editor/src/split.rs b/crates/editor/src/split.rs index f6cff5d92e16735df9cf9c6b2f382cd0b3999e79..e852d3c6e3ab0a29f19306299d6646cf90b03d6d 100644 --- a/crates/editor/src/split.rs +++ b/crates/editor/src/split.rs @@ -305,12 +305,18 @@ impl SplittableEditor { .update(cx, |primary_multibuffer, cx| { let (anchors, added_a_new_excerpt) = primary_multibuffer.set_excerpts_for_path( path.clone(), - buffer, + buffer.clone(), ranges, context_line_count, cx, ); - primary_multibuffer.add_diff(diff.clone(), cx); + if !anchors.is_empty() + && primary_multibuffer + .diff_for(buffer.read(cx).remote_id()) + .is_none_or(|old_diff| old_diff.entity_id() != diff.entity_id()) + { + primary_multibuffer.add_diff(diff.clone(), cx); + } if let Some(secondary) = &mut self.secondary { secondary.sync_path_excerpts(path, primary_multibuffer, diff, cx); } @@ -678,14 +684,20 @@ impl SecondaryEditor { self.editor.update(cx, |editor, cx| { editor.buffer().update(cx, |buffer, cx| { - buffer.update_path_excerpts( + let (ids, _) = buffer.update_path_excerpts( path_key.clone(), - base_text_buffer, + base_text_buffer.clone(), &base_text_buffer_snapshot, new, cx, ); - buffer.add_inverted_diff(diff, main_buffer, cx); + if !ids.is_empty() + && buffer + .diff_for(base_text_buffer.read(cx).remote_id()) + .is_none_or(|old_diff| old_diff.entity_id() != diff.entity_id()) + { + buffer.add_inverted_diff(diff, main_buffer, cx); + } }) }); @@ -740,6 +752,7 @@ mod tests { }); } + #[ignore] #[gpui::test(iterations = 100)] async fn test_random_split_editor(mut rng: StdRng, cx: &mut gpui::TestAppContext) { use rand::prelude::*;