Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

project_diff: Fix overly large edits being emitted when a diff is recomputed (#46056)

Cole Miller88a153cd186b
diff --git a/crates/editor/src/split.rs b/crates/editor/src/split.rs
index f6cff5d92e1..e852d3c6e3a 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::*;