Skip to content

editor: Add GutterStyle for line-number gap, color and font - #3737

Merged
huacnlee merged 13 commits into
longbridge:mainfrom
sator-imaging:sator-imaging-psychic-disco
Nov 19, 2026
Merged

huacnlee merged 13 commits into
longbridge:mainfrom
sator-imaging:sator-imaging-psychic-disco

Conversation

@sator-imaging

Copy link
Copy Markdown
Contributor

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
image image

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

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

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

  • I have read the CONTRIBUTING document and followed the guidelines.
  • Reviewed the changes in this PR and confirmed AI generated code (If any) is accurate.
  • Passed cargo run for story tests related to the changes.
  • Tested macOS, Windows and Linux platforms performance (if the change is platform-specific)

@huacnlee huacnlee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()).

@huacnlee

huacnlee commented Nov 1, 2026

Copy link
Copy Markdown
Member

One additional correctness issue if independent line-number fonts remain in scope: layout_line_numbers reserves gutter width by measuring +++, but the actual numbers are painted right-aligned using their own width. With a font whose digits are wider than +, multi-digit line numbers can extend past the reserved gutter and be clipped or overlap gutter decorations. Please size the lane for the actual supported digits and cover a font where digit glyphs are wider than +.

@huacnlee

huacnlee commented Nov 2, 2026

Copy link
Copy Markdown
Member

Thanks for the PR — the feature is useful and the tests are thorough. Reviewed at 607280ec49; a few things to address before merge, mostly around API shape (this adds new public API, so we want it consistent with the rest of the crate before it ships).

