Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
editor: Add configurable git gutter width setting (#61304)
Evan Vinciguerra35cb7558a9d9
diff --git a/assets/settings/default.json b/assets/settings/default.jsonindex 875f65650ea..bbd1a33a0de 100644--- a/assets/settings/default.json+++ b/assets/settings/default.json@@ -695,6 +695,9 @@"folds": true,// Minimum number of characters to reserve space for in the gutter."min_line_number_digits": 4,+ // The width, in pixels, of the git diff hunk indicators in the gutter.+ // When set to null, the width scales with the buffer font size.+ "git_gutter_width": null,},"indent_guides": {// Whether to show indent guides in the editor.diff --git a/crates/editor/src/editor_settings.rs b/crates/editor/src/editor_settings.rsindex 9e6cdcd44b7..f6fdd6c16d2 100644--- a/crates/editor/src/editor_settings.rs+++ b/crates/editor/src/editor_settings.rs@@ -141,7 +141,7 @@ impl Minimap {}}-#[derive(Copy, Clone, Debug, PartialEq, Eq)]+#[derive(Copy, Clone, Debug, PartialEq)]pub struct Gutter {pub min_line_number_digits: usize,pub line_numbers: bool,@@ -149,6 +149,7 @@ pub struct Gutter {pub breakpoints: bool,pub bookmarks: bool,pub folds: bool,+ pub git_gutter_width: Option<f32>,}/// Forcefully enable or disable the scrollbar for each axis@@ -267,6 +268,7 @@ impl Settings for EditorSettings {bookmarks: gutter.bookmarks.unwrap(),breakpoints: gutter.breakpoints.unwrap(),folds: gutter.folds.unwrap(),+ git_gutter_width: gutter.git_gutter_width,},scroll_beyond_last_line: editor.scroll_beyond_last_line.unwrap(),vertical_scroll_margin: editor.vertical_scroll_margin.unwrap() as f64,diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rsindex be019873335..a5ce7bdd54c 100644--- a/crates/editor/src/element.rs+++ b/crates/editor/src/element.rs@@ -1676,6 +1676,7 @@ impl EditorElement {gutter_hitbox.bounds,hunk,snapshot,+ cx,);*hitbox = Some(window.insert_hitbox(hunk_bounds, HitboxBehavior::BlockMouse));}@@ -2669,7 +2670,7 @@ impl EditorElement {.ilog10()+ 1;- let git_gutter_width = Self::gutter_strip_width(line_height)+ let git_gutter_width = Self::gutter_strip_width(line_height, cx)+ gutter_dimensions.git_blame_entries_width.unwrap_or_default();@@ -5228,6 +5229,7 @@ impl EditorElement {layout.gutter_hitbox.bounds,hunk,&layout.position_map.snapshot,+ cx,);Some((hunk_bounds,@@ -5313,8 +5315,11 @@ impl EditorElement {});}- fn gutter_strip_width(line_height: Pixels) -> Pixels {- (0.275 * line_height).floor()+ fn gutter_strip_width(line_height: Pixels, cx: &App) -> Pixels {+ match EditorSettings::get_global(cx).gutter.git_gutter_width {+ Some(width) => px(width),+ None => (0.275 * line_height).floor(),+ }}fn diff_hunk_bounds(@@ -5323,9 +5328,10 @@ impl EditorElement {gutter_bounds: Bounds<Pixels>,hunk: &DisplayDiffHunk,snapshot: &EditorSnapshot,+ cx: &App,) -> Bounds<Pixels> {let scroll_top = scroll_position.y * ScrollPixelOffset::from(line_height);- let gutter_strip_width = Self::gutter_strip_width(line_height);+ let gutter_strip_width = Self::gutter_strip_width(line_height, cx);match hunk {DisplayDiffHunk::Folded { display_row, .. } => {@@ -5351,7 +5357,10 @@ impl EditorElement {.into();let end_y = start_y + line_height;- let width = (0.35 * line_height).floor();+ let width = match EditorSettings::get_global(cx).gutter.git_gutter_width {+ Some(width) => px(width),+ None => (0.35 * line_height).floor(),+ };let highlight_origin = gutter_bounds.origin + point(px(0.), start_y);let highlight_size = size(width, end_y - start_y);Bounds::new(highlight_origin, highlight_size)@@ -6720,7 +6729,7 @@ impl Gutter<'_> {AvailableSpace::Definite(self.line_height),);let indicator_size = button.layout_as_root(available_space, window, cx);- let git_gutter_width = EditorElement::gutter_strip_width(self.line_height)+ let git_gutter_width = EditorElement::gutter_strip_width(self.line_height, cx)+ self.dimensions.git_blame_entries_width.unwrap_or_default();let x = git_gutter_width + px(2.);@@ -9148,7 +9157,7 @@ impl Element for EditorElement {);}- let git_gutter_width = Self::gutter_strip_width(line_height)+ let git_gutter_width = Self::gutter_strip_width(line_height, cx)+ gutter_dimensions.git_blame_entries_width.unwrap_or_default();diff --git a/crates/settings/src/vscode_import.rs b/crates/settings/src/vscode_import.rsindex 24072a291b4..652748eda09 100644--- a/crates/settings/src/vscode_import.rs+++ b/crates/settings/src/vscode_import.rs@@ -350,6 +350,7 @@ impl VsCodeSettings {"never" => Some(false),_ => None,}),+ git_gutter_width: None,})}diff --git a/crates/settings_content/src/editor.rs b/crates/settings_content/src/editor.rsindex 14a594236a4..52ff2fa10e1 100644--- a/crates/settings_content/src/editor.rs+++ b/crates/settings_content/src/editor.rs@@ -483,7 +483,7 @@ pub struct ScrollbarAxesContent {/// Gutter related settings#[with_fallible_options]-#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq)]+#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)]pub struct GutterContent {/// Whether to show line numbers in the gutter.///@@ -509,6 +509,11 @@ pub struct GutterContent {////// Default: truepub folds: Option<bool>,+ /// The width, in pixels, of the git diff hunk indicators in the gutter.+ /// When unset, the width scales with the buffer font size.+ ///+ /// Default: null+ pub git_gutter_width: Option<f32>,}/// Whether to display code lenses from language servers above code elements.diff --git a/crates/settings_ui/src/page_data.rs b/crates/settings_ui/src/page_data.rsindex 5da60174a8e..a1b905fe18b 100644--- a/crates/settings_ui/src/page_data.rs+++ b/crates/settings_ui/src/page_data.rs@@ -2182,7 +2182,7 @@ fn editor_page() -> SettingsPage {]}- fn gutter_section() -> [SettingsPageItem; 9] {+ fn gutter_section() -> [SettingsPageItem; 10] {[SettingsPageItem::SectionHeader("Gutter"),SettingsPageItem::SettingItem(SettingItem {@@ -2339,6 +2339,30 @@ fn editor_page() -> SettingsPage {metadata: None,files: USER,}),+ SettingsPageItem::SettingItem(SettingItem {+ title: "Git Gutter Width",+ description: "Width, in pixels, of the git diff indicators in the gutter. When unset, the width scales with the buffer font size.",+ field: Box::new(SettingField {+ organization_override: None,+ json_path: Some("gutter.git_gutter_width"),+ pick: |settings_content| {+ settings_content+ .editor+ .gutter+ .as_ref()+ .and_then(|gutter| gutter.git_gutter_width.as_ref())+ },+ write: |settings_content, value, _| {+ settings_content+ .editor+ .gutter+ .get_or_insert_default()+ .git_gutter_width = value;+ },+ }),+ metadata: None,+ files: USER,+ }),SettingsPageItem::SettingItem(SettingItem {title: "Inline Code Actions",description: "Show code action button at start of buffer line.",diff --git a/docs/src/reference/all-settings.md b/docs/src/reference/all-settings.mdindex a141d1b3db6..b0bf79dbe20 100644--- a/docs/src/reference/all-settings.md+++ b/docs/src/reference/all-settings.md@@ -838,7 +838,8 @@ List of `string` values"runnables": true,"breakpoints": true,"folds": true,- "min_line_number_digits": 4+ "min_line_number_digits": 4,+ "git_gutter_width": null}}```@@ -850,6 +851,7 @@ List of `string` values- `breakpoints`: Whether to show breakpoints in the gutter- `folds`: Whether to show fold buttons in the gutter- `min_line_number_digits`: Minimum number of characters to reserve space for in the gutter+- `git_gutter_width`: The width, in pixels, of the git diff hunk indicators in the gutter. When `null`, the width scales with the buffer font size## Hide Mouse