Skip to content

editor: Let the gutter sit on the right side - #3417

Open
glani wants to merge 4 commits into
longbridge:nextfrom
GigLaboCom:editor-gutter-right-side
Open

glani wants to merge 4 commits into
longbridge:nextfrom
GigLaboCom:editor-gutter-right-side

Conversation

@glani

@glani glani commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Description

Stacks on #3416 — please review only the last three commits (editor: Let the gutter sit on the right side, editor: Keep the text clear of a scrollbar on the left, editor: Let the gutter's columns be ordered).

Targets next: it builds on #3359's gutter markers, which are on next.

The editor's gutter is always on the left of the text. In a mirrored side-by-side diff the left pane wants its gutter on its right, facing the middle, and its scrollbar on its outer edge.

This adds gutter_side(Side) / set_gutter_side to the editor state, default Side::Left (unchanged). On the right the gutter is mirrored: the same columns, in the same order counted from the text, with the line numbers aligned toward it. The text and gutter x offsets are computed once per layout and used for painting, hit testing, IME bounds and scroll-into-view. A scrollbar on the gutter's side stays outermost.

The right gutter is the exact mirror of the left one. Line numbers are placed by their shaped width rather than padded with spaces: in a proportional font a space is about a third of a digit, so the default left gutter left right-aligned numbers ragged and 6–11 px short of the text; they now line up against it on either side. Editor puts its narrow padding on the gutter's side.

gutter_order([GutterColumn]) orders the gutter's columns from the text outward, on either side: the default is [FoldIcons, LineNumbers, Markers] (unchanged); [FoldIcons, Markers, LineNumbers] is IntelliJ's diff, with the change markers by the text and the line numbers at the outer edge. A column left out follows the listed ones in its default order.

Screenshot

Before After
scrollbar-left mirrored

A side-by-side diff with changed lines marked; the left pane uses .scrollbar_side(Side::Left).gutter_side(Side::Right), mirrored:

Both gutters on the left Mirrored
both gutters on the left mirrored

The columns in IntelliJ's order, .gutter_order([GutterColumn::FoldIcons, GutterColumn::Markers, GutterColumn::LineNumbers]) on both panes — without and with folding (an empty fold column here):

IntelliJ's order With folding
IntelliJ's order IntelliJ's order with folding

Public API

gpui_base (re-exported by gpui_component):

  • InputBaseState::gutter_side(mut self, side: Side) -> Self — builder: which side of the text the gutter is drawn on; default Side::Left.
  • InputBaseState::set_gutter_side(&mut self, side: Side, cx: &mut Context<Self>) — the same, at runtime.
  • GutterColumn { FoldIcons, LineNumbers, Markers } — a column of the gutter.
  • InputBaseState::gutter_order(mut self, columns: impl IntoIterator<Item = GutterColumn>) -> Self / set_gutter_order(&mut self, columns, cx: &mut Context<Self>) — the columns from the text outward; default [FoldIcons, LineNumbers, Markers]; a column left out follows in its default order, a repeat is ignored.

How to Test

  • cargo test -p gpui-base --lib: new tests for the text and gutter origins with an unchanged wrap width, the mirrored fold icons and columns, the scrollbar staying outermost (left/left, right/left, right/right), clicks in the text and in the gutter on both sides, caret / IME / range_to_bounds / selection-path x including a long line scrolled clear of the gutter, a right-side case in the existing gutter-bounds test, every gutter column — markers included — mirrored to 0.01 px for all six orders with folding on and off, the order normalised and counted from the text on both sides, clicks on the fold icon and the line number in every side/order combination, and Editor keeping its gutter-side padding. Each fails with its code reverted.
  • cargo run the story, an editor with .gutter_side(Side::Right) and .scrollbar_side(Side::Left), then .gutter_order([GutterColumn::FoldIcons, GutterColumn::Markers, GutterColumn::LineNumbers]).

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)

@glani
glani force-pushed the editor-gutter-right-side branch from 7eb77d9 to 48a3393 Compare October 8, 2026 20:32
@glani
glani force-pushed the editor-gutter-right-side branch from fb4861c to f7844c9 Compare October 8, 2026 21:30
@glani
glani changed the base branch from main to next October 8, 2026 21:30
@glani
glani marked this pull request as ready for review October 8, 2026 21:36
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.

1 participant