Skip to content

Keep the reading place on what stands at the landing edge, in the reader's column - #2624

Merged
max-sixty merged 4 commits into
mainfrom
place-at-the-landing-edge
Oct 12, 2026
Merged

max-sixty merged 4 commits into
mainfrom
place-at-the-landing-edge

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

A reading place is now what stands at the landing edge, in the column the reader is using, rather than the first text block in document order plus a pixel offset from that block's start. That offset held only while nothing between the block's start and what the reader saw changed height, so a width change or a revision moved the reader whenever it did. A review of #2562 and #2574 as they sit together on main found the cases below; each became a test that fails on main.

What a place stands on, in order:

  • a drawing the edge cuts (an img, svg, canvas, video, picture, iframe, object, embed, or a custom element holding no text block), or a box that scrolls on its own and is no reading region of its own, kept as how far through its height the edge cuts it. The browser's hit test names it, at the reader's column or the middle of the content. The line below it is recorded too, and stands in when a revision replaces the drawing's node.
  • otherwise the first line at or below the edge, quoted from its first character with the prefix and suffix a comment's anchor takes (anchorForPassage, split out of anchorForRange), measured from that line. Lines above it in the same paragraph can rewrap or be rewritten without moving what the reader sees. Text in a stuck sticky box, and runs under 24 characters (a nav of labels), name no place.
  • the reader's column (the pointer's last x over the box, else focus's) only decides between blocks standing side by side at that line's row.
  • a raw scroll offset is restored only in the same scroller, at the same width, in the same revision; elsewhere the browser's anchoring keeps the box.

