Skip to content

Keep a code block as tall when its line scrolls as when it fits - #258

Merged
rostislavrotaru merged 3 commits into
mainfrom
dev1/18-code-block-scroll-height
Nov 30, 2026
Merged

rostislavrotaru merged 3 commits into
mainfrom
dev1/18-code-block-scroll-height

Conversation

@rostislavrotaru

@rostislavrotaru rostislavrotaru commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Closes #18

The cause

When its line scrolled sideways, the code's bottom padding gave up the scrollbar token, 0.375rem. It did this through a scroll-state(scrollable: inline) container query, which assumes the scrollbar always takes that room.

A scrollbar that lies over the code, as on a phone or in a headless browser, takes none. So a block whose line scrolled was 6 px shorter than one whose line fit.

Measured in the test browser on Linux, macOS and Windows, a one-line block 335 px wide:

Line fits Line scrolls
Block height, Linux and macOS 71 px 65 px
Block height, Windows 70 px 64 px
Room the scrollbar takes 0 px 0 px
Bottom padding 14 px 8 px

The fix

The block now measures the room its sideways scrollbar takes, as its body's offsetHeight − clientHeight. It sets that as --nol-code-scrollbar-height, and the code's bottom padding gives up exactly that:

  • An overlay scrollbar takes nothing, so the padding stays 0.875rem.
  • A classic 0.375rem bar leaves 0.5rem, as before.

The block measures again on every border-box resize of its body, through the ResizeObserver it already has. A scrollbar that takes room grows that box when the line starts to scroll and shrinks it when the line stops.

Until the block has measured, as in prerendered HTML or the first frame of a client render, the padding gives up a likely bar instead:

  • Under a fine pointer, while the line scrolls (the scroll-state(scrollable: inline) query main used), the likely bar is the kit's --nol-scrollbar-size. Mouse desktops, whose Chromium and Safari draw the kit's classic bar, are right from first paint.
  • Elsewhere, as on a phone, the likely bar is none, and the padding stays whole.

Firefox and forced colors draw system bars of other sizes; there the measurement corrects the height once it runs.

Changes, by path

  • src/noldova.ui.components.angular/src/app/components/code-block/code-block-behavior.ts: scrollbarHeight, measured by measureScrollbar in the existing layout observer, which now also watches the body's border box.
  • src/noldova.ui.components.angular/src/app/components/code-block/code-block.component.ts and site-code-block.component.ts: the host sets --nol-code-scrollbar-height from it.
  • src/noldova.ui.components.angular/src/app/components/code-block/code-block.component.css:
    • The bottom padding gives up --nol-code-scrollbar-height, or before it is measured, --nol-code-scrollbar-guess.
    • The scroll-state query now sets that guess to the scrollbar token under (pointer: fine), in place of setting the padding.
  • src/noldova.ui.components.angular/tests/app/components/code-block/code-block-scroll-height.component.spec.ts, new:
    • Where the scrollbar lies over the code: a one-line block is as tall when its line scrolls as when it fits, with its padding whole, at 375 and 1280 pixels in light and dark.
    • With a classic bar's measured 0.375rem set on the body, as the block sets it: the padding gives up 0.375rem, and the block plus the bar's room is as tall as a block whose line fits, at 375 pixels in light and dark.
    • Before the block has measured, with the test browser's fine pointer: the padding gives up the scrollbar token while the line scrolls and stays whole once it fits, at 375 pixels in light and dark.
  • src/noldova.ui.components.angular/tests/app/components/code-block/site-code-block.component.spec.ts: the site block and the code block are compared once both have measured their scrollbar.
  • src/noldova.ui.components.angular/tests/app/components/code-block/code-block-scrollbar.component.spec.ts: the bottom padding is 0.875rem minus the room the scrollbar takes, measured, in place of minus the token.
  • src/noldova.ui.components.angular/tests/app/components/code-block/code-block-code-size.component.spec.ts and code-block-code-size-dark.component.spec.ts:
    • These specs added the token back under the code to match the old rule. That correction is gone.
    • The space under the code is 0.875rem, as over it.

Not covered by a test

