Skip to content

Keep a comment's pin by its code line through the code block's scroll - #5097

Merged
max-sixty merged 8 commits into
mainfrom
grind/code-scroll-pin
Nov 2, 2026
Merged

max-sixty merged 8 commits into
mainfrom
grind/code-scroll-pin

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

A comment on a line of a code block whose code scrolls, as reveal.js's
theme makes every long one (pre code { overflow: auto; max-height: 400px }), stood its pin in one of two places. A layout pass put it above
the block's top-right corner; a scroll of the code then carried it away
with the lines, 40px for a 40px scroll, until the next pass put it back.
The row also stayed shown while its line was scrolled out of the code's
view.

This happens only where pins are placed by the block: workspace pages,
so every reveal deck, and column pages narrower than the rail needs. On
a desktop column page the row stands in the rail, level with its line,
and the only change there is that it hides while its line is scrolled
out of the code's view.

The cause

The carrier was right: since #3091 a passage's row is carried by its
words (anchorFor), so it moves with the code's scroll. The pass
measured the row against its target instead. The target is the pre,
which the code's scroll doesn't move, so the block seats (the pre's
corner), the words' visibility (clipped by the pre's ancestors, not by
the code inside it) and the offsets the scroll reading and
paintedBox find the row by all disagreed with the carrier. And a
passage in code took the seats built for prose: the seat level with the
line fails whenever the next line reaches as far right, the raised
fallback hangs off the end of the line above, and the slide-left
fallback crosses every word to the window's edge. The pass reached the
block's corner because the margin counted the keyboard stop reach.js
lends the pre (claimed by Copy) as a control, so no seat inside a code
block was clear.

What changed

  • Visibility. wordsShown answers what shows of each quoted line
    through every box holding it, the code included, in the pass and in
    the scroll reading, which also hears a scroll of a box inside the
    target. The row shows while one quoted line does, and comes back with
    it.
  • One seat on a block of preformatted lines. A block whose text keeps
    its spaces and doesn't wrap its lines (white-space-collapse: preserve, text-wrap-mode: nowrap, as reveal's pre and Leaf's
    document code blocks compute) has one seat per pin, at the right edge
    of what shows of it (preformattedBlock): a line's pin inside the
    block, its centre on what shows of the passage's first line still in
    view, and the block's own pin above its top-right corner, where main
    stood it. A scroll carries a line's pin with its line; once that
    carries its middle past the quoted lines that show, the scroll reading
    brings a pass in the next frame that seats it by the first line still
    in view. seatRow keeps such a pin
    level: it takes that seat whatever words it covers, or slides left
    past a control or a pin already seated there, never up, down or past
    words. A line's carrier follows the line down the block but not
    sideways (axes: "y", as a rail row's), so a sideways scroll of a long
    line leaves the pin at the edge. Wrapped text that keeps its spaces,
    such as a pre-wrap paragraph or lf-code's lines, keeps prose seats.
  • Block controls are controls. coverIn never counts a lent reach
    stop as a control, as control-selectors.js already says of it. It
    counts instead the box of every control block-controls.js stands over
    a block (blockControlBoxes), at rest as when shown, so no pin stands
    on Copy or a recording's bar. blockControlBoxes reads each control's
    transform insets from its block first, every block before any control
    is written, since a deck moves and scales its slides with no resize to
    say so; on a reveal slide reached after load in Firefox, Copy's box at
    rest had been read from before the move. A heading's link, made only
    when it shows, has no footprint, since counting it would move pins on
    hover.
  • Prose fallback in the words' frame. passageBlock, the block a
    prose passage's pin falls back to, is the outermost box from the words
    to the target that every scroll moving them moves too.
  • Where a row stands between passes. standsBy records each row's
    offsets from its carrier's anchor, on the axes the carrier follows (or
    from the document's origin in the root lane). standsNow reads where
    the row stands now for the scroll reading, paintedBox and a held
    pin, which replaces the separate record of a held pin's seat.

In Chromium, #5058's scrollend pass inside a scaled box now writes the
insets the scroll left for such a row instead of moving it back to the
block's corner. Firefox and WebKit still need it for the scale drift.

Visible changes

  • A line's pin in a code block, where pins are placed by the block,
    stands level with its line at the block's right edge rather than above
    the block's corner (main). On a phone it covers the last visible
    characters of a line that reaches the edge, as Copy does on line 1.
    Still pair (760px, main | this branch):
    ~/.tmp/leaf.agent-a531589747ffee0ab/line-pin.png.
  • A first-line pin that meets Copy slides left of Copy, level with its
    line, over the line's last words (pair:
    ~/.tmp/leaf.agent-a531589747ffee0ab/first-line-pin.png). Accepted
    cost: a first-line pin beside Copy can cover the last characters of its
    own passage when that line reaches Copy's column, as nam of
    profile_name) at 760 (pair:
    ~/.tmp/leaf.agent-a531589747ffee0ab/first-line-at-copy.png).
  • An element comment's pin on a code block stands above the block's
    top-right corner, as on main (pair:
    ~/.tmp/leaf.agent-a531589747ffee0ab/element-pin.png; the pin inside
    main's block belongs to the scrolling block above it, which main stands
    247px below its line after a pass).

