Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix minimum gutter line number spacing (#18021)
Galen Elias1a4f9b289130
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex 730482b123b..102e94f1abb 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -12956,6 +12956,7 @@ impl EditorSnapshot {font_id: FontId,font_size: Pixels,em_width: Pixels,+ em_advance: Pixels,max_line_number_width: Pixels,cx: &AppContext,) -> GutterDimensions {@@ -12976,7 +12977,7 @@ 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_width * 4.0;+ let min_width_for_number_on_gutter = em_advance * 4.0;max_line_number_width.max(min_width_for_number_on_gutter)} else {0.0.into()diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rsindex 9fe05bc4f26..f5db7b94ba8 100644--- a/crates/editor/src/element.rs+++ b/crates/editor/src/element.rs@@ -4970,6 +4970,7 @@ impl Element for EditorElement {font_id,font_size,em_width,+ em_advance,self.max_line_number_width(&snapshot, cx),cx,);@@ -6283,10 +6284,21 @@ fn compute_auto_height_layout(.unwrap().size.width;+ let em_advance = cx+ .text_system()+ .advance(font_id, font_size, 'm')+ .unwrap()+ .width;let mut snapshot = editor.snapshot(cx);- let gutter_dimensions =- snapshot.gutter_dimensions(font_id, font_size, em_width, max_line_number_width, cx);+ let gutter_dimensions = snapshot.gutter_dimensions(+ font_id,+ font_size,+ em_width,+ em_advance,+ max_line_number_width,+ cx,+ );editor.gutter_dimensions = gutter_dimensions;let text_width = width - gutter_dimensions.width;