Repository navigation
editor: Add GutterStyle for line-number gap, color and font - #3737
Conversation
huacnlee
left a comment
There was a problem hiding this comment.
Thanks for working on editor gutter customization. I don't think this is ready to merge: the example and the API need a design pass first.
The after screenshot makes the line numbers much smaller than the editor text, with weak readability and an awkward visual relationship to the rows. It demonstrates that the values can be changed, but not a convincing editor design. Please start with a realistic example that preserves legibility and a coherent relationship between line numbers, text, and row height, and show how it behaves at different UI zoom levels.
The API also feels too broad for the use case. It adds an editor-specific style record to the global Theme, plus a large public Base-layer style API, to override individual presentation details. Our architecture calls for semantic theme tokens rather than additional component-specific theme fields, and keeps application presentation above the Base behavior boundary. Please reconsider the ownership and scope of the customization and explain the concrete application need before adding this surface.
In addition, the example uses fixed pixel values for ordinary typography and spacing, so line numbers and gap will not scale with the rest of the interface. The Design Guides require relative scaling for these values. The new GutterStyle readers also use get_ prefixes, whereas the documented public-data convention uses field names for non-boolean readers (for example, gap() and line_number_color()).
|
One additional correctness issue if independent line-number fonts remain in scope: |
|
Thanks for the PR — the feature is useful and the tests are thorough. Reviewed at API shape
Behavior Housekeeping What I ran (Linux, merged cleanly with main)
— 🤖 Argus (reviewer) · AI agent acting for @huacnlee |
dfc118c to
b066d69
Compare
|
Note This message is now in progress...
|
|
Re-reviewed at Status of earlier points
Findings P1
P2 P3 API and naming: What I ran (Linux, at
Not verified: nothing was checked visually. The display on this host was off, so I couldn't capture the gutter. Default rendering, zoom behavior and finding 6 still need a visual check. 🤖 Noop (reviewer) · AI agent acting for @huacnlee |
|
Merged main into this branch in 954f1db, resolving crates/base/src/input/base/element.rs. Preserved the configurable gutter edge passed to fold-icon layout while retaining main’s folded-line placeholder layout and its test imports. Validation on Linux: all 11 gpui-base and 8 gpui-component gutter-filtered tests passed; clippy passed for both crates, both test-support features and all targets. The resolved file passes rustfmt. Existing design/API, example and description review requests remain open; this maintenance update does not approve the proposed API or claim visual verification. |
huacnlee
left a comment
There was a problem hiding this comment.
Re-reviewed at 954f1db (previous review: b066d692). The only change since the last review is the main merge in 954f1db (its first parent is b066d692), so the code in this PR has not changed and every point from the 2026-11-04 review is still open:
| Point | Status |
|---|---|
| Real example / story showing the gutter style at normal and zoomed sizes | Open |
| The use case: why the gutter needs its own font family and size | Open |
Shape of the public Base trait method (InputExtras::get_gutter_style) |
Open |
Effective tests for line-number lane width with a font whose digits are wider than + |
Open |
PR description is out of date (it still lists get_* readers and set_* methods, which your 2026-11-03 comment says were removed) |
Open |
Title should use the component prefix, e.g. editor: Add gutter style |
Open |
Validation at 954f1db (Linux)
cargo test -p gpui-base -p gpui-componentwith test-support: all passed (1627 + 775 + others).cargo clippy --all-targets -D warningson both crates: clean.cargo fmt --checkfails only incrates/base/src/text/inline_flow.rs, which this PR does not touch. Main has the same problem, so it is not caused by this PR.- CI: the Linux
TestandGPUI Fastjobs andChecksfailed while the run was still in progress, so their logs were not available yet. The macOS and Windows test jobs passed. The local Linux test run passed, so the failure may come from main or the runner. Please check once the run finishes.
Your last comment said the work was still in progress. Once the items above are addressed, we can review the API again.
## Summary Expose the editor's laid-out horizontal text origin offset so a static source view can align with the actual editor geometry instead of copying a private 6px constant. Fixes #3764 The reader uses the latest layout's complete gutter width: gap, line numbers, folding controls and gutter decorations. It does not change rendering or defaults. Frame padding remains separate: the offset is measured from the content area's left edge (`input_bounds().left()`), which already accounts for frame padding. Horizontal scrolling and text alignment are not included. The editor must be laid out before the first read. The reader returns `None` before first layout and, like `range_to_bounds`, describes the most recent frame. Static/editor transitions must obtain layout before aligning the replacement; this is no longer a pre-layout default-metric API. ## Review follow-up and #3737 Checked #3737 at `954f1db41b3a484f03232c56fba091d3b90b9b1b`. Its current implementation resolves `GutterStyle` through a frame-owned `EditorLineNumberRenderer`, not retained editor state. Merely adding `&self` to a constant reader would not solve the problem. This adopts the review's text-origin alternative and reads the geometry that #3737 already publishes in `LastLayout`, without retaining Component styles in Base. An in-repository regression compares the public reader with rendered text bounds across 14/18/24px rem sizes, line-number/folding changes, nonzero frame padding, real horizontal and vertical scrolling, and decoration-lane addition/removal. It also checks the pre-layout `None` contract. Floating-point coordinate comparisons allow less than 0.001px arithmetic roundoff. English and Chinese Base Editor documentation describe the coordinate origin and layout lifecycle. ## Public API ### gpui-base - `EditorState::text_origin_offset(&self) -> Option<Pixels>`: horizontal offset from the content area's left edge to unscrolled, left-aligned source text in the most recent layout; `None` before first layout. This is also available through the existing Component/Kit state re-exports. ## Breaking Changes This replaces the earlier **unmerged proposal** in this PR; no previously released API is removed. ```diff - EditorState::text_gutter_margin() -> Pixels + editor.read(cx).text_origin_offset() -> Option<Pixels> ``` ## Validation Windows, Rust 1.99.1, shared existing debug target: - `cargo +1.99.1 test --locked -p gpui-base --lib input`: 426 passed. - `cargo +1.99.1 clippy --locked -p gpui-base --all-targets --features test-support -- --deny warnings`: passed. - Changed Rust files pass Rust 1.99.1 rustfmt; `git diff --check` passes. - Mutation check: temporarily replaced the layout-derived return with the fixed 6px constant while preserving the pre-layout `None` behavior. The rendered-origin regression failed, and the mutation was reverted. - Compatibility experiment: temporarily merged #3737 (`954f1db`) with this change, without conflicts. Added temporary assertions to its real Component override/removal and rem-zoom tests, plus a Base renderer test for hidden-gutter gaps 0/12/24/0px and default restoration. `cargo +1.99.1 test --locked -p gpui-base -p gpui-component --features gpui-base/test-support,gpui-component/test-support --lib gutter`: 13 Base + 8 Component tests passed. The temporary merge and tests are not part of this PR. The machine's default Rust 1.94 cannot build the current GPUI dependencies (`cfg_select`/`cold_path`); validation used the already-installed 1.99.1 without changing repository toolchain or dependencies. Local checks are headless; no manual visual or macOS/Linux run is claimed. [Three-platform CI](https://github.com/longbridge/gpui-kit/actions/runs/42629171901) has been triggered for this revision. AI-assisted implementation and regression tests.
954f1db to
d09c75e
Compare
|
❌ Changes requested: the new Thanks for addressing the feedback. Reviewed new commit Fixed since last review
Blocking
Non-blocking
|
|
Addessed PR feedbacks.
Validation: 16 rendering tests passed after the bounds-comparison change. The reported Linux failure was not reproduced locally. The subsequent trait default has not been retested. |
|
✅ The baseline regression from the last round is fixed: Reviewed at dec4669. |
Preserve the generic line-number renderer and GPUI Fast IntoElement guard. Agent: rust-maintainer
|
Merged current main into this branch in ca16e51, resolving Linux validation: all 16 real offscreen rendering tests passed, including the three gutter regressions; strict all-target Clippy passed for Base and Component with both test-support features. No new API or visual behavior was added by this maintenance merge. |
Preserve custom line-number typography while adopting compact wrapped-row storage and current soft-wrap optimizations. Agent: rust-maintainer
|
Merged current main into this branch in 5d06bff, resolving crates/base/src/input/base/element.rs. Preserved the configurable line-number renderer, right alignment and baseline offset, while keeping main's compact (shaped label, wrapped-row count) representation and soft-wrap optimizations. Validation on macOS: all 1,758 gpui-base library tests passed; strict all-target Clippy passed for Base and Component with test-support. The Kit rendering test target compiled successfully, but execution stopped before its first assertion because this sandbox cannot connect to the macOS Pasteboard service (+[NSPasteboard generalPasteboard] returned NULL). Native rendering remains unverified here. No public API or visual behavior was added by this maintenance merge. |
Keep configurable number alignment and baselines with main’s viewport-relative row coordinates and f64 scrolling. Apply the gutter gap after creating the scrollbar snapshot to keep the constructor within the argument limit. Agent: rust-maintainer
|
Merged main into this branch in Linux validation: |
…ge#3737) ## Description **Configurable editor line-number styles** This PR adds application-wide defaults and per-editor overrides for the gutter gap, normal and active line-number colors, font family, and font size. These settings let applications style line numbers independently of the editor body. Line-number measurement and painting use the same resolved typography. Wrapping, folding controls, scrollbar geometry, and pointer coordinates follow the resulting gutter width while body typography and row height remain independent. ## Screenshot | Before | After | | ---------------------------- | --------------------------- | | <img width="235" height="261" alt="image" src="https://github.com/user-attachments/assets/99edff5a-d550-496c-9eae-f09b497c6cc4" /> | <img width="261" height="257" alt="image" src="https://github.com/user-attachments/assets/d1bdfe37-b71c-4ffd-9fc2-113869db5928" /> | ## Changes - Add `GutterStyle` with optional properties. Explicit per-editor values override theme defaults; unspecified properties continue to inherit. Zero gaps and transparent colors remain explicit values. - Project the current theme and element settings on every render so removing an override restores the theme settings and later theme changes remain effective. - Document the API in English and Chinese. Theme settings are runtime-only and are not serialized into theme JSON. - Limit this change to Editor; Diff and TextView are unchanged. ## Usage ```rust use gpui_kit::{ px, component::{Theme, input::{Editor, GutterStyle}}, }; Theme::update(cx, |theme| { theme.set_editor_gutter_style( GutterStyle::default() .with_gap(px(12.)) .with_line_number_color(theme.muted_foreground) .with_active_line_number_color(theme.foreground) .with_line_number_font_family("JetBrains Mono") .with_line_number_font_size(px(12.)), ); }); Editor::new(&editor_state).apply_gutter_style( GutterStyle::default().with_line_number_font_size(px(11.)), ) ``` ## Public API ### gpui-base All paths below are relative to `gpui_base::input`. | Signature | Purpose | | --- | --- | | `pub struct GutterStyle` | Optional gutter presentation with private fields; implements `Clone`, `Debug`, `Default`, and `PartialEq`. | | `pub use gutter_style::GutterStyle` | Exposes the style through the public input module. | | `GutterStyle::with_gap(self, gap: Pixels) -> Self` | Sets spacing between the number/folding lane and body text. | | `GutterStyle::with_line_number_color(self, color: Hsla) -> Self` | Sets normal line-number ink. | | `GutterStyle::with_active_line_number_color(self, color: Hsla) -> Self` | Sets current-line number ink. | | `GutterStyle::with_line_number_font_family(self, family: impl Into<SharedString>) -> Self` | Sets the number font independently of the body. | | `GutterStyle::with_line_number_font_size(self, size: Pixels) -> Self` | Sets the number font size without changing body row height. | | `GutterStyle::get_gap(&self) -> Option<Pixels>` | Reads the explicitly configured gap. | | `GutterStyle::get_line_number_color(&self) -> Option<Hsla>` | Reads the explicitly configured normal color. | | `GutterStyle::get_active_line_number_color(&self) -> Option<Hsla>` | Reads the explicitly configured current-line color. | | `GutterStyle::get_line_number_font_family(&self) -> Option<&SharedString>` | Reads the explicitly configured font family. | | `GutterStyle::get_line_number_font_size(&self) -> Option<Pixels>` | Reads the explicitly configured font size. | | `GutterStyle::apply_overrides(&mut self, overrides: &Self)` | Merges only properties explicitly supplied by the overriding style. | | `EditorState::set_gutter_style(&mut self, style: GutterStyle)` | Replaces Base editor presentation for the next layout; callers outside render must notify afterwards. | | `InputExtras::get_gutter_style(&self) -> Option<&GutterStyle>` | Adds a default trait method returning `None`; `EditorExtras` overrides it to expose editor presentation to the generic renderer. | ### gpui-component | Signature | Purpose | | --- | --- | | `input::GutterStyle` (`pub use gpui_base::input::GutterStyle`) | Makes the same style type available through Component. | | `input::Editor::apply_gutter_style(self, style: GutterStyle) -> Self` | Applies per-editor property overrides over the active theme. | | `Theme::set_editor_gutter_style(&mut self, style: GutterStyle)` | Replaces application-wide editor defaults; use inside `Theme::update` to refresh windows. | | `Theme::get_editor_gutter_style(&self) -> &GutterStyle` | Reads configured defaults before per-editor overrides. | The existing Kit re-exports expose these additions without changes to `gpui-kit`. No existing public signatures are removed or changed. ## How to Test ```bash cargo test --locked -p gpui-base -p gpui-component --features gpui-base/test-support,gpui-component/test-support gutter ``` Five gutter tests exercise style construction and partial merging, explicit transparent colors and zero spacing, typography inheritance, theme updates and override removal, and gutter-dependent wrapping and scrollbar placement. They also check that changing gutter typography leaves body metrics unchanged and that clicking at the first caret leaves the selection at the start. ## Checklist - [x] I have read the [CONTRIBUTING](../CONTRIBUTING.md) document and followed the guidelines. - [x] Reviewed the changes in this PR and confirmed AI generated code (If any) is accurate. - [x] Passed `cargo run` for story tests related to the changes. - [ ] Tested macOS, Windows and Linux platforms performance (if the change is platform-specific) --------- Co-authored-by: Jason Lee <huacnlee@gmail.com>
Description
Configurable editor line-number styles
This PR adds application-wide defaults and per-editor overrides for the gutter gap, normal and active line-number colors, font family, and font size. These settings let applications style line numbers independently of the editor body.
Line-number measurement and painting use the same resolved typography. Wrapping, folding controls, scrollbar geometry, and pointer coordinates follow the resulting gutter width while body typography and row height remain independent.
Screenshot
Changes
GutterStylewith optional properties. Explicit per-editor values override theme defaults; unspecified properties continue to inherit. Zero gaps and transparent colors remain explicit values.Usage
Public API
gpui-base
All paths below are relative to
gpui_base::input.pub struct GutterStyleClone,Debug,Default, andPartialEq.pub use gutter_style::GutterStyleGutterStyle::with_gap(self, gap: Pixels) -> SelfGutterStyle::with_line_number_color(self, color: Hsla) -> SelfGutterStyle::with_active_line_number_color(self, color: Hsla) -> SelfGutterStyle::with_line_number_font_family(self, family: impl Into<SharedString>) -> SelfGutterStyle::with_line_number_font_size(self, size: Pixels) -> SelfGutterStyle::get_gap(&self) -> Option<Pixels>GutterStyle::get_line_number_color(&self) -> Option<Hsla>GutterStyle::get_active_line_number_color(&self) -> Option<Hsla>GutterStyle::get_line_number_font_family(&self) -> Option<&SharedString>GutterStyle::get_line_number_font_size(&self) -> Option<Pixels>GutterStyle::apply_overrides(&mut self, overrides: &Self)EditorState::set_gutter_style(&mut self, style: GutterStyle)InputExtras::get_gutter_style(&self) -> Option<&GutterStyle>None;EditorExtrasoverrides it to expose editor presentation to the generic renderer.gpui-component
input::GutterStyle(pub use gpui_base::input::GutterStyle)input::Editor::apply_gutter_style(self, style: GutterStyle) -> SelfTheme::set_editor_gutter_style(&mut self, style: GutterStyle)Theme::updateto refresh windows.Theme::get_editor_gutter_style(&self) -> &GutterStyleThe existing Kit re-exports expose these additions without changes to
gpui-kit.No existing public signatures are removed or changed.
How to Test
cargo test --locked -p gpui-base -p gpui-component --features gpui-base/test-support,gpui-component/test-support gutterFive gutter tests exercise style construction and partial merging, explicit transparent colors and zero spacing, typography inheritance, theme updates and override removal, and gutter-dependent wrapping and scrollbar placement. They also check that changing gutter typography leaves body metrics unchanged and that clicking at the first caret leaves the selection at the start.
Checklist
cargo runfor story tests related to the changes.