Skip to content

fix(editor): the TOC button keeps a gutter to stand on with line numbers off - #812

Merged
PathGao merged 1 commit into
masterfrom
fix/810-toc-toggle-over-text
Sep 21, 2026
Merged

PathGao merged 1 commit into
masterfrom
fix/810-toc-toggle-over-text

Conversation

@PathGao

@PathGao PathGao commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

What this is

With "Line Numbers" off and the table of contents collapsed, the floating TOC
button sits on the text. Reported by @felhasznalonev in #810, second bullet, on
2.7.6 / macOS Apple Silicon. Not Closes: that issue carries six items and
this is one of them.

Mechanism

.toc-toggle-floating is positioned against the pane, not the editor — left: 8px, width: 28px, so it reaches 36px in. What it floats over is the
line-number gutter.

Measured on monaco-editor 0.55.1 with this app's creation options, Menlo 14px:

glyph margin line numbers line decorations contentLeft
Line Numbers on 0 42 26 68
Line Numbers off 0 0 26 26

EditorLayoutInfoComputer.computeLayout reserves that gutter on renderType !== Off, and 'off' is the only one of the five accepted values that
collapses it — 'on', 'relative', 'interval' and a render function all
keep it. A render function validates as Custom, so () => '' is "keep the
gutter, draw nothing in it": with line numbers off the layout is now identical
to line numbers on, minus the digits.

Scope

  • Nothing narrows the kept gutter, so turning line numbers off no longer
    reclaims their width. I had a lineNumbersMinChars: 2 here that got it back
    to 17px, and took it out: the gutter is a multiple of the digit width while
    the button is a fixed 28px, so a narrowed gutter reintroduces the overlap
    below 8px of effective type (the default 14px at 50% zoom, the minimum 10px
    at 70%), and it leaves the button on the line-decoration strip that the full
    gutter clears. Matching "on" exactly has neither problem.
  • tocSide: 'right' is untouched. The button mirrors to right: 8px, where
    what it covers is the vertical scrollbar rather than text, and nothing is
    reported about it.
  • The other five items in Paragraph, icon, fonts, settings, sidebar, highlight #810 are separate; I have replied there with what
    each one looks like from the source.

Tests

One, in editorOptionWiring.test.ts. It asserts that "off" does not reach
Monaco as 'off' — that it arrives as a function returning '', that the
function is one module-level value rather than a closure per call (this runs
in an effect, and a fresh arrow would read as a changed option on every
updateOptions), and that the three modes which already reserved the gutter
are passed through untouched.

Reverted the change and kept the test: it fails.

Not pinned: the pixel widths. An earlier draft drove
EditorLayoutInfoComputer with the button's geometry read out of
MarkdownViewer.svelte, which needed two internals declared in
monacoInternals.d.ts and came to about 125 lines for a one-line fix. "Off
lays out like on" is the stronger invariant anyway — it survives the button
moving.

Verification

npm audit    # 0 vulnerabilities
npm run check    # 838 files, 0 errors, 0 warnings
npm test     # 1028 pass, 0 fail

cargo test not run — nothing under src-tauri/ changed.

Not verified: I have no screenshot of Markpad itself. The layout numbers come
from monaco-editor 0.55.1 driven directly with this app's creation options in
a browser, and the 36px from the stylesheet; that the editor pane starts at
the layout container's left edge is read off the CSS, not measured in the app.

…ers off

`.toc-toggle-floating` is positioned against the pane — 8px from its left
edge, 28px wide — so what it floats over is the line-number gutter. Measured
on this Monaco build, contentLeft is 68px with line numbers on (42px of
gutter, 26px of line decorations) and 26px with them off, which dropped the
button onto the first 10px of every line (#810).

Monaco reserves the gutter on `renderType !== Off`, and a render function
validates as `Custom`: `() => ''` keeps the width and draws nothing in it, so
"off" now lays out exactly as "on" does, minus the digits.
@PathGao
PathGao force-pushed the fix/810-toc-toggle-over-text branch from 0eafe63 to 3046aa5 Compare September 21, 2026 18:45
@PathGao
PathGao merged commit 98938f8 into master Sep 21, 2026
4 checks passed
@PathGao
PathGao deleted the fix/810-toc-toggle-over-text branch September 21, 2026 18:46
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