Skip to content

Fit the source editor toolbar to its width by measuring - #19897

Merged
gtritchie merged 12 commits into
mainfrom
bugfix/editor-toolbar-overflow
Dec 3, 2026
Merged

gtritchie merged 12 commits into
mainfrom
bugfix/editor-toolbar-overflow

Conversation

@gtritchie

Copy link
Copy Markdown
Member

Fixes #19896.

The source editor toolbar used to hide its buttons and labels at fixed pane widths. Those widths no longer matched what the toolbar holds, so at several widths it pushed its rightmost buttons past its right edge. Examples: "Toggle the second view of this document", "Show Changes Side by Side", and "Publish options" in a Quarto or R Markdown document, and "Show document outline" in an R script.

The toolbar now fits itself by measuring. On each layout it shows everything, then gives up width in the same order as before until its widgets no longer overflow. The order is: the go-to section buttons; the split editor and diff toggle buttons; the Render/Knit/Preview/Compile PDF labels; the publish caption; the Format label; the shorter "Render on Save" label; the Run labels; and the Source label. The Run menu's label on R Markdown and Quarto documents now drops in the same step as the Run button's.

  • Toolbar gains fitWidgets(lastStep, step -> ...), which runs that loop. It also gains onWidgetsResized(command), which watches the toolbar's widgets with a ResizeObserver. When a widget changes width after a fit, for example a YAML edit restoring Render's label, Run App becoming Reload App, or the publish button's caption becoming Republish, the toolbar fits again. The observer ignores the width a fit leaves, so a fit doesn't trigger itself.
  • TextEditingTargetWidget supplies the steps and refits when the diff toggle becomes available or unavailable, which the observer can't see while the fit has hidden the toggle.
  • showsMenuHalf() and its 20px allowance for split buttons' menu halves are removed. Measuring covers them.

At the narrowest widths, below about 450px for a Quarto document, the toolbar still overflows: everything that can be hidden already is.

Testing

  • e2e/rstudio/tests/toolbar/source_toolbar_breakpoints.test.ts replaces its test of Controls are smaller than the WCAG 2.2 minimum target size and too closely spaced #19786's fixed breakpoints with two tests, run with npm run test:server-dev:
    • The first narrows an R script's and a Quarto document's toolbars to 662, 612 and 512px. Those are widths where the fixed breakpoints left a control clipped. It checks that no control is clipped, then that widening restores the controls that were hidden. It fails against main and passes here.
    • The second shows the labels a fit hid and expects the toolbar to fit again. It fails without the observer and passes here.
  • Checked by hand in a dev server, with a Quarto document in a Git project, in Source and Visual modes, from 1165px down to 475px: no control clipped at any of those widths.
  • A worst-case fit, nine rounds of changing a label and reading the layout, takes about 1ms.

The go-to section buttons' visibility still comes from the global chunk commands, as before. That's tracked separately in #19895.

The toolbar sheds width in the same order as before (go-to buttons,
split buttons, render labels, publish caption, ...), but now steps
through that order until its widgets no longer overflow, instead of
at fixed widths that no longer matched what the toolbar holds. The
Run menu's label now drops with the Run button's.
The publish button's caption (Publish to Republish) and visibility
change as deployment records arrive, after the toolbar has fitted
itself; it now tells the editor, which fits the toolbar again.
Replaces the test of #19786's fixed breakpoints with one that, at
widths where those breakpoints left a control clipped, checks that no
control is, and that widening restores the controls given up.
Activating a tab fits its toolbar as well, so a check right after one
could pass even if resizing left the toolbar clipped.
A label or button that widens after the toolbar is fitted (a YAML edit
restoring Render's label, Run App becoming Reload App, the publish
button's menu half appearing) clipped controls until the next resize.
The toolbar now runs the fit itself and watches its widgets with a
ResizeObserver, refitting when they reach a width its last fit didn't
leave. This replaces the publish button's own width callback.
Also retry a splitter drag that doesn't take, rather than fail the
test, and allow the toolbar 2px from its target width.
The toolbar's observer can't see the toggle change while the fit has
hidden it, so the editor split button stayed hidden when it would fit
alone.
The toolbar's ResizeObserver replaced it in 4ea8d2c, which meant to
remove it but kept it by mistake; nothing registers the callback.
Selecting a tab fits its toolbar in a deferred command, so the test's
baseline could be read before the fit.
@gtritchie gtritchie added this to the 2026.12 (Parrot Balsam) milestone Dec 2, 2026
@gtritchie gtritchie self-assigned this Dec 2, 2026
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

RStudio E2E - all platforms

All tests passed!

#################### 100% pass rate

Passed Failed Skipped Flaky
6025 0 274 1
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ auth-teardown 4 0 16 0
✅ desktop-linux 1510 0 49 0
✅ desktop-macos 1497 0 63 0
✅ desktop-windows 1504 0 60 1
✅ server-linux 1462 0 54 0
✅ setup 48 0 32 0

View report online


All platforms - commit 6bc64a566df0af735e7456de5966cea7c7dc60bd - Run #2624

@gtritchie
gtritchie merged commit 8b19974 into main Dec 3, 2026
45 checks passed
@gtritchie
gtritchie deleted the bugfix/editor-toolbar-overflow branch December 3, 2026 15:09
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.

Source editor toolbar pushes buttons past its right edge at some pane widths

1 participant