From ad2ddf12008ffc674eade95d164d95d34d2cc1d8 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Wed, 5 Jun 2024 10:05:53 +0300 Subject: [PATCH] Omit clickable hunks when git hunks are disabled in the gutter (#12671) Closes https://github.com/zed-industries/zed/issues/12644 https://github.com/zed-industries/zed/pull/12425 fixes the issue so that clicks are never reaching the hunks' hitboxes in such case, this PR actually removes those hitboxes. Hunks can still be toggled via the action. Release Notes: - N/A --- crates/editor/src/element.rs | 53 ++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 3abb250efb..87eab4d068 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -1220,34 +1220,41 @@ impl EditorElement { .collect::>() }); + let git_gutter_setting = ProjectSettings::get_global(cx) + .git + .git_gutter + .unwrap_or_default(); buffer_snapshot .git_diff_hunks_in_range(buffer_start_row..buffer_end_row) .map(|hunk| diff_hunk_to_display(&hunk, snapshot)) .dedup() - .map(|hunk| { - let hitbox = if let DisplayDiffHunk::Unfolded { - display_row_range, .. - } = &hunk - { - let was_expanded = expanded_hunk_display_rows - .get(&display_row_range.start) - .map(|expanded_end_row| expanded_end_row == &display_row_range.end) - .unwrap_or(false); - if was_expanded { - None + .map(|hunk| match git_gutter_setting { + GitGutterSetting::TrackedFiles => { + let hitbox = if let DisplayDiffHunk::Unfolded { + display_row_range, .. + } = &hunk + { + let was_expanded = expanded_hunk_display_rows + .get(&display_row_range.start) + .map(|expanded_end_row| expanded_end_row == &display_row_range.end) + .unwrap_or(false); + if was_expanded { + None + } else { + let hunk_bounds = Self::diff_hunk_bounds( + &snapshot, + line_height, + gutter_hitbox.bounds, + &hunk, + ); + Some(cx.insert_hitbox(hunk_bounds, true)) + } } else { - let hunk_bounds = Self::diff_hunk_bounds( - &snapshot, - line_height, - gutter_hitbox.bounds, - &hunk, - ); - Some(cx.insert_hitbox(hunk_bounds, true)) - } - } else { - None - }; - (hunk, hitbox) + None + }; + (hunk, hitbox) + } + GitGutterSetting::Hide => (hunk, None), }) .collect() }