Evidence

Real reveal.js 5.1 deck (embedded, scale 1.22) in a layout-workspace
page at 1440x900, leaf-dev probe --base. Slide 1: comments on step_05
(the code's line 7) and on the whole pre. Slide 2, reached with
Reveal.next() after load: comments on the whole pre, on line 1 and on
step_03. dy is the pin's top less its line's top (its centre at +16
lies inside the line); right is the pin's right edge less the pre's:

main this branch
Slide 1, step_05 dy +321 to +322, right −9 (below the block) dy +3, right −28, all three engines
Slide 1, the pre 30px above the block's top, right −9 29–30px above, right −10
Slide 2, line 1 dy +408, right −9 dy +2 to +4, right −28 (ends where Copy begins)
Slide 2, step_03 dy −1 to 0, right −1103 dy +3 to +4, right −28
Slide 2, the pre pin bottom 4px above the block 3px above
Slide 2, Copy pressable pressable, elementFromPoint at its centre is Copy, all three engines

On slide 1, scrolling the code 200px hides the step_05 row in all three
engines (main kept it shown, from a line out of view) and scrolling back
shows it at the same place. At d5c51bb0d, the review found Firefox's
slide-2 element pin standing on Copy and a click on Copy timing out.

Column page at 760 and 390 in Chromium and 760 in Firefox (the review's
states), this branch:

  • A line in a short block, in a scrolling block, and beside an element
    comment: dy −4 or −5 (centred on the line), right −10, or −24 in the
    scrolling block, whose code box sits inside the pre. main: −93,
    −173 then +247 after a pass, and +0 from a line scrolled out of view.
  • The block's own pin: 29px above the block's top, right −10 (main −30,
    −9).
  • The first line beside Copy: dy −5, right −37, slid left of Copy. A long
    first line ending under Copy: pin at x673–699 over nam of the
    commented profile_name), Copy at x708–732 and pressable.
  • A line wider than its block: level at right −10; after scrolling the
    block sideways, the start's row hides and the tail's shows at right −10.
  • Two comments on adjacent lines: the second slides left of the first
    (right −45). At 390 a scrolling block's line reaching the edge: right −24,
    inside the code box (main: 273px above the line; this PR's first head:
    x4, at the window's edge).
  • A prose passage, and lf-code lines with neighbours as long as the
    commented one (at 1280, 760 and 390): the same seats as main. A
    pre-wrap paragraph's pin stands where the same paragraph's does
    without pre-wrap (the test below).

The new tests fail on the head before each fix and pass now, in
Chromium, Firefox and WebKit:

  • test_a_pin_on_a_line_of_a_scrolling_code_block_marks_that_line (short
    neighbours, long neighbours, 390px): the pin's vertical centre lies
    inside its line's box and the pin inside the code box; a 40px scroll
    carries it with no layout pass and a forced pass leaves it there; it
    hides while the line is out of view. 290fcb8cb failed it (30px high;
    x4 at 390).
  • test_a_pin_on_a_code_block_s_first_line_leaves_copy_pressable
    (column, and a slide moved after load): no overlap with where Copy
    shows, and a Playwright click on Copy. 290fcb8cb failed the column
    case; d5c51bb0d failed the moved slide in Firefox.
  • test_a_pin_on_lines_partly_scrolled_away_stands_by_one_still_shown
    (a quote of eight lines with two and a half scrolled past the code
    box's top, and one with 6px of its first line at the box's foot): the
    pin's middle lies beside a quoted line in view, after the scroll and
    after a forced pass, and the row hides once none shows. fa60f4806
    failed all six cases (the pin above the box, or below it), as Tend's
    review found with lines 4–11 and the code scrolled 180px.
  • test_a_code_block_s_own_pin_stands_above_its_corner: d5c51bb0d
    failed it (the pin stood inside the block, under Copy).
  • test_wrapped_prose_that_keeps_its_spaces_seats_its_pin_as_prose:
    d5c51bb0d failed it (the pre-wrap pin stood at the right edge).
  • A runtime case for the level seat in seatRow.

Checks run

  • uv run pytest on test_scrollers.py, test_pins.py,
    test_clusters.py, test_card_placement.py, test_entries.py,
    test_render_margin.py, test_rail.py, test_status.py,
    test_render_heading_links.py, test_render_code_reading.py,
    controls/test_recording_bar.py, test_opening_threads.py, and the
    passage and Copy tests of test_render_send_placement.py and
    test_render_anchors.py: all pass but five that fail the same way on
    main: test_release_notes_pins_under_a_finger_stand_by_the_words_they_decide,
    test_a_finger_hides_the_annotations_from_the_leaf_s_menu,
    test_suggestion_actions_stay_reachable_through_a_decision_and_its_undo
    (an unchanged style write at teardown, in earlier runs only),
    test_a_new_anchored_comment_keeps_the_users_thread_view[760-False] and
    test_a_quoted_passage_keeps_its_inline_attachment_before_and_after_send[pointer-900]
    (the thread card never opens after the send).
  • test_scrollers.py at the head (58 passed, the new cases in all
    three engines), pnpm run test:runtime (747 passed), pnpm run build:browser, pnpm run check:browser, pre-commit on the changed
    files.

Not verified

  • After reveal's animated slide change in Firefox, the reading taken on
    slide 2 still shows Copy's box at rest at its unscaled place: the last
    pass ran while Copy was still hidden (its block's near-window
    observer had not fired), and nothing reads it again once Copy shows. On
    that slide no pin needed to keep off Copy and Copy stayed pressable;
    a line-1 pin whose seat met Copy there would stand on it until the next
    pass. A slide moved without a transition is covered by the test above.

  • A code block inside a box that scrolls sideways around it: a line's
    pin follows its line down the block only, so that outer scroll leaves
    it where the window holds it until the next pass, as it does a rail
    row. Accepted.

  • A passage in a scroller inside a widget's shadow tree inside the
    target, and a real trackpad scroll (probes and tests set scrollTop).

Calls Max may reverse

  • A line's pin follows the line's scroll down the block but not
    sideways, which keeps it at the edge through a sideways scroll of a
    long line.

Part of #5024

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

max-sixty and others added 7 commits November 2, 2026 00:35
A comment on a line of a code block whose `code` scrolls, as reveal.js's
theme makes every long one (`pre code { overflow: auto; max-height:
400px }`), stood its pin in one of two places. A layout pass put it above
the block's top-right corner; a scroll of the code then carried it away
with the lines, 40px for a 40px scroll, until the next pass put it back.
The row also stayed shown while its line was scrolled out of the code's
view, and stood below the block for a line below the code's fold.

The carrier was right: since #3091 a passage's row is carried by its
words (`anchorFor`), so it moves with the code's scroll. The pass
measured the row in its target's frame instead. The target is the `pre`,
which the code's scroll doesn't move, so the block seats (the `pre`'s
corner), the words' visibility (clipped by the `pre`'s ancestors, not by
the `code` inside it) and the offsets the scroll reading and `paintedBox`
find the row by (from the target's box) all disagreed with the carrier.
The pass reached the block's corner because the `pre` carries the
keyboard stop Copy claims (reach.js lends it), and the margin counted
that stop as a control, so no seat inside the code block was clear.

Now a passage's row is measured from its words:

- `wordsShown` clips the words through every box holding them, the
  `code` included, in the pass and in the scroll reading. The scroll
  reading also hears a scroll of a box inside the target that moves the
  words. The row is withheld once its line leaves the code's view and
  comes back with it.
- `passageBlock` is the block a passage's pin falls back to: the
  outermost box from the words to the target that every scroll moving
  them moves too, short of a box that scrolls them or carries a lent
  stop. Words standing directly in the `code` have none.
- `coverIn` no longer counts a lent reach stop on a box holding the
  passage's words as a control for that passage's pin, since reach.js
  lends it for the keyboard to reach and scroll those words. The pin
  can stand by its line inside a code block. An element comment on a
  code block still stands above it, clear of Copy.
- `standsBy` records each row's offsets from its carrier's anchor (or
  the document's origin for the root lane), which is what the browser
  moves it by. `standsNow` reads where the row stands now for the scroll
  reading, `paintedBox` and a held pin, which replaces the separate
  `seats` record of a held pin's place.

In Chromium, #5058's `scrollend` pass inside a scaled box now writes the
insets the scroll left for such a row, rather than moving it back to the
block's corner. Firefox and WebKit still need it for the scale drift.

Evidence (`leaf-dev probe`, 1280x800, a `layout-workspace` page with a
`pre > code` scroller of 60 lines and a comment on line 24; pin offset
from the line's top after the scroll and after a forced pass, the same in
Chromium and Firefox within a pixel):

| code scrollTop | main: scroll | main: pass | branch: scroll | branch: pass |
| --- | --- | --- | --- | --- |
| 0 (line below the fold) | shown | shown | withheld | withheld |
| 200 | 0 | −313 (block corner) | −30 | −30 |
| 240 | −313 | −273 | −30 | −30 |
| 380 | 0 | −133 | −30 | −30 |
| 600 (line above the box) | shown, off screen | withheld | withheld | withheld |

On an unscaled copy of reveal's rule, the new test fails on main in
Chromium and Firefox with the pin 1011px right of and 193px above its
line; with that assertion removed, it fails where the pass moves the pin
40px from where the scroll carried it.

Other passages keep their seats: probes of a paragraph, a table cell, an
SVG label and an element comment on a code block place the pin exactly
as main does. A passage in a card that clips its own words keeps main's
seat too. A passage in a code block that fits now stands by its words,
or with every seat by its words covered, beside the code's first line,
where main stood it above the block's corner.

Part of #5024

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	dist/kernel/runtime/bundle-content-layout.js
Review of the reveal.js 5.1 deck found the pin for a commented line
standing 30px high, at the end of the line above, in Chromium and
Firefox, and on the block's left border in WebKit. At 390px a line
reaching a scrolling `code`'s edge slid its pin to the window's left
edge. A passage in code took the seats built for prose: the seat level
with the line fails whenever the next line reaches as far right, the
raised fallback hangs off the end of the line above, and the slide-left
fallback crosses every word to the window's edge.

- A passage in preformatted text (`white-space-collapse: preserve`) has
  one seat: level with its line, at the inside right edge of what shows
  of its nearest block (`preformattedBlock`). `seatRow` keeps such a pin
  `level`: it takes that seat over the line's last words, or slides left
  past a control or a pin already seated there, never up, down or past
  words. Its carrier follows the line down the block but not sideways
  (`axes: "y"`), so a sideways scroll of the block's lines leaves it at
  the edge.
- `coverIn` never counts a lent reach stop as a control, as
  control-selectors.js already says, and counts instead the box of every
  control block-controls.js stands over a block (`blockControlBoxes`),
  at rest as when shown, so no pin stands on Copy. A heading's link,
  made only when it shows, has no footprint. Both lent-stop clauses
  (`coverIn`'s and `passageBlock`'s) are gone. An element comment's pin
  on a code block now stands inside the block's corner, under Copy,
  where main stood it above the corner.
- Copy writes its transform insets where it first stands, as a heading's
  link and a recording's bar already did, and every block control reads
  them again after a resize, so its box at rest is where it shows on a
  scaled slide in Firefox. Without that, the element pin stood on Copy
  at load and moved 31px when the pointer first revealed Copy.

Tests: `test_a_pin_on_a_line_of_a_scrolling_code_block_marks_that_line`
asserts the pin's vertical centre lies inside its line's box and the pin
inside the code box, with short neighbours, with neighbours as long as
the line (the deck's shape) and at 390px where the line runs past the
code's edge; `test_a_pin_on_a_code_block_s_first_line_leaves_copy_pressable`
needs no overlap with Copy and a Playwright click on it. All four fail
on the previous head in Chromium, Firefox and WebKit (pin 30px high;
x=4 at 390; overlapping Copy) and pass now. A runtime case covers the
level seat in `seatRow`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… on a moved slide

Second review of the reveal.js deck and the column pages:

- On a reveal slide reached after load, Firefox kept Copy's box at rest
  where the slide had been, so the margin kept clear of the wrong box,
  the pin took Copy's corner, and a press on Copy reached the pin.
  `blockControlBoxes` now reads each control's transform insets from its
  block itself, every block before any control is written, once for
  every pin a pass seats. That covers a first stand, a resize and a
  slide change, so the resize re-read and Copy's write where it first
  stands are gone, and code-copy.js matches main.
- A paragraph with `white-space: pre-wrap` took the code seat, since its
  spaces are kept, and stood its pin at the right edge over the words
  ending its line. The line seat is now for text that keeps its spaces
  and doesn't wrap (`text-wrap-mode: nowrap`), as reveal's `pre` and
  Leaf's document code blocks compute; wrapped text, `lf-code`'s lines
  included, takes prose seats as on main.
- A comment on a whole code block stands its pin above the block's
  top-right corner, as on main, so it reads apart from a line-2 pin at
  the block's right edge. `preformattedBlock` takes the box holding a
  passage's words or the target of a row about the block itself, and the
  one seat it gives is at the block's right edge: level with the line
  for a passage, above the top-right corner for the block. Only a line's
  pin follows its line down the block alone (`axes: "y"`); the margin
  records beside that rule that a sideways scroll of a box around the
  block leaves the pin behind until the next pass.

Tests: a line-1 pin on a slide moved after load must leave Copy
pressable (fails on the previous head in Firefox), a block's own pin
stands above its corner with a line pin level with its line (fails in
all three engines), and a `pre-wrap` paragraph's pin stands where the
same paragraph's does without it (fails in all three engines).

Co-Authored-By: Claude Opus 5.5 <[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 multiline code quote can leave its pin outside the code block while part of the quote remains visible; the inline finding has the reproduction.

@max-sixty
max-sixty marked this pull request as ready for review November 2, 2026 12:01
Tend's review of #5097 found a pin for a quote of several lines of a
scrolling code block seated by the passage's first line wherever that
line had gone: with lines 4–11 quoted and the code scrolled 180px, the
pin stood at y=15–41 above a code box starting at y=118, while the row
stayed shown because later quoted lines still showed. Seating read the
first raw line; visibility read the whole passage.

Both now read one thing. `wordsShown` answers what shows of each quoted
line, in order, the lines nothing shows left out. The row shows while
one does; a pin on preformatted lines stands at the block's right edge,
level with what shows of the first of them. A scroll carries the pin
with its line, and once that carries its middle past the quoted lines
that show, `targetShown` answers no for a pin kept `level` (recorded in
`standsBy`), so the scroll reading brings a pass at once, in the next
frame, which seats it by the first line still in view. Waiting for some
later pass would have left it above or below the code box meanwhile.

`test_a_pin_on_lines_partly_scrolled_away_stands_by_one_still_shown`
scrolls two and a half quoted lines past the code box's top, and in a
second case leaves 6px of a quote's first line showing at its foot. The
pin's middle must lie beside a quoted line in view, after the scroll and
after a forced pass, and the row hides once no quoted line shows. All
six cases fail on fa60f48 (pin above the box at y≈64, or below it at
y≈508) in Chromium, Firefox and WebKit, and pass now.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@max-sixty
max-sixty merged commit c6628dc into main Nov 2, 2026
5 checks passed
@max-sixty
max-sixty deleted the grind/code-scroll-pin branch November 2, 2026 13:08
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