git: Remove hunk style setting (#26504)

This commit is contained in:
Cole Miller 2025-03-12 00:35:34 -04:00 committed by GitHub
parent d6255fb3d2
commit 2cd970f137
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 25 additions and 116 deletions

View file

@ -837,15 +837,7 @@
// //
// The minimum column number to show the inline blame information at // The minimum column number to show the inline blame information at
// "min_column": 0 // "min_column": 0
}, }
// How git hunks are displayed visually in the editor.
// This setting can take two values:
//
// 1. Show unstaged hunks with a transparent background (default):
// "hunk_style": "transparent"
// 2. Show unstaged hunks with a pattern background:
// "hunk_style": "pattern"
"hunk_style": "staged_border"
}, },
// Configuration for how direnv configuration should be loaded. May take 2 values: // Configuration for how direnv configuration should be loaded. May take 2 values:
// 1. Load direnv configuration using `direnv export json` directly. // 1. Load direnv configuration using `direnv export json` directly.

View file

@ -32,15 +32,14 @@ use collections::{BTreeMap, HashMap, HashSet};
use file_icons::FileIcons; use file_icons::FileIcons;
use git::{blame::BlameEntry, status::FileStatus, Oid}; use git::{blame::BlameEntry, status::FileStatus, Oid};
use gpui::{ use gpui::{
anchored, deferred, div, fill, linear_color_stop, linear_gradient, outline, pattern_slash, anchored, deferred, div, fill, linear_color_stop, linear_gradient, outline, point, px, quad,
point, px, quad, relative, size, solid_background, svg, transparent_black, Action, AnyElement, relative, size, solid_background, svg, transparent_black, Action, AnyElement, App,
App, AvailableSpace, Axis, Bounds, ClickEvent, ClipboardItem, ContentMask, Context, Corner, AvailableSpace, Axis, Bounds, ClickEvent, ClipboardItem, ContentMask, Context, Corner, Corners,
Corners, CursorStyle, DispatchPhase, Edges, Element, ElementInputHandler, Entity, CursorStyle, DispatchPhase, Edges, Element, ElementInputHandler, Entity, Focusable as _,
Focusable as _, FontId, GlobalElementId, Hitbox, Hsla, InteractiveElement, IntoElement, FontId, GlobalElementId, Hitbox, Hsla, InteractiveElement, IntoElement, Keystroke, Length,
Keystroke, Length, ModifiersChangedEvent, MouseButton, MouseDownEvent, MouseMoveEvent, ModifiersChangedEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, PaintQuad,
MouseUpEvent, PaintQuad, ParentElement, Pixels, ScrollDelta, ScrollWheelEvent, ShapedLine, ParentElement, Pixels, ScrollDelta, ScrollWheelEvent, ShapedLine, SharedString, Size,
SharedString, Size, StatefulInteractiveElement, Style, Styled, Subscription, TextRun, StatefulInteractiveElement, Style, Styled, Subscription, TextRun, TextStyleRefinement, Window,
TextStyleRefinement, Window,
}; };
use inline_completion::Direction; use inline_completion::Direction;
use itertools::Itertools; use itertools::Itertools;
@ -56,7 +55,7 @@ use multi_buffer::{
Anchor, ExcerptId, ExcerptInfo, ExpandExcerptDirection, MultiBufferPoint, MultiBufferRow, Anchor, ExcerptId, ExcerptInfo, ExpandExcerptDirection, MultiBufferPoint, MultiBufferRow,
RowInfo, RowInfo,
}; };
use project::project_settings::{self, GitGutterSetting, GitHunkStyleSetting, ProjectSettings}; use project::project_settings::{self, GitGutterSetting, ProjectSettings};
use settings::Settings; use settings::Settings;
use smallvec::{smallvec, SmallVec}; use smallvec::{smallvec, SmallVec};
use std::{ use std::{
@ -4356,13 +4355,6 @@ impl EditorElement {
} }
fn paint_gutter_diff_hunks(layout: &mut EditorLayout, window: &mut Window, cx: &mut App) { fn paint_gutter_diff_hunks(layout: &mut EditorLayout, window: &mut Window, cx: &mut App) {
let is_light = cx.theme().appearance().is_light();
let hunk_style = ProjectSettings::get_global(cx)
.git
.hunk_style
.unwrap_or_default();
if layout.display_hunks.is_empty() { if layout.display_hunks.is_empty() {
return; return;
} }
@ -4423,28 +4415,7 @@ impl EditorElement {
}), }),
}; };
if let Some((hunk_bounds, mut background_color, corner_radii, secondary_status)) = if let Some((hunk_bounds, background_color, corner_radii, _)) = hunk_to_paint {
hunk_to_paint
{
match hunk_style {
GitHunkStyleSetting::Transparent | GitHunkStyleSetting::Pattern => {
if secondary_status.has_secondary_hunk() {
background_color =
background_color.opacity(if is_light { 0.2 } else { 0.32 });
}
}
GitHunkStyleSetting::StagedPattern
| GitHunkStyleSetting::StagedTransparent => {
if !secondary_status.has_secondary_hunk() {
background_color =
background_color.opacity(if is_light { 0.2 } else { 0.32 });
}
}
GitHunkStyleSetting::StagedBorder | GitHunkStyleSetting::Border => {
// Don't change the background color
}
}
// Flatten the background color with the editor color to prevent // Flatten the background color with the editor color to prevent
// elements below transparent hunks from showing through // elements below transparent hunks from showing through
let flattened_background_color = cx let flattened_background_color = cx
@ -6798,10 +6769,6 @@ impl Element for EditorElement {
.update(cx, |editor, cx| editor.highlighted_display_rows(window, cx)); .update(cx, |editor, cx| editor.highlighted_display_rows(window, cx));
let is_light = cx.theme().appearance().is_light(); let is_light = cx.theme().appearance().is_light();
let hunk_style = ProjectSettings::get_global(cx)
.git
.hunk_style
.unwrap_or_default();
for (ix, row_info) in row_infos.iter().enumerate() { for (ix, row_info) in row_infos.iter().enumerate() {
let Some(diff_status) = row_info.diff_status else { let Some(diff_status) = row_info.diff_status else {
@ -6821,69 +6788,23 @@ impl Element for EditorElement {
let unstaged = diff_status.has_secondary_hunk(); let unstaged = diff_status.has_secondary_hunk();
let hunk_opacity = if is_light { 0.16 } else { 0.12 }; let hunk_opacity = if is_light { 0.16 } else { 0.12 };
let slash_width = line_height.0 / 1.5; // ~16 by default
let staged_highlight: LineHighlight = match hunk_style { let staged_highlight = LineHighlight {
GitHunkStyleSetting::Transparent background: (background_color.opacity(if is_light {
| GitHunkStyleSetting::Pattern 0.08
| GitHunkStyleSetting::Border => { } else {
solid_background(background_color.opacity(hunk_opacity)).into() 0.06
} }))
GitHunkStyleSetting::StagedPattern => { .into(),
pattern_slash(background_color.opacity(hunk_opacity), slash_width) border: Some(if is_light {
.into() background_color.opacity(0.48)
} } else {
GitHunkStyleSetting::StagedTransparent => { background_color.opacity(0.36)
solid_background(background_color.opacity(if is_light { }),
0.08
} else {
0.04
}))
.into()
}
GitHunkStyleSetting::StagedBorder => LineHighlight {
background: (background_color.opacity(if is_light {
0.08
} else {
0.06
}))
.into(),
border: Some(if is_light {
background_color.opacity(0.48)
} else {
background_color.opacity(0.36)
}),
},
}; };
let unstaged_highlight = match hunk_style { let unstaged_highlight =
GitHunkStyleSetting::Transparent => { solid_background(background_color.opacity(hunk_opacity)).into();
solid_background(background_color.opacity(if is_light {
0.08
} else {
0.04
}))
.into()
}
GitHunkStyleSetting::Pattern => {
pattern_slash(background_color.opacity(hunk_opacity), slash_width)
.into()
}
GitHunkStyleSetting::Border => LineHighlight {
background: (background_color.opacity(if is_light {
0.08
} else {
0.02
}))
.into(),
border: Some(background_color.opacity(0.5)),
},
GitHunkStyleSetting::StagedPattern
| GitHunkStyleSetting::StagedTransparent
| GitHunkStyleSetting::StagedBorder => {
solid_background(background_color.opacity(hunk_opacity)).into()
}
};
let background = if unstaged { let background = if unstaged {
unstaged_highlight unstaged_highlight

View file

@ -168,10 +168,6 @@ pub struct GitSettings {
/// ///
/// Default: on /// Default: on
pub inline_blame: Option<InlineBlameSettings>, pub inline_blame: Option<InlineBlameSettings>,
/// How hunks are displayed visually in the editor.
///
/// Default: transparent
pub hunk_style: Option<GitHunkStyleSetting>,
} }
impl GitSettings { impl GitSettings {