API shape

  1. crates/component/src/theme/mod.rs:153,247-253 — other runtime theme settings are plain public fields (pub notification, pub motion, pub cursor_blink, all #[serde(skip)]). Please make this pub editor_gutter_style: GutterStyle (with #[serde(skip)]) and drop set_editor_gutter_style / get_editor_gutter_style.
  2. crates/base/src/input/editor/gutter_style.rs:18-71 — the get_* prefix isn't used elsewhere in the repo (one other pub fn get_ in component). Either make the fields pub (it's a plain optional-value style struct, like gpui's *Refinement types) or use bare getter names. Having both with_* and get_* for every field doubles the API surface we must keep compatible.
  3. crates/base/src/input/base/kind.rs:82 — same for the trait method: gutter_style() rather than get_gutter_style().
  4. crates/base/src/input/mod.rs:29 — #[path = "editor/gutter_style.rs"] mod gutter_style; declared from the parent module is unusual; please declare it as a normal submodule of editor and re-export it.

Behavior
5. crates/base/src/input/base/element.rs:3853-3857 — line numbers changed from left-aligned (after line_number_offset) to right-aligned against line_number_right. Right-alignment is probably the better look, but it changes every existing editor and isn't mentioned in the description. Please call it out explicitly (or keep it separate). Gutter decorations still look correct because their width is included in line_number_width, and the decoration tests pass.

Housekeeping
6. cargo fmt --check fails: 21 hunks, in element.rs and the new tests. Please run cargo fmt.
7. The title should be component-scoped, per the repo's convention, e.g. editor: Add GutterStyle for line-number gap, color and font.

What I ran (Linux, merged cleanly with main)

  • cargo test --locked -p gpui-base -p gpui-component --features gpui-base/test-support,gpui-component/test-support gutter → 13 + 4 passed
  • cargo test -p gpui-base --features test-support -- line_number decoration fold → 34 passed
  • cargo clippy -p gpui-base -p gpui-component → no new warnings (only existing workspace/manifest ones)
  • cargo fmt --check → fails (see 6)
  • No screenshot: no story/gallery case was added for this. A small story toggle would help with visual review.

— 🤖 Argus (reviewer) · AI agent acting for @huacnlee

@sator-imaging
sator-imaging force-pushed the sator-imaging-psychic-disco branch from dfc118c to b066d69 Compare November 3, 2026 12:37
@sator-imaging

Copy link
Copy Markdown
Contributor Author

Note

This message is now in progress...

  • Gutter styling is scoped to each Component editor.
  • A narrow renderer boundary keeps styling in Component without exposing Base's internal layout state.
  • Updated the gutter API: gutter_style(...), with_* builders, and field-named readers. Removed get_* and gutter-style set_* methods. Merge helpers are crate-private.
  • Replaced the #[path] declaration with a normal submodule.
  • Gap and font size accept AbsoluteLength; GPUI handles unit conversion.
  • Default style values, body typography, and row height remain unchanged.
  • Replaced +-based width measurement with the widest digit in the configured font and removed space padding. Line numbers are right-aligned; the alignment change is documented.
  • Updated English and Chinese examples for both px and rems.
  • Applied cargo fmt. All 19 gutter tests passed.

@huacnlee

huacnlee commented Nov 4, 2026

Copy link
Copy Markdown
Member

Re-reviewed at b066d6921f (previous review: 607280ec49). Changes are still needed. The code has improved a lot, and the blockers are now the design questions from the 2026-11-01 review, plus test coverage and an out-of-date description. Your last comment says it is still in progress, so some of this may already be planned.

Status of earlier points

Point Status
Editor-specific record on the global Theme Fixed: removed, and Theme is untouched
Large Base-layer style API Partly fixed: GutterStyle moved to Component, but Base gains a new public seam (see 2)
get_ readers and setter/getter pairs Fixed: with_* setters and field-named readers match AGENTS.md rule 7
Fixed pixels for typography and spacing Fixed: AbsoluteLength, with rems in the docs example and zoom tests
Gutter width measured from +++ Fixed in code, not covered by tests (see 3)
Realistic example, shown at different zoom levels Not fixed: no story case, and I saw no new screenshots
Concrete application need Not fixed: neither the description nor your comment explains it
#[path] module declaration Fixed: normal submodule
Right-aligned numbers undisclosed Fixed: documented. Correction to my earlier review: main already pads with {:>width$}, so monospace output should not move. Only proportional fonts change
cargo fmt Fixed: passes
Title prefix Not fixed: still feat: gutter style

Findings

P1

  1. The example and the need are still missing. crates/story/src/stories/editor_story.rs and examples/editor/src/main.rs have no gutter style case. Please add a story with a realistic configuration at two or more zoom levels, and say which application needs an independent line-number font and size. Without that need, the public surface can't be justified. Colors and gap alone may be enough.

  2. The Base seam is the part of the API I would change before it ships (crates/base/src/input/editor/mod.rs:13-33,305,321):

    • measure_line_numbers returns an unnamed (Pixels, Pixels), and digit_count == 0 is a sentinel for "hidden". A small named result type would be clearer and easier to extend.
    • The trait is public with required methods, so any later required method breaks implementers.
    • Editor gains a type parameter and moves from RenderOnce to View. Both are visible to users, but the description says no existing public signatures changed.

    If Component is the only real implementer, consider keeping this out of the supported Base API (for example #[doc(hidden)]) and removing the "Base-only applications" promise from the docs until someone needs it. This is a recommendation; the owner decides the final scope.

  3. The wider-digit case still has no test, although it was requested. I replaced "0123456789" with "+" in both crates/component/src/input/gutter_style.rs:39 and crates/base/src/input/editor/mod.rs:47, and all 19 gutter tests still passed (change reverted, nothing pushed). The Base test uses a fixed 100px lane (crates/base/src/input/base/element.rs:4976), so it never exercises the real measurement. Please add a test that fails with this change.

  4. The description is out of date. Its Usage and Public API sections still list Theme::set_editor_gutter_style, apply_gutter_style, get_* and InputExtras::get_gutter_style, and omit EditorLineNumberRenderer, Editor::with_line_number_renderer and Editor::gutter_style. CONTRIBUTING requires an accurate ## Public API section, and any changes to existing items need a ## Breaking Changes section. It also says five gutter tests; there are now 19. The after screenshot should be replaced once the story exists.

P2
5. Body text decorations now reach line numbers. crates/component/src/input/gutter_style.rs:80-82 copies background_color, underline and strikethrough from the body style. main and the Base () renderer use None, so an underlined editor would get underlined numbers. These should be None. This comes from reading the code; I did not run this case.
6. A different number size won't share the body baseline. crates/base/src/input/base/element.rs:3847-3858 paints each number through ShapedLine::paint, which centers it from that run's own ascent and descent, so a smaller number is centered in the row and not baseline-aligned. This bears directly on the "coherent relationship" point from the review, so please check it in the story. This also comes from reading the code, and I haven't seen it rendered.

P3
7. Please retitle using the component prefix, for example editor: Add GutterStyle for line-number gap, color and font. Recent merged titles follow this form.

API and naming: GutterStyle, Editor::gutter_style and the with_* setters with field-named readers follow the repo's conventions, so I have no objection to those names. The open issue is scope: the font family and size options need a stated use, and the Base trait needs the changes in 2.

What I ran (Linux, at b066d6921f)

  • cargo fmt --check: passes
  • cargo clippy -p gpui-base --all-targets --features test-support and cargo clippy -p gpui-component --all-targets, run separately: no warnings from the PR code, only existing manifest warnings
  • cargo test --locked -p gpui-base --features test-support --lib: 1551 passed
  • cargo test --locked -p gpui-component --lib: 753 passed
  • Gutter-filtered tests: 11 + 8 passed
  • git merge-tree against current main: no conflicts
  • CI checks on this head: all green

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

@huacnlee

huacnlee commented Nov 8, 2026

Copy link
Copy Markdown
Member

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.

🤖 Noop (rust-maintainer) · AI agent acting for @huacnlee

@huacnlee huacnlee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-component with test-support: all passed (1627 + 775 + others).
  • cargo clippy --all-targets -D warnings on both crates: clean.
  • cargo fmt --check fails only in crates/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 Test and GPUI Fast jobs and Checks failed 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.

🤖 Noop (reviewer) · AI agent acting for @huacnlee

huacnlee pushed a commit that referenced this pull request Nov 9, 2026
## 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.
@sator-imaging sator-imaging changed the title feat: gutter style editor: Add GutterStyle for line-number gap, color and font Nov 14, 2026
@sator-imaging
sator-imaging force-pushed the sator-imaging-psychic-disco branch from 954f1db to d09c75e Compare November 15, 2026 06:42
@huacnlee

Copy link
Copy Markdown
Member

❌ Changes requested: the new gutter_baselines_stay_fixed_when_line_contents_change test fails on Linux.

Thanks for addressing the feedback. Reviewed new commit 4073e8c (head d09c75e).

Fixed since last review

  • Real-font regression test for digit lane width (gutter_lane_contains_digits_wider_than_plus) — passes.
  • Gutter labels no longer inherit body underline/strikethrough/background (gutter_labels_ignore_body_decorations) — passes.
  • EditorLineNumberRenderer / with_line_number_renderer are now #[doc(hidden)], and the story shows the gutter style.
  • Line-number y now advances per soft line with a font-based baseline offset (element.rs:3857).

Blocking

  • cargo test -p gpui-kit --features test-support,component,assets --test rendering on Linux (x86_64) panics at crates/kit/tests/rendering.rs:446: the gutter ink pixels after set_value("A\nA\nA") / "A\n漢😀A\nA" differ from the initial frame (assertion left == right failed). Either the baseline still moves when row content changes (e.g. fallback fonts for CJK/emoji change the row line height), or the pixel-exact comparison is too strict for this platform. Please check which; if it's the test, compare glyph bounds per row rather than exact pixel indices.

Non-blocking

  • resolve_line_number_baseline_offset is a new required trait method; since the trait is hidden this is fine, but a default px(0.) impl would avoid breaking any existing implementor.
  • PR description: please mention the baseline-alignment change and the hidden renderer trait.

🤖 Noop (reviewer) · AI agent acting for @huacnlee

@sator-imaging

Copy link
Copy Markdown
Contributor Author

Addessed PR feedbacks.

  • Marked the internal Base renderer integration with #[doc(hidden)]. Styling stays in Component without exposing core editor state.
  • Removed body background, underline, and strikethrough inheritance from line numbers.
  • Aligned line-number baselines using configured font metrics, independently of line contents.
  • Added a default zero baseline offset to the renderer trait.
  • Applied gutter styling to the existing Decorations tab, using theme colors, an independent font, and rem-based size and gap (note: examples uses pixel-sized theme, so the size won't be changed by the font size accordingly).
  • Added rendering regression tests for digits wider than + and body-decoration isolation. Confirmed that switching measurement back to + fails the regression test.
  • Changed the baseline regression test to compare glyph bounds per row within the gutter instead of exact pixel values, retaining detection of one-device-pixel shifts.

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.

@huacnlee

Copy link
Copy Markdown
Member

✅ The baseline regression from the last round is fixed: crates/kit/tests/rendering.rs now passes locally on Linux.

Reviewed at dec4669. address feedback measures exact gutter label bounds per row, so the test is no longer sensitive to antialiasing. It also gives resolve_line_number_baseline_offset a default of px(0.), so renderers that use the body typography no longer need to implement it. Ran cargo test -p gpui-kit --features test-support,component,assets --test rendering: 16 passed (real offscreen renderer). CI on this head has not finished yet.

🤖 Noop (reviewer) · AI agent acting for @huacnlee

Preserve the generic line-number renderer and GPUI Fast IntoElement guard.

Agent: rust-maintainer
@huacnlee

Copy link
Copy Markdown
Member

Merged current main into this branch in ca16e51, resolving crates/base/src/input/base/element.rs. Kept the PR's generic EditorLineNumberRenderer and main's #[cfg(not(feature = "gpui-fast"))] guard on the explicit IntoElement implementation.

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.

🤖 Noop (rust-maintainer) · AI agent acting for @huacnlee

Preserve custom line-number typography while adopting compact wrapped-row storage and current soft-wrap optimizations.

Agent: rust-maintainer
@huacnlee

Copy link
Copy Markdown
Member

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.

🤖 Noop (rust-maintainer) · AI agent acting for @huacnlee

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
@huacnlee

Copy link
Copy Markdown
Member

Merged main into this branch in 44736166, resolving crates/base/src/input/base/element.rs. Kept configurable line-number right alignment and baseline offsets alongside main’s viewport-relative row coordinates and f64 scrolling. The gutter gap is applied after snapshot construction so the private constructor stays within Clippy’s argument limit.

Linux validation: cargo check -p gpui-base -p gpui-component; all 1,769 Base library tests; all 16 real offscreen rendering tests; strict all-target Clippy for Base and Component with test-support. The rendering suite was repeated after the constructor adjustment and passed. No additional public API or visual behavior was added.

🤖 Noop (rust-maintainer) · AI agent acting for @huacnlee

@huacnlee
huacnlee merged commit d758da0 into longbridge:main Nov 19, 2026
18 of 19 checks passed
@sator-imaging
sator-imaging deleted the sator-imaging-psychic-disco branch November 20, 2026 01:37
linruohan pushed a commit to linruohan/gpui-kit that referenced this pull request Nov 20, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants