Omit clickable hunks when git hunks are disabled in the gutter (#12671)
Kirill Bulatov
created 2 years ago
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
Change summary
crates/editor/src/element.rs | 53 +++++++++++++++++++++----------------
1 file changed, 30 insertions(+), 23 deletions(-)
Detailed changes
@@ -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()
}