The measurement of a classic scrollbar, one that takes room, has no test. The specs run in headless Chromium, which hides scrollbars: even with a styled ::-webkit-scrollbar height, no scrollbar takes room there. The classic-bar spec checks the padding and height arithmetic from a measured value. The measurement itself is checked where the bar takes 0 px.

Checks

  • On the test machines, the code block's, the site code block's and the markdown view's specs pass on Linux, macOS and Windows, 306 tests each, 2 of them skipped.
  • With the old source and these specs, 11 tests fail: the 375-pixel overlay tests, the scrolling code-size tests and both scrollbar-spec tests.
  • The 1280-pixel cases, where nothing scrolls, and the classic-bar cases pass with the old source too. The old rule also gave 0.5rem for a 0.375rem bar.
  • Without the unmeasured guess and the site block's binding, the two tests before the first measure and the site block's comparison fail.

Agent: DEV1 (developer)
Agent-Model: Anthropic Opus 5.5, Medium

The code's bottom padding gave up the scrollbar token's 0.375rem whenever
its line scrolled, whether or not the scrollbar took that room. Where it
lies over the code, as on a phone or in a headless browser, a block whose
line scrolled was 6 px shorter. The block now measures the room its
sideways scrollbar takes, on each border-box resize of its body, and its
bottom padding gives up exactly that.

Issue #18

Agent: DEV1 (developer)
Agent-Model: Anthropic Opus 5.5, Medium
@rostislavrotaru rostislavrotaru self-assigned this Nov 30, 2026

@rostislavrotaru rostislavrotaru left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reviewed: #258 at 055d841
Verdict: Changes needed
Findings: 0 Should fix, 1 Low, as line comments

Agent: REVIEW1 (reviewer)
Agent-Model: Anthropic Opus 5.5, High

Until the block measures its sideways scrollbar, the padding gives up
the scrollbar token while the line scrolls under a fine pointer, so
prerendered pages and the first frame match the measured height.

Agent: DEV1 (developer)
Agent-Model: Anthropic Opus 5.5, Medium
The site code block shares the code block's behavior and stylesheet,
but its host did not set the measured scrollbar height, so its padding
kept the unmeasured guess.

Agent: DEV1 (developer)
Agent-Model: Anthropic Opus 5.5, Medium

@rostislavrotaru rostislavrotaru left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reviewed: #258 at 7f43022
Verdict: Approve
Findings: 0 Should fix, 0 Low, as line comments
Why it's right: the padding gives up only the scrollbar the block measures, with the token as its guess under a fine pointer until then, so a code block keeps one height whether its line fits or scrolls; the site code block now binds the same measured value, and the specs check both before and after the measure.

Agent: LEAD (lead)
Agent-Model: Anthropic Opus 5.5, High

@rostislavrotaru
rostislavrotaru merged commit 57868b7 into main Nov 30, 2026
21 checks passed
@rostislavrotaru
rostislavrotaru deleted the dev1/18-code-block-scroll-height branch November 30, 2026 01:54
rostislavrotaru added a commit that referenced this pull request Dec 1, 2026
Closes #286

Moves the kit to 0.0.48, with what has merged since 0.0.47, so apps can
take the binary file note and the path tooltip from #282, and the tab
marker's tone, close place and dot from #299.

## What changes

- `version.json` is at 0.0.48.
- `CHANGELOG.md` has the 0.0.48 section, one entry per change a consumer
or docs-site reader sees, from #303 (#299), #291 (#280), #281 (#275),
#285 (#282), #263 (#151), #250 (#245), #262 (#138, #223), #260 (#16),
#248 (#233), #258 (#18), #268 (#28), #255 (#234), #254 (#239), #256
(#236), #253 (#238), #252 (#160), #249 (#244), #242 (#231), #269 (#261)
and #259 (#26).
- Left out, as changing nothing the package or the docs site shows: #251
(the header's phone-bar rules written once, the same look), #247
(workflow pins), #264 and #277 (build scripts), #266 (example names and
their check), #267, #271, #272, #273, #274, #276, #289 and #290 (tests
and their tools), #279 and #295 (workflow pins).

## Checks

No test covers these two files. The product names check reads the new
section in CI; it names no product.

Agent: DEV2 (developer)
Agent-Model: Anthropic Opus 5.5, Medium
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.

A code block whose line scrolls is shorter than one whose line fits

1 participant