Skip to content

Keep a page's place below the banner across width changes, and derive the focus margin from the sticky-header slot - #2302

Merged
max-sixty merged 14 commits into
mainfrom
reading-place
Oct 10, 2026
Merged

max-sixty merged 14 commits into
mainfrom
reading-place

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner

Two follow-ups from #2039, each fixed where its cause is rather than where it showed.

A page keeps its place below the banner when the window changes width

The follow-up said Leaf's reading-position code overrode the browser's scroll anchoring for a pane on a document page: after a jump, narrowing moved the landed line 36px. The pane was right. Below about 800px the banner takes a second row, and the browser's anchoring keeps the reader's line at the same distance from the window's top, which is then under the taller banner. A plain document page left the line covered; a pane only escaped because its own restore measures from the landing band below the banner.

  • reading-regions.js watches the page as it watches regions: its width and the top of its landing band, announced as a shift with no region, in the same measurement that announces main's window-height shifts. regionsSettled waits for it. A band change without a width change, such as a page tab strip arriving, is adopted rather than read as unsettled.
  • version.js moves the page with the band, then restores regions against the new band from the readings snapshotted when the shift was announced (Restore the pre-resize reading before scroll recording replaces it #2303). The page keeps no record of its own: the browser's anchoring already holds its words, and main now keeps a focused control in view across the reflow.
  • Narrowing then widening returns a pane's line to where the reader left it (it ended 36px low).

The focus margin is derived from the sticky-header slot; a visual review's navigation stays in reach

The visual review's case navigation and view controls scrolled away above a pair taller than the window. Sticking them needs focus inside a stuck header to scroll nothing. #2135 did that by having each header declare where its controls stand (--lf-head-inset) and each scroller restate its landing room, so every new sticky header, the visual review's two included, needed its own declarations.

  • The layer's focus margin is read from the sticky-header slot (styles/components/surfaces.css). A scroller's band has two parts, the slot it covers whole (--lf-top-covered) and the room below it (--lf-landing-room); the root's scroll-padding-top reads the same two, and a box that scrolls restarts them (state.css). A focused box's --lf-top less the covered slot is the headers over it the band does not count, so it lands below them; a box in a header that sticks at its top also takes the room back, so it counts as shown where it sticks.
  • The runtime marks every box that sticks at its top (data-lf-sticks, reach.js), so a header declares nothing unless its controls stand inset from its stick line (the tab strip, the trace toolbar, the screenshot toolbar). The thread title's and diff header's declarations, the tab panels' landing-room restatement and --lf-landing-gap are gone.
  • The visual review's pane header sticks under the banner at a stated height (two rows where the review is narrow) and stacks --lf-top for the cases; the shown case's view controls stick under it. The capture stage isolates its stacking, so a flip's handle and marked regions pass under them.

The CSS changes are in the styles/ sources (#2252); the committed sheets are rebuilt from them.

Tests

  • test_a_page_keeps_its_place_below_the_banner_as_the_window_changes_width (document and pane): without the change, the document fails narrowing and the pane fails widening.
  • test_a_visual_review_in_flow_keeps_its_navigation_over_a_tall_pair: without the change, the navigation stands 495px above the window.
  • test_focus_in_a_stuck_header_leaves_the_page_where_it_is keeps passing with every per-header declaration but the tab strip's removed.

This was written by Claude Code on behalf of max-sixty

max-sixty and others added 12 commits October 8, 2026 23:17
When the window narrows past about 800px the banner takes a second row,
36px taller. Chrome's scroll anchoring keeps the line the reader was on
at the same distance from the top of the window, which is now under
the taller banner: after a jump to a line in a plain document, narrowing
left it covered (banner bottom 78px, line at 59px). A place in Leaf is
measured from the landing band below the banner, so the page now moves
with that band. Widening moves it back.

Reading regions already kept their place across a width change, which
made a pane the page carries look like the odd one out: its landed line
moved 36px on narrowing where a plain page's stood still. The pane was
right and the plain page was wrong. The pane also kept the line 36px low
after widening again, since its restore only kept the focused line in
view; it now returns to where the reader left it.

The page is now watched like a region: `reading-regions.js` observes the
root and announces a shift with no region when the page's width or the
top of its landing band changes, and `regionsSettled` refuses a record
until then. `version.js` moves the page by the band's change and keeps a
visible focused control in view. The page's record holds only that
focused place. Reading its words would scan every block above the
window on each scroll (6.7ms a capture near the end of how-it-works),
and an offset would undo the browser's anchoring.

The same mechanism kept a focused control in view at the top of a plain
page, where the browser anchors nothing: a focused option at 988px of an
1100px window ended at 1606px after narrowing to 420px; it stays in view
now, as it already did inside a region.

`test_a_page_keeps_its_place_below_the_banner_as_the_window_changes_width`
covers a document and a pane; on main the document fails narrowing
(-31px against 5px below the band) and the pane fails widening.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…review's navigation stuck

A control in a stuck sticky header stands inside its scroller's landing
band: the root's band starts 12px below where headers stick under the
banner. On every focus the browser scrolled toward the control, and the
stuck header never came out from under the band, so the page crept on
each focus: 17px under a diff's file header, 14px under the trace
toolbar, and 313px under a page tab strip, which stands wholly inside
the band it is counted in.

The layer's focus margin is now read from the sticky-header slot rather
than declared per header (shadow.css). A scroller's band is stated in
two parts: the slot it covers whole (`--lf-top-covered`: the banner and
a page tab strip on the root, the slot's start in a box that scrolls)
and the room below it (`--lf-landing-room`: 12px on the root, none in a
box that scrolls unless it states `--lf-landing-room-start`, as the
Threads list does). The root's scroll-padding reads the same two. A
focused box's `--lf-top` less the covered slot is the headers stacked
over it that the band does not count, so a focused row lands below them;
a box in a header that sticks at its top also takes the room back, so a
control focused where its header sticks counts as shown. The runtime
marks every box that sticks at its top (`data-lf-sticks`, reach.js), so
no header declares anything: the diff file header and its action, the
page tab strip, the Threads list title, a sticky Ask's options, the
trace toolbar and tree summary, and a margin thread's message head are
all covered. This supersedes the per-header `--lf-head-inset`
declarations of the unlanded agent-a99a6117121b1d35c branch.

With focus settled, the visual review's case navigation and view
controls stay in reach over a pair taller than the window. The evidence
pane's header sticks under the banner at a stated height (one row of
its controls) and stacks `--lf-top` for the cases, so a focused
disposition lands below it; the shown case's view controls stick under
it, padded by the focus ring's room. In a workspace the pane's body
scrolls, so the header already stands above it and the view controls
stick at the body's top. The capture stage isolates its own stacking,
so a flip's handle and marked regions pass under the stuck controls.

The page shift from the previous commit also adopts a band change that
comes without a width change, such as a page tab strip arriving, rather
than reading the page as unsettled until the window next changes.

`test_focus_in_a_stuck_header_leaves_the_page_where_it_is` fails on main
with -313px and -17px.
`test_a_visual_review_in_flow_keeps_its_navigation_over_a_tall_pair`
fails on main with the navigation scrolled 495px above the window, and
also focuses the case select, whose control stands in Web Awesome's
shadow tree.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…out a resize

A column's sidebar sticks and scrolls, and was marked to stick but not
to scroll, so it restarted `--lf-top` itself but kept the root's covered
slot and landing room: its links took a focus margin of about -60px, and
Shift+Tab up a scrolled contents map landed a link out of sight. Every
box that scrolls is now marked, sticky or not; it restarts its landing
band (`--lf-top-covered`, `--lf-landing-room`), and only a box that does
not stick restarts `--lf-top`, which a sticking box reads for its own
`top`.

A band that moves without a width change, as a page tab strip arriving
does, changes no observed size where the body is held to the window (a
short page, a workspace), so the body observer missed it and the page
read as unsettled, recording nothing, until the window next changed.
It is now adopted wherever the page's geometry is read, and the body
observer is gone.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The previous commit restarted the landing band on every box that
scrolls, sticky ones included. A page tab strip sticks and scrolls
sideways, so its names kept the banner's slot but lost the covered
band, took a focus margin of the banner's height, and crept the page
again. A sticky box now keeps all three of `--lf-top`,
`--lf-top-covered` and `--lf-landing-room`, and a column's sidebar,
which sticks and scrolls what it holds, restarts them itself beside its
`--lf-top`. Its links are not a stuck header's controls, so it also
withdraws `--lf-head-inset`, and a focused link keeps the focus ring's
room (5px) rather than landing flush with the sidebar's top.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…eave sticky boxes unmarked as scrollers

The page's record kept any visible focused element as a place to keep
in view across a width change. A page tab's panel takes focus from a
click on its words, so after reading far down a tab and narrowing the
window, the restore brought the panel's top into view and lost the
reader's place (`test_resume_writing_reveals_page_editor_from_a_covering_panel_and_keeps_back[True]`).
A box holding what the user reads is no place the box itself can keep,
so the page now records a focused control only while the user sees it
whole (`captureFocusedControl`, reading-place.js).

A sticky box is again left unmarked as a scroller, as before this
branch: it keeps its slot and landing band, and a column's sidebar
restarts them itself, so the restart needs no exception for it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
main landed #2135, which fixes focus creeping under stuck sticky headers
with a per-header `--lf-head-inset` and a root landing room that counts
the page tab strip. This branch reads the margin from the sticky-header
slot instead (`--lf-top` less `--lf-top-covered`), with every top-sticky
box marked by the runtime, so the kernel conflicts take this branch's
mechanism. Its declarations of a zero inset (the Threads title, a diff's
file header) and the tab panel's reset landing room are dropped; its
non-zero insets stay as refinements of where a revealed control lands.
#2135's fuller creep test (in a page tab, after the tabs, the file
action, and the code's sideways scroller) replaces this branch's copy
and passes.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…rked controls

main made the page tab strip sticky in every non-side tab set and kept
its panels' reset landing room, which the derived focus margin does
without, so that line goes. main's visual review (#2098) puts the case
picker on its own row in a narrow review, so the sticky header states
two rows there. The visual review's navigation test opens the inspector,
which now folds into a disclosure, and names Next exactly beside Next
unreviewed. The sticky-header creep test drops the diff's file action:
an inline diff has no file press since #2175 removed review marks, and
the test failed on main for it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
main (#2252) generates the kernel and package sheets from sources under
`styles/`, so the derived focus margin, the root's covered band, the
dropped landing-room restatements and the visual review's sticky
navigation now live in those sources, and the sheets are rebuilt from
them. main also shifts every region when only the window's height
changes; the page's own width and band check joins that same
measurement, still observed on the root so it is seeded on a page
without regions.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
main's #2285 moved the in-view rule to user-place.js and dropped the
import the page's whole-control check still reads.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A resize can replace a region's saved place before this deferred restore reads it. readingRegionTransition schedules restoreShifted for the next render, but a resize-induced scroll event can run queueRecord after measureRegions has marked the region settled; that recording overwrites regionViews with the moved position. The restore then uses that new position, so a focused inline editor can leave the viewport instead of keeping its pre-resize place. PR #2303 fixes the overlapping version.js path by snapshotting the region readings when the shift is reported. That fix needs to be reconciled with this branch before it lands.

max-sixty and others added 2 commits October 10, 2026 15:21
#2303 snapshots the region readings when a shift is announced, so a
scroll event the resize causes before the restore cannot replace them.
The page's focused-control reading has the same exposure, so it is
snapshotted with them.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A focused control at the top of a page stays in view as the window
narrows without it, so only the band move remains. The test's focus
case opens a fresh page: reusing the scrolled one met a stale pane
reading that main restores on a window-height change.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 03c671e into main Oct 10, 2026
6 checks passed
@max-sixty
max-sixty deleted the reading-place branch October 10, 2026 23:50
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