Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix mismatched excerpts in split agent diff (#55629)
Cole Miller8bf57f8dd6ef
diff --git a/crates/agent_ui/src/agent_diff.rs b/crates/agent_ui/src/agent_diff.rsindex 04951fcbe7c..4a5771fd981 100644--- a/crates/agent_ui/src/agent_diff.rs+++ b/crates/agent_ui/src/agent_diff.rs@@ -173,19 +173,17 @@ impl AgentDiffPane {.map(|diff_hunk| diff_hunk.buffer_range.to_point(&snapshot)).collect::<Vec<_>>();- let (was_empty, is_excerpt_newly_added) =- self.multibuffer.update(cx, |multibuffer, cx| {- let was_empty = multibuffer.is_empty();- let is_excerpt_newly_added = multibuffer.update_excerpts_for_path(- path_key.clone(),- buffer.clone(),- diff_hunk_ranges,- multibuffer_context_lines(cx),- cx,- );- multibuffer.add_diff(diff_handle.clone(), cx);- (was_empty, is_excerpt_newly_added)- });+ let was_empty = self.multibuffer.read(cx).is_empty();+ let is_excerpt_newly_added = self.editor.update(cx, |editor, cx| {+ editor.update_excerpts_for_path(+ path_key.clone(),+ buffer.clone(),+ diff_hunk_ranges,+ multibuffer_context_lines(cx),+ diff_handle.clone(),+ cx,+ )+ });let rhs_editor = self.editor.read(cx).rhs_editor().clone();rhs_editor.update(cx, |editor, cx| {@@ -216,9 +214,9 @@ impl AgentDiffPane {});}- self.multibuffer.update(cx, |multibuffer, cx| {+ self.editor.update(cx, |editor, cx| {for buffer_id in buffers_to_delete {- multibuffer.remove_excerpts_for_buffer(buffer_id, cx);+ editor.remove_excerpts_for_buffer(buffer_id, cx);}});diff --git a/crates/editor/src/split.rs b/crates/editor/src/split.rsindex 42f485a236b..8f7ef224c53 100644--- a/crates/editor/src/split.rs+++ b/crates/editor/src/split.rs@@ -1280,6 +1280,18 @@ impl SplittableEditor {}}}++ pub fn remove_excerpts_for_buffer(+ &mut self,+ buffer_id: BufferId,+ cx: &mut Context<'_, SplittableEditor>,+ ) {+ let snapshot = self.rhs_multibuffer.read(cx).snapshot(cx);+ let Some(path) = snapshot.path_for_buffer(buffer_id) else {+ return;+ };+ self.remove_excerpts_for_path(path.clone(), cx);+ }}#[cfg(test)]