Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
agent_ui: Enable split diff view in agent diff (#54638)
Lukas Wirthb9beca160f63
diff --git a/crates/agent_ui/src/agent_diff.rs b/crates/agent_ui/src/agent_diff.rsindex 50297390970..04951fcbe7c 100644--- a/crates/agent_ui/src/agent_diff.rs+++ b/crates/agent_ui/src/agent_diff.rs@@ -7,7 +7,7 @@ use buffer_diff::DiffHunkStatus;use collections::{HashMap, HashSet};use editor::{Direction, Editor, EditorEvent, EditorSettings, MultiBuffer, MultiBufferSnapshot,- SelectionEffects, ToPoint,+ SelectionEffects, SplittableEditor, ToPoint,actions::{GoToHunk, GoToPreviousHunk},multibuffer_context_lines,scroll::Autoscroll,@@ -40,7 +40,7 @@ use zed_actions::assistant::ToggleFocus;pub struct AgentDiffPane {multibuffer: Entity<MultiBuffer>,- editor: Entity<Editor>,+ editor: Entity<SplittableEditor>,thread: Entity<AcpThread>,focus_handle: FocusHandle,workspace: WeakEntity<Workspace>,@@ -91,15 +91,21 @@ impl AgentDiffPane {let project = thread.read(cx).project().clone();let editor = cx.new(|cx| {- let mut editor =- Editor::for_multibuffer(multibuffer.clone(), Some(project.clone()), window, cx);- editor.disable_inline_diagnostics();- editor.set_expand_all_diff_hunks(cx);- editor+ let workspace_entity = workspace.upgrade().expect("workspace must exist");+ let diff_display_editor = SplittableEditor::new(+ EditorSettings::get_global(cx).diff_view_style,+ multibuffer.clone(),+ project.clone(),+ workspace_entity,+ window,+ cx,+ );+ diff_display_editor.set_render_diff_hunk_controls(diff_hunk_controls(&thread, workspace.clone()), cx);- editor.register_addon(AgentDiffAddon);- editor.disable_mouse_wheel_zoom();- editor+ diff_display_editor.update_editors(cx, |editor, _cx| {+ editor.register_addon(AgentDiffAddon);+ });+ diff_display_editor});let action_log = thread.read(cx).action_log().clone();@@ -181,7 +187,8 @@ impl AgentDiffPane {(was_empty, is_excerpt_newly_added)});- self.editor.update(cx, |editor, cx| {+ let rhs_editor = self.editor.read(cx).rhs_editor().clone();+ rhs_editor.update(cx, |editor, cx| {if was_empty {let first_hunk = editor.diff_hunks_in_ranges(@@ -238,7 +245,8 @@ impl AgentDiffPane {pub fn move_to_path(&self, path_key: PathKey, window: &mut Window, cx: &mut App) {if let Some(position) = self.multibuffer.read(cx).location_for_path(&path_key, cx) {- self.editor.update(cx, |editor, cx| {+ let rhs_editor = self.editor.read(cx).rhs_editor().clone();+ rhs_editor.update(cx, |editor, cx| {let first_hunk = editor.diff_hunks_in_ranges(&[position..editor::Anchor::Max],@@ -257,14 +265,16 @@ impl AgentDiffPane {}fn keep(&mut self, _: &Keep, window: &mut Window, cx: &mut Context<Self>) {- self.editor.update(cx, |editor, cx| {+ let rhs_editor = self.editor.read(cx).rhs_editor().clone();+ rhs_editor.update(cx, |editor, cx| {let snapshot = editor.buffer().read(cx).snapshot(cx);keep_edits_in_selection(editor, &snapshot, &self.thread, window, cx);});}fn reject(&mut self, _: &Reject, window: &mut Window, cx: &mut Context<Self>) {- self.editor.update(cx, |editor, cx| {+ let rhs_editor = self.editor.read(cx).rhs_editor().clone();+ rhs_editor.update(cx, |editor, cx| {let snapshot = editor.buffer().read(cx).snapshot(cx);reject_edits_in_selection(editor,@@ -278,7 +288,8 @@ impl AgentDiffPane {}fn reject_all(&mut self, _: &RejectAll, window: &mut Window, cx: &mut Context<Self>) {- self.editor.update(cx, |editor, cx| {+ let rhs_editor = self.editor.read(cx).rhs_editor().clone();+ rhs_editor.update(cx, |editor, cx| {let snapshot = editor.buffer().read(cx).snapshot(cx);reject_edits_in_ranges(editor,@@ -551,7 +562,10 @@ impl Item for AgentDiffPane {cx: &App,f: &mut dyn FnMut(gpui::EntityId, &dyn project::ProjectItem),) {- self.editor.for_each_project_item(cx, f)+ self.editor+ .read(cx)+ .rhs_editor()+ .for_each_project_item(cx, f)}fn set_nav_history(@@ -560,8 +574,10 @@ impl Item for AgentDiffPane {_: &mut Window,cx: &mut Context<Self>,) {- self.editor.update(cx, |editor, _| {- editor.set_nav_history(Some(nav_history));+ self.editor.update(cx, |editor, cx| {+ editor.rhs_editor().update(cx, |editor, _| {+ editor.set_nav_history(Some(nav_history));+ });});}@@ -628,14 +644,12 @@ impl Item for AgentDiffPane {&'a self,type_id: TypeId,self_handle: &'a Entity<Self>,- _: &'a App,+ cx: &'a App,) -> Option<gpui::AnyEntity> {if type_id == TypeId::of::<Self>() {Some(self_handle.clone().into())- } else if type_id == TypeId::of::<Editor>() {- Some(self.editor.clone().into())} else {- None+ self.editor.act_as_type(type_id, cx)}}@@ -1799,7 +1813,7 @@ mod tests {use gpui::{TestAppContext, UpdateGlobal, VisualTestContext};use project::{FakeFs, Project};use serde_json::json;- use settings::SettingsStore;+ use settings::{DiffViewStyle, SettingsStore};use std::{path::Path, rc::Rc};use util::path;use workspace::{MultiWorkspace, PathList};@@ -1809,6 +1823,11 @@ mod tests {cx.update(|cx| {let settings_store = SettingsStore::test(cx);cx.set_global(settings_store);+ SettingsStore::update_global(cx, |store, cx| {+ store.update_user_settings(cx, |settings| {+ settings.editor.diff_view_style = Some(DiffViewStyle::Unified);+ });+ });prompt_store::init(cx);theme_settings::init(theme::LoadThemes::JustBase, cx);language_model::init(cx);@@ -1847,7 +1866,7 @@ mod tests {let agent_diff = cx.new_window_entity(|window, cx| {AgentDiffPane::new(thread.clone(), workspace.downgrade(), window, cx)});- let editor = agent_diff.read_with(cx, |diff, _cx| diff.editor.clone());+ let editor = agent_diff.read_with(cx, |diff, cx| diff.editor.read(cx).rhs_editor().clone());let buffer = project.update(cx, |project, cx| project.open_buffer(buffer_path, cx))diff --git a/crates/editor/src/split.rs b/crates/editor/src/split.rsindex 0c00ca2f322..347383d0171 100644--- a/crates/editor/src/split.rs+++ b/crates/editor/src/split.rs@@ -505,6 +505,7 @@ impl SplittableEditor {editor.set_expand_all_diff_hunks(cx);editor.disable_runnables();editor.disable_inline_diagnostics();+ editor.disable_mouse_wheel_zoom();editor.set_minimap_visibility(crate::MinimapVisibility::Disabled, window, cx);editor.start_temporary_diff_override();editor@@ -600,6 +601,7 @@ impl SplittableEditor {editor.disable_lsp_data();editor.disable_runnables();editor.disable_diagnostics(cx);+ editor.disable_mouse_wheel_zoom();editor.set_minimap_visibility(crate::MinimapVisibility::Disabled, window, cx);editor});