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
This commit is contained in:
Kirill Bulatov
2024-06-05 10:05:53 +03:00
committed by GitHub
parent d6e271c956
commit ad2ddf1200
+30 -23
View File
@@ -1220,34 +1220,41 @@ impl EditorElement {
.collect::<HashMap<_, _>>() .collect::<HashMap<_, _>>()
}); });
let git_gutter_setting = ProjectSettings::get_global(cx)
.git
.git_gutter
.unwrap_or_default();
buffer_snapshot buffer_snapshot
.git_diff_hunks_in_range(buffer_start_row..buffer_end_row) .git_diff_hunks_in_range(buffer_start_row..buffer_end_row)
.map(|hunk| diff_hunk_to_display(&hunk, snapshot)) .map(|hunk| diff_hunk_to_display(&hunk, snapshot))
.dedup() .dedup()
.map(|hunk| { .map(|hunk| match git_gutter_setting {
let hitbox = if let DisplayDiffHunk::Unfolded { GitGutterSetting::TrackedFiles => {
display_row_range, .. let hitbox = if let DisplayDiffHunk::Unfolded {
} = &hunk display_row_range, ..
{ } = &hunk
let was_expanded = expanded_hunk_display_rows {
.get(&display_row_range.start) let was_expanded = expanded_hunk_display_rows
.map(|expanded_end_row| expanded_end_row == &display_row_range.end) .get(&display_row_range.start)
.unwrap_or(false); .map(|expanded_end_row| expanded_end_row == &display_row_range.end)
if was_expanded { .unwrap_or(false);
None 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 { } else {
let hunk_bounds = Self::diff_hunk_bounds( None
&snapshot, };
line_height, (hunk, hitbox)
gutter_hitbox.bounds, }
&hunk, GitGutterSetting::Hide => (hunk, None),
);
Some(cx.insert_hitbox(hunk_bounds, true))
}
} else {
None
};
(hunk, hitbox)
}) })
.collect() .collect()
} }