From 52c963df1d5db578e713f0435d66910cd2001090 Mon Sep 17 00:00:00 2001 From: Cole Miller Date: Wed, 4 Feb 2026 12:07:46 -0500 Subject: [PATCH] git: Ensure the sides of the side-by-side diff use the same hunk controls (#48376) Fixes hunk controls appearing on the LHS of the branch diff when they should be disabled Release Notes: - N/A --- crates/editor/src/split.rs | 25 ++++++++++++++++++++++++- crates/git_ui/src/project_diff.rs | 11 +++++++---- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/crates/editor/src/split.rs b/crates/editor/src/split.rs index 14ca7e7f652531536315a6d1d088ac3215979070..f4236a1ab15dc63f690b6b1026567f07d6614314 100644 --- a/crates/editor/src/split.rs +++ b/crates/editor/src/split.rs @@ -25,7 +25,8 @@ use crate::{ use workspace::{ActivatePaneLeft, ActivatePaneRight, Item, Workspace}; use crate::{ - Autoscroll, DisplayMap, Editor, EditorEvent, ToggleCodeActions, ToggleSoftWrap, + Autoscroll, DisplayMap, Editor, EditorEvent, RenderDiffHunkControlsFn, ToggleCodeActions, + ToggleSoftWrap, actions::{DisableBreakpoint, EditLogBreakpoint, EnableBreakpoint, ToggleBreakpoint}, display_map::Companion, }; @@ -308,6 +309,22 @@ impl SplittableEditor { self.lhs.is_some() } + pub fn set_render_diff_hunk_controls( + &self, + render_diff_hunk_controls: RenderDiffHunkControlsFn, + cx: &mut Context, + ) { + self.rhs_editor.update(cx, |editor, cx| { + editor.set_render_diff_hunk_controls(render_diff_hunk_controls.clone(), cx); + }); + + if let Some(lhs) = &self.lhs { + lhs.editor.update(cx, |editor, cx| { + editor.set_render_diff_hunk_controls(render_diff_hunk_controls.clone(), cx); + }); + } + } + pub fn last_selected_editor(&self) -> &Entity { if let Some(lhs) = &self.lhs && lhs.has_latest_selection @@ -395,6 +412,8 @@ impl SplittableEditor { multibuffer.set_all_diff_hunks_expanded(cx); multibuffer }); + + let render_diff_hunk_controls = self.rhs_editor.read(cx).render_diff_hunk_controls.clone(); let lhs_editor = cx.new(|cx| { let mut editor = Editor::for_multibuffer(lhs_multibuffer.clone(), Some(project.clone()), window, cx); @@ -406,6 +425,10 @@ impl SplittableEditor { editor }); + lhs_editor.update(cx, |editor, cx| { + editor.set_render_diff_hunk_controls(render_diff_hunk_controls, cx); + }); + let subscriptions = vec![cx.subscribe( &lhs_editor, diff --git a/crates/git_ui/src/project_diff.rs b/crates/git_ui/src/project_diff.rs index a1239ae37a89881b45c78e5699ae890f07275e88..cb9310d6ed43dd38a6e341344fda266dce624377 100644 --- a/crates/git_ui/src/project_diff.rs +++ b/crates/git_ui/src/project_diff.rs @@ -288,6 +288,13 @@ impl ProjectDiff { window, cx, ); + match branch_diff.read(cx).diff_base() { + DiffBase::Head => {} + DiffBase::Merge { .. } => diff_display_editor.set_render_diff_hunk_controls( + Arc::new(|_, _, _, _, _, _, _, _| gpui::Empty.into_any_element()), + cx, + ), + } diff_display_editor.rhs_editor().update(cx, |editor, cx| { editor.disable_diagnostics(cx); editor.set_show_diff_review_button(true, cx); @@ -303,10 +310,6 @@ impl ProjectDiff { branch_diff: branch_diff.clone(), }); editor.start_temporary_diff_override(); - editor.set_render_diff_hunk_controls( - Arc::new(|_, _, _, _, _, _, _, _| gpui::Empty.into_any_element()), - cx, - ); } } });