From 35568124bff8f67be882191099932e54f33ba769 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Tue, 16 Sep 2025 21:50:09 +0800 Subject: [PATCH] editor: Improve CodeEditor inset and line number width. (#1255) image --- crates/story/examples/code-editor.rs | 1 + crates/ui/src/input/element.rs | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/story/examples/code-editor.rs b/crates/story/examples/code-editor.rs index 2045491d..0348c613 100644 --- a/crates/story/examples/code-editor.rs +++ b/crates/story/examples/code-editor.rs @@ -649,6 +649,7 @@ impl Render for Example { .child( TextInput::new(&self.editor) .bordered(false) + .p_0() .h_full() .font_family("Monaco") .text_size(px(12.)) diff --git a/crates/ui/src/input/element.rs b/crates/ui/src/input/element.rs index 45ef2ba9..5ede9acc 100644 --- a/crates/ui/src/input/element.rs +++ b/crates/ui/src/input/element.rs @@ -599,10 +599,10 @@ impl Element for TextElement { // Calculate the width of the line numbers let empty_line_number = window.text_system().shape_line( - "++++".into(), + "+++++".into(), font_size, &[TextRun { - len: 4, + len: 5, font: style.font(), color: gpui::black(), background_color: None, @@ -612,7 +612,7 @@ impl Element for TextElement { None, ); let line_number_width = if state.mode.line_number() { - empty_line_number.width + LINE_NUMBER_RIGHT_MARGIN + empty_line_number.width + px(6.) + LINE_NUMBER_RIGHT_MARGIN } else { px(0.) }; @@ -811,7 +811,7 @@ impl Element for TextElement { let ix = last_layout.visible_range.start + ix; let line_no = ix + 1; - let mut line_no_text = format!("{:>4}", line_no); + let mut line_no_text = format!("{:>5}", line_no); if !line.wrap_boundaries.is_empty() { line_no_text.push_str(&"\n ".repeat(line.wrap_boundaries.len())); } @@ -972,7 +972,7 @@ impl Element for TextElement { Bounds { origin: input_bounds.origin, size: size( - prepaint.last_layout.line_number_width, + prepaint.last_layout.line_number_width - LINE_NUMBER_RIGHT_MARGIN, input_bounds.size.height, ), },