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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1220,34 +1220,41 @@ impl EditorElement {
.collect::<HashMap<_, _>>()
});
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()
}