Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Make minimum width for line numbers in gutter configurable (#31959)

Max Mynter7d5a5d09841e
diff --git a/assets/settings/default.json b/assets/settings/default.json
index 939f79e2812..98f3585f473 100644
--- a/assets/settings/default.json
+++ b/assets/settings/default.json
@@ -445,7 +445,9 @@
// Whether to show breakpoints in the gutter.
"breakpoints": true,
// Whether to show fold buttons in the gutter.
- "folds": true
+ "folds": true,
+ // Minimum number of characters to reserve space for in the gutter.
+ "min_line_number_digits": 4
},
"indent_guides": {
// Whether to show indent guides in the editor.
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs
index 412333f15f1..7215a9e0a25 100644
--- a/crates/editor/src/editor.rs
+++ b/crates/editor/src/editor.rs
@@ -240,7 +240,6 @@ pub(crate) const SCROLL_CENTER_TOP_BOTTOM_DEBOUNCE_TIMEOUT: Duration = Duration:
pub(crate) const EDIT_PREDICTION_KEY_CONTEXT: &str = "edit_prediction";
pub(crate) const EDIT_PREDICTION_CONFLICT_KEY_CONTEXT: &str = "edit_prediction_conflict";
-pub(crate) const MIN_LINE_NUMBER_DIGITS: u32 = 4;
pub(crate) const MINIMAP_FONT_SIZE: AbsoluteLength = AbsoluteLength::Pixels(px(2.));
pub type RenderDiffHunkControlsFn = Arc<
@@ -21558,7 +21557,8 @@ impl EditorSnapshot {
.unwrap_or(gutter_settings.line_numbers);
let line_gutter_width = if show_line_numbers {
// Avoid flicker-like gutter resizes when the line number gains another digit and only resize the gutter on files with N*10^5 lines.
- let min_width_for_number_on_gutter = em_advance * MIN_LINE_NUMBER_DIGITS as f32;
+ let min_width_for_number_on_gutter =
+ em_advance * gutter_settings.min_line_number_digits as f32;
max_line_number_width.max(min_width_for_number_on_gutter)
} else {
0.0.into()
diff --git a/crates/editor/src/editor_settings.rs b/crates/editor/src/editor_settings.rs
index 803587a923c..44e220f90d8 100644
--- a/crates/editor/src/editor_settings.rs
+++ b/crates/editor/src/editor_settings.rs
@@ -150,6 +150,7 @@ impl Minimap {
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
pub struct Gutter {
+ pub min_line_number_digits: usize,
pub line_numbers: bool,
pub runnables: bool,
pub breakpoints: bool,
@@ -609,6 +610,10 @@ pub struct GutterContent {
///
/// Default: true
pub line_numbers: Option<bool>,
+ /// Minimum number of characters to reserve space for in the gutter.
+ ///
+ /// Default: 4
+ pub min_line_number_digits: Option<usize>,
/// Whether to show runnable buttons in the gutter.
///
/// Default: true
diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs
index 36bad300050..1f820162d44 100644
--- a/crates/editor/src/element.rs
+++ b/crates/editor/src/element.rs
@@ -6,10 +6,10 @@ use crate::{
Editor, EditorMode, EditorSettings, EditorSnapshot, EditorStyle, FILE_HEADER_HEIGHT,
FocusedBlock, GutterDimensions, HalfPageDown, HalfPageUp, HandleInput, HoveredCursor,
InlayHintRefreshReason, InlineCompletion, JumpData, LineDown, LineHighlight, LineUp,
- MAX_LINE_LEN, MIN_LINE_NUMBER_DIGITS, MINIMAP_FONT_SIZE, MULTI_BUFFER_EXCERPT_HEADER_HEIGHT,
- OpenExcerpts, PageDown, PageUp, PhantomBreakpointIndicator, Point, RowExt, RowRangeExt,
- SelectPhase, SelectedTextHighlight, Selection, SelectionDragState, SoftWrap,
- StickyHeaderExcerpt, ToPoint, ToggleFold,
+ MAX_LINE_LEN, MINIMAP_FONT_SIZE, MULTI_BUFFER_EXCERPT_HEADER_HEIGHT, OpenExcerpts, PageDown,
+ PageUp, PhantomBreakpointIndicator, Point, RowExt, RowRangeExt, SelectPhase,
+ SelectedTextHighlight, Selection, SelectionDragState, SoftWrap, StickyHeaderExcerpt, ToPoint,
+ ToggleFold,
code_context_menus::{CodeActionsMenu, MENU_ASIDE_MAX_WIDTH, MENU_ASIDE_MIN_WIDTH, MENU_GAP},
display_map::{
Block, BlockContext, BlockStyle, DisplaySnapshot, EditorMargins, FoldId, HighlightedChunk,
@@ -2826,7 +2826,8 @@ impl EditorElement {
let available_width = gutter_dimensions.left_padding - git_gutter_width;
let editor = self.editor.clone();
- let is_wide = max_line_number_length >= MIN_LINE_NUMBER_DIGITS
+ let is_wide = max_line_number_length
+ >= EditorSettings::get_global(cx).gutter.min_line_number_digits as u32
&& row_info
.buffer_row
.is_some_and(|row| (row + 1).ilog10() + 1 == max_line_number_length)