Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Add `git.hunk_style` setting for gutter hollow hunk behavior (#26816)
Jakub Charvat65994c057683
diff --git a/assets/settings/default.json b/assets/settings/default.jsonindex 5e5930ea30f..800c2761230 100644--- a/assets/settings/default.json+++ b/assets/settings/default.json@@ -850,7 +850,15 @@//// The minimum column number to show the inline blame information at// "min_column": 0- }+ },+ // How git hunks are displayed visually in the editor.+ // This setting can take two values:+ //+ // 1. Show unstaged hunks filled and staged hunks hollow:+ // "hunk_style": "staged_hollow"+ // 2. Show unstaged hunks hollow and staged hunks filled:+ // "hunk_style": "unstaged_hollow"+ "hunk_style": "staged_hollow"},// The list of custom Git hosting providers."git_hosting_providers": [diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rsindex 18036140289..f3a9c33ca70 100644--- a/crates/editor/src/element.rs+++ b/crates/editor/src/element.rs@@ -55,7 +55,7 @@ use multi_buffer::{Anchor, ExcerptId, ExcerptInfo, ExpandExcerptDirection, ExpandInfo, MultiBufferPoint,MultiBufferRow, RowInfo,};-use project::project_settings::{self, GitGutterSetting, ProjectSettings};+use project::project_settings::{self, GitGutterSetting, GitHunkStyleSetting, ProjectSettings};use settings::Settings;use smallvec::{smallvec, SmallVec};use std::{@@ -4379,8 +4379,6 @@ impl EditorElement {};if let Some((hunk_bounds, background_color, corner_radii, status)) = hunk_to_paint {- let unstaged = status.has_secondary_hunk();-// Flatten the background color with the editor color to prevent// elements below transparent hunks from showing throughlet flattened_background_color = cx@@ -4389,7 +4387,7 @@ impl EditorElement {.editor_background.blend(background_color);- if unstaged {+ if !Self::diff_hunk_hollow(status, cx) {window.paint_quad(quad(hunk_bounds,corner_radii,@@ -5622,6 +5620,18 @@ impl EditorElement {&[run],)}++ fn diff_hunk_hollow(status: DiffHunkStatus, cx: &mut App) -> bool {+ let unstaged = status.has_secondary_hunk();+ let unstaged_hollow = ProjectSettings::get_global(cx)+ .git+ .hunk_style+ .map_or(false, |style| {+ matches!(style, GitHunkStyleSetting::UnstagedHollow)+ });++ unstaged == unstaged_hollow+ }}fn header_jump_data(@@ -6773,10 +6783,9 @@ impl Element for EditorElement {}};- let unstaged = diff_status.has_secondary_hunk();let hunk_opacity = if is_light { 0.16 } else { 0.12 };- let staged_highlight = LineHighlight {+ let hollow_highlight = LineHighlight {background: (background_color.opacity(if is_light {0.08} else {@@ -6790,13 +6799,13 @@ impl Element for EditorElement {}),};- let unstaged_highlight =+ let filled_highlight =solid_background(background_color.opacity(hunk_opacity)).into();- let background = if unstaged {- unstaged_highlight+ let background = if Self::diff_hunk_hollow(diff_status, cx) {+ hollow_highlight} else {- staged_highlight+ filled_highlight};highlighted_rowsdiff --git a/crates/project/src/project_settings.rs b/crates/project/src/project_settings.rsindex 4574be5d15e..d9fc6cefee3 100644--- a/crates/project/src/project_settings.rs+++ b/crates/project/src/project_settings.rs@@ -168,6 +168,10 @@ pub struct GitSettings {////// Default: onpub inline_blame: Option<InlineBlameSettings>,+ /// How hunks are displayed visually in the editor.+ ///+ /// Default: staged_hollow+ pub hunk_style: Option<GitHunkStyleSetting>,}impl GitSettings {@@ -203,20 +207,11 @@ impl GitSettings {#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema)]#[serde(rename_all = "snake_case")]pub enum GitHunkStyleSetting {- /// Show unstaged hunks with a transparent background+ /// Show unstaged hunks with a filled background and staged hunks hollow.#[default]- Transparent,- /// Show unstaged hunks with a pattern background- Pattern,- /// Show unstaged hunks with a border background- Border,-- /// Show staged hunks with a pattern background- StagedPattern,- /// Show staged hunks with a pattern background- StagedTransparent,- /// Show staged hunks with a pattern background- StagedBorder,+ StagedHollow,+ /// Show unstaged hunks hollow and staged hunks with a filled background.+ UnstagedHollow,}#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema)]