Memory: a place holds its focused node and body through WeakRefs, and retainUserIntent holds its source weakly, so a revision that removes the section the reader focused or clicked in frees it (#2574's guarantee, which #2562's places broke). Holds are keyed by scroller id with a WeakRef to the box; writing is a WeakMap.

Also fixed: every bounded region's hold was dropped the first time it was read, because the hold compared region records with === and readingRegions() builds fresh records each call, so since #2562 a pane did not re-apply its restored place while its layout settled.

Behavior changes (main → this, 1440×900 unless stated):

  • a paragraph partly under the banner, reader's line: 1200→600 +84px → +2.1px; 600→1200 −79px (under the banner) → +2.95px; a revision rewriting words above the line +84px → +2.1px.
  • a 2160px figure, reader 40% through: 1200→600 the figure's top landed 451px below the edge → stays 40% through at every width; a same-width revision inserting paragraphs above it threw the reader ~2000px back → −864 → −864.5.
  • a figure with its caption lower on screen: 22%/54% → 40% both ways.
  • two columns stacking at 800, reading the right one: 1255px → 4.45px.
  • a nav of short items stacking above the text, keyboard reader: 40px drift → line kept.
  • the shipped layout-column sticky sidebar: main threw the reader 2353px → paragraph kept.
  • a scrolling div that is no reading region: 47% → 60%/34% → 47.5% both ways.
  • a bounded pane whose content grows two frames after a resize: +200px → held.

Known limits, shared with main: with scroll anchoring off (Safari), an image that loads late after a revision still moves the reader (21% → 22%), because a revision's restore is applied once rather than held; holding it would reverse the rule that a revision ends every hold. focus.js stood/published keep a removed focused node until the next input, and history.js keeps a clicked # link's focus for its entry's life.

Tests: test_a_width_change_keeps_what_stands_at_the_landing_edge (new, nine shapes), test_a_bounded_box_holds_its_place_while_its_layout_settles (new); inside and figure cases on test_live_revision_keeps_the_visible_semantic_reading; test_paging_down_from_a_landed_section_keeps_the_paged_passage measures the word at the edge; test_a_revision_releases_the_served_markup_it_removes focuses a link in the removed section.

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

max-sixty and others added 4 commits October 12, 2026 09:38
…go of removed nodes

A reading place was the first text block on screen in document order, quoted
from its start, plus that start's offset. That held only while nothing between
the block's start and what the reader saw changed:

- A paragraph partly above the edge pinned its first line, so the line the
  reader was on drifted by however much the text above it rewrapped or was
  rewritten: +84px at 1200→600, -79px (under the banner) at 600→1200, and
  +81px for a revision lengthening words above it.
- With the right column of two scrolled, stacking the columns at 800 restored
  the left column's block, 1255px away from the paragraph read.
- With no text on screen (a tall figure), the place was a raw scrollTop that a
  width change re-applied over the browser's scroll anchoring: the figure's top
  landed 451px below the edge.

capturePlace now names the first line whose middle stands at or below the
landing edge, quoted from that line's first character with the context a
comment's capture gives (anchorForPassage, split out of anchorForRange so a
caller holding page segments skips the reading walk), and measures that line.
Blocks are read in the column the reader's pointer, or failing that their
focus, named; a heading is still read whole; words in a stuck box name no
place. A raw offset is taken back only by the same scroller at the same width,
so a width change with no line on screen leaves the browser's anchoring in
charge (figure top stays put, as before #2562).

Memory: a focused place and every intent (retainUserIntent's source) now hold
their nodes weakly, so a place outliving a revision no longer keeps the removed
section alive until the next scroll. Holds are keyed by scroller identity with
a weak box. That also fixes their identity check: a bounded region's hold
compared fresh region records and was dropped on its first reading, so a pane
never re-applied its restored place while its layout settled.

Tests: test_live_revision_keeps_the_visible_semantic_reading gains an `inside`
case (revision rewriting words above the reader's line); the paging-down test
now measures the word at the edge rather than its paragraph's top; the #2574
memory test focuses a link in the removed section; new
test_a_width_change_keeps_what_stands_at_the_landing_edge (figure, right
column) and test_a_bounded_box_holds_its_place_while_its_layout_settles. Each
fails on main.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ep a figure's part across revisions

Review of 1fb2e22 found two regressions against main and confirmed a
pre-existing case:

- A nav of short labels beside the text column became the place: "Part 36"
  first in document order, or under a pointer resting on the nav, put the
  paragraph read 2379px away once the columns stacked. A run shorter than
  24 characters names no place again, as on main.
- A pointer resting in the margin kept only a wide exhibit lower on screen
  that reached it, putting the reader's word under the banner at 600. The
  column now only chooses between blocks standing side by side at the line
  the document order found: blocks overlapping that line's row are asked,
  and one across the reader's column replaces it.
- A same-width revision inserting paragraphs above a text-free screen
  restored the old scrollTop over the new paragraphs (figure top -864 to
  +473 with anchoring off). A raw offset now also has to be read in the
  current revision; and with no line on screen, a drawing the edge cuts (a
  replaced element, or a custom element) is the place, with how far through
  its height the edge cuts it, so a figure keeps the same part at the edge
  as it scales (0.40 at every width, not 0.52) and through a revision that
  keeps its node. Empty boxes draw nothing and are never landmarks, which
  is what sank the hit-tested landmark before.

Tests: test_a_width_change_keeps_what_stands_at_the_landing_edge gains the
nav (pointer on it, and no pointer) and margin-exhibit shapes and holds the
figure to 0.01; test_live_revision_keeps_the_visible_semantic_reading gains a
figure case. Each fails on 1fb2e22.

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

Review of 8731174 confirmed two pre-existing cases:

- A figure cut 40% through by the edge, with its caption 531px down: the
  caption became the place, so 1200→600 left the reader 22% into the
  figure and 600→1200 54%. What the edge cuts is now the place ahead of the
  first line below it; that line is still written down, and stands for the
  drawing where a revision replaces its node.
- A div that scrolls on its own without being a reading region was read as
  page text: its lines move with its own scroll and rewrap, so 600→1200 took
  the edge from 47% to 34% into it. Lines inside a box that scrolls its
  words alone no longer name the page's place, and the edge cutting such a
  box takes it as a drawing is taken. A registered region's scroller is not
  the page's: the hit test stops at anything another scroller carries, so a
  pane never stands in for the page's place.

A pointer resting outside the box's contents no longer aims the hit test.

Run alongside: a drawing whose height changes after a revision. A revision
that gives the figure a taller source keeps the reader 40% into it (main
26%). An image above it that loads after the restore moves it by the image's
height where native anchoring is off, as on main: a revision's restore is not
held while late layout settles, as a width change's is.

Tests: test_a_width_change_keeps_what_stands_at_the_landing_edge gains the
figure-above-caption and box-scrolling-alone shapes; both fail on 8731174.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…er-scrollable boxes as scrolling alone

Review of 1212b2e found two bugs:

- With no reader column and the content box at the window's left edge (a
  600px window, nothing pointed at), `null >= 0` passed the column test, so
  the hit test ran at x = 0 and missed the figure: 600→1200 took the reader
  from 40% to 54% into it. A missing column now always probes the middle.
- `overflow: hidden` counted as scrolling on its own, so a clearfix wrapper
  whose decoration hangs 12px past its foot hid its article's lines from the
  page's place: 1200→600 moved the line at the edge from -2.2px to -17.9px.
  Only overflows the reader can scroll (auto, scroll) count now.

Tests: test_a_width_change_keeps_what_stands_at_the_landing_edge gains
figure-above-caption-from-narrow and box-clipping-what-hangs-past-it; both
fail on 1212b2e.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 60e2898 into main Oct 12, 2026
3 checks passed
@max-sixty
max-sixty deleted the place-at-the-landing-edge branch October 12, 2026 17:51
max-sixty added a commit that referenced this pull request Oct 13, 2026
… revision

Since #2624, a raw scroll offset is taken back only in the revision that
read it, on the reasoning that another revision draws other content there
and the browser's scroll anchoring keeps the box better. Neither holds for
Leaf's own interface across an executable revision: the Threads list and
drawers draw the log, which the revision does not change, their words name
no reading place (capturePlace reads only the document's blocks), and the
reload leaves no box for the browser to anchor. So a reader who had
scrolled the Threads list found it back at the top after every executable
revision (`test_executable_revision_keeps_a_reader_who_scrolled_away_from_their_reply`,
red in the journeys tier since #2624: 0 against a held 790).

`rawOffsetFits` now also accepts an offset from another revision in a box
of Leaf's interface when that box is not the one that read it. A reading
holds the box that read it weakly, under a symbol, so a reading carried
across a reload arrives without it. An in-place revision keeps its box, so
there the browser's anchoring still keeps the list, as before.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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