diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 48cf3ba0639483f56c674b1c1e3a551871319ed0..732449f6d7f53eeb020f7895df795e4d79fcce2d 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -27095,12 +27095,20 @@ impl EditorSnapshot { self.buffer_snapshot() .diff_hunks_in_range(buffer_start..buffer_end) .filter_map(|hunk| { - if folded_buffers.contains(&hunk.buffer_id) { + if folded_buffers.contains(&hunk.buffer_id) + || (hunk.row_range.is_empty() && self.buffer.all_diff_hunks_expanded()) + { return None; } let hunk_start_point = Point::new(hunk.row_range.start.0, 0); - let hunk_end_point = Point::new(hunk.row_range.end.0, 0); + let hunk_end_point = if hunk.row_range.end > hunk.row_range.start { + let last_row = MultiBufferRow(hunk.row_range.end.0 - 1); + let line_len = self.buffer_snapshot().line_len(last_row); + Point::new(last_row.0, line_len) + } else { + Point::new(hunk.row_range.end.0, 0) + }; let hunk_display_start = self.point_to_display_point(hunk_start_point, Bias::Left); let hunk_display_end = self.point_to_display_point(hunk_end_point, Bias::Right); @@ -27111,7 +27119,7 @@ impl EditorSnapshot { } } else { let mut end_row = hunk_display_end.row(); - if hunk_display_end.column() > 0 { + if hunk.row_range.end > hunk.row_range.start || hunk_display_end.column() > 0 { end_row.0 += 1; } let is_created_file = hunk.is_created_file(); diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index d516de75d98be94b000a673548e546e5e2adac92..229e8dc1dabfb425078abd4650d07dbd525986c5 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -6077,7 +6077,12 @@ impl EditorElement { } } - fn paint_gutter_diff_hunks(layout: &mut EditorLayout, window: &mut Window, cx: &mut App) { + fn paint_gutter_diff_hunks( + layout: &mut EditorLayout, + split_side: Option, + window: &mut Window, + cx: &mut App, + ) { if layout.display_hunks.is_empty() { return; } @@ -6104,37 +6109,37 @@ impl EditorElement { status, display_row_range, .. - } => hitbox.as_ref().map(|hunk_hitbox| match status.kind { - DiffHunkStatusKind::Added => ( - hunk_hitbox.bounds, - cx.theme().colors().version_control_added, - Corners::all(px(0.)), - *status, - ), - DiffHunkStatusKind::Modified => ( - hunk_hitbox.bounds, - cx.theme().colors().version_control_modified, - Corners::all(px(0.)), - *status, - ), - DiffHunkStatusKind::Deleted if !display_row_range.is_empty() => ( - hunk_hitbox.bounds, - cx.theme().colors().version_control_deleted, - Corners::all(px(0.)), - *status, - ), - DiffHunkStatusKind::Deleted => ( - Bounds::new( - point( - hunk_hitbox.origin.x - hunk_hitbox.size.width, - hunk_hitbox.origin.y, + } => hitbox.as_ref().map(|hunk_hitbox| { + let color = match split_side { + Some(SplitSide::Left) => cx.theme().colors().version_control_deleted, + Some(SplitSide::Right) => cx.theme().colors().version_control_added, + None => match status.kind { + DiffHunkStatusKind::Added => { + cx.theme().colors().version_control_added + } + DiffHunkStatusKind::Modified => { + cx.theme().colors().version_control_modified + } + DiffHunkStatusKind::Deleted => { + cx.theme().colors().version_control_deleted + } + }, + }; + match status.kind { + DiffHunkStatusKind::Deleted if display_row_range.is_empty() => ( + Bounds::new( + point( + hunk_hitbox.origin.x - hunk_hitbox.size.width, + hunk_hitbox.origin.y, + ), + size(hunk_hitbox.size.width * 2., hunk_hitbox.size.height), ), - size(hunk_hitbox.size.width * 2., hunk_hitbox.size.height), + color, + Corners::all(1. * line_height), + *status, ), - cx.theme().colors().version_control_deleted, - Corners::all(1. * line_height), - *status, - ), + _ => (hunk_hitbox.bounds, color, Corners::all(px(0.)), *status), + } }), }; @@ -6320,8 +6325,8 @@ impl EditorElement { GitGutterSetting::TrackedFiles ) }); - if show_git_gutter && self.split_side.is_none() { - Self::paint_gutter_diff_hunks(layout, window, cx) + if show_git_gutter { + Self::paint_gutter_diff_hunks(layout, self.split_side, window, cx) } let highlight_width = 0.275 * layout.position_map.line_height; diff --git a/crates/multi_buffer/src/multi_buffer.rs b/crates/multi_buffer/src/multi_buffer.rs index 842dd78a1a94f608132657670d4599943b4b1429..9b66666e75ed577d4b988dc9498d36f172846d30 100644 --- a/crates/multi_buffer/src/multi_buffer.rs +++ b/crates/multi_buffer/src/multi_buffer.rs @@ -6807,6 +6807,10 @@ impl MultiBufferSnapshot { self.diffs.get(&buffer_id).map(|diff| &diff.diff) } + pub fn all_diff_hunks_expanded(&self) -> bool { + self.all_diff_hunks_expanded + } + /// Visually annotates a position or range with the `Debug` representation of a value. The /// callsite of this function is used as a key - previous annotations will be removed. #[cfg(debug_assertions)]