Repository navigation
Give a reading key the page can't take to its largest pane, and keep the page ahead of it - #5456
Conversation
…press in it In a workspace, j, k, d and u moved nothing from a fresh load, and since #5228 they also moved nothing after a click on a pane's words or a wheel in it. The first press now moves the page's largest pane with more to show, and a press or wheel in a pane gives that pane the keys. #5228 widened pageDocument() to body, so inPage(document.body) became true, and focus on the body, which stands on nothing, read as standing in the page. focusInPage answers that question once for userReadingRegion, pageReadingRegion and version.js's place recorder, whose page place outranked the one the reader made in a pane. With nothing named, mainReadingRegion answers where the page has nothing to scroll, and a step the keys take names its region as a wheel does, so a walk goes on from where it reached. Closes #4062. The focus mark and the pane-to-pane key stay postponed until a user loses track of the active pane. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Takes mainReadingRegion, actedIn and their tests and docs off this branch, for a separate proposal, and returns #4062's reference to Refs. What stays is focusInPage, which the three readers #5228 changed ask: userReadingRegion, pageReadingRegion and version.js's place recorder. A new test holds the wheel and the walk from a pane, with the rail holding the most to scroll so that a pane chosen for the user can't pass it. Refs #4062 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…croll On a fresh workspace load, j, k, d and u moved nothing: nothing names a pane yet, and the page has nothing to scroll, or only the height of a header or footer beside main. With no region named the page now takes the step while it can, and a step it can't take goes to the shown region with the most to scroll in that direction, the first in reading order of two that tie. That step names the region, so later keys and a walk go on from there. Choosing reads every region, and only a step with no region named that the page can't take pays for it. This is a new policy for Max to decide; it sits on the repair in #5425. Refs #4062 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…first Review of the fallback found three faults, each measured in Chromium and Firefox: - `k` at a long page's top chose a following log in view, which then stopped following, and later keys moved the log rather than the page. A step up now chooses only on a page that doesn't scroll, which still lets a fresh `k` move a workspace's following log. - Ranking by scroll range alone moved alert-review's side list at 900x600 rather than the item beside it. Panes now rank by area in whole pixels, then range, then reading order, which still picks Proposed on current-proposed-comparison. - After a hand-off `k` never returned the page the height of a header or footer beside main. A chosen pane now stays behind the page in both directions until the user acts (`chooseReadingRegion`, `chosenReadingRegion`). Refs #4062 Co-Authored-By: Claude Opus 5.5 <[email protected]>
test_motion_preference_changes_are_heard_without_reloading stubs requestAnimationFrame and reads a frame request after `d` as the glide starting. rendering.js asks for a frame only when none is pending, so a frame already queued takes the glide's first tick without a new request, and the count read 0. On main the keydown recorder, which focusInPage now stops for focus on the body, happened to make the request, so the test failed alone on this branch and passed in a batch. It now lets the page render what it queued before stubbing. With the tick's own reduced-motion check removed it fails, "an active glide kept moving". Refs #4062 Co-Authored-By: Claude Opus 5.5 <[email protected]>
test_motion_preference_changes_are_heard_without_reloading stubs requestAnimationFrame and reads a frame request after `d` as the glide starting. rendering.js asks for a frame only when none is pending, so a frame already queued takes the glide's first tick without a new request, and the count read 0. On main the keydown recorder, which focusInPage now stops for focus on the body, happened to make the request, so the test failed alone on this branch and passed in a batch. It now lets the page render what it queued before stubbing. With the tick's own reduced-motion check removed it fails, "an active glide kept moving". Refs #4062 Co-Authored-By: Claude Opus 5.5 <[email protected]>
#5468 landed the same body-focus predicate for userReadingRegion and pageReadingRegion, as a local focusInPage in reading-regions.js, and its own fix to the motion test. This keeps main's motion test, and keeps one focusInPage, in passages.js with main's wording, since version.js's place recorder, which main left on inPage, reads it too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e-fallback Carries #5425's merge with main: one focusInPage in passages.js, and main's motion test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
The choice scans every region on each press, and the description's own numbers put it outside AGENTS.md's Responsiveness budget: the first j at 801 panes takes 26 to 33 ms against the 8 ms a keystroke gets on the largest scaling page, and a key that finds no pane (k on a fresh workspace) pays the scan on every press. That section also asks that an input's work not grow with how much the page holds, so a ranking redone for the whole page on a keystroke is the shape it rules out. Inline note below on one way to keep the rule without the scan.
… focusInPage one home (#5425) A key pressed with focus on the body, which is where focus stands after a click on words or a wheel, no longer records a place for the page. That place outranked the one the reader made in a pane, so a window narrowed afterwards left them at the top of the page rather than on the paragraph they had read. Recording it on every keydown also cost 303.8 ms per key on a workspace of 801 panes. Refs #4062. That issue's fresh-load gap, where the keys move nothing before the user acts in any pane, stays open here; choosing a pane for the user is proposed separately in #5456. ## Cause #5228 widened `pageDocument()` from `main` to `body`, so `inPage(document.body)` became true. The browser gives the body focus whenever focus stands on nothing. Three readers asked whether focus stands in the page, and each then answered yes. #5468 fixed two of them, `userReadingRegion` and `pageReadingRegion`, with a local `focusInPage` in `reading-regions.js`, and fixed `test_motion_preference_changes_are_heard_without_reloading` too. The third, `recordCurrentLocation` in `version.js`, still reads `inPage` on `main`. ## Change `focusInPage` moves to `passages.js`, beside `inPage`, and all three readers import it: one home for the question, with #5468's wording. `browser/AGENTS.md`, "One answer for each question", names it. ## Evidence A wheel in a pane, a key, then a window narrowed to 520 px, in Chromium: on the parent of #5228 and on this branch the page returns to the paragraph the reader had reached (`scrollTop` 941). With `inPage` back in the recorder it stays at 0. Keydown dispatch for a key pressed with focus on the body, on a workspace of N panes, in ms. The `main` figures are one run at 22accdd, and this branch's the range over three rounds before the merge: | Panes | `main` | This branch | Only the recorder back on `inPage` | | ----- | ------ | ----------- | ---------------------------------- | | 51 | 2.7 | 0.4 to 0.8 | 2.6 | | 201 | 21.6 | 1.0 to 1.3 | 23.8 | | 801 | 303.8 | 1.4 to 1.9 | 310.1 | On `main`, four times the panes cost 8 to 14 times as much per key, which root `AGENTS.md`, "Responsiveness", rules out. The last column shows that the recorder alone holds that cost. I measured `k` and `j`; the recorder runs on every keydown, so I expect the same of other keys, but did not measure them. ## What I ran On the merge with b5f5c5d: - `test_a_key_pressed_with_nothing_focused_keeps_the_place_read_in_a_pane` passes here, and fails on `main`'s runtime with `assert 0 > 0`. - `test_a_wheel_or_a_press_on_words_gives_a_pane_the_reading_keys_and_the_walk` passes here and on `main`'s runtime. #5468 fixed the readers it holds, so it now guards them. - `test_motion_preference_changes_are_heard_without_reloading` passes. Before the merge, the 46 tests by node id that press a reading key, read the region answer or restore a place all passed at two workers. - `pnpm run test:runtime` (815 passed) and `pnpm run check:browser`. `test_a_click_on_a_panes_words_makes_it_the_subject_of_every_scroll_key` fails here and on `main`'s runtime alike: the resting "Comment on pane · Left reading" button that #5428 added covers `#right-start`, so the click never lands. I did not run WebKit, or `leaf page check --render` over the corpus. The change adds no work on the startup path. > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
#5425 landed the repair this branch sat on, so its focusInPage move and its wheel test are main's now. passages.js takes main's focusInPage, which #5511 extended to Leaf surfaces seated in the page. reading-regions.js keeps this branch's chosen region beside main's removal of the local focusInPage. test_panes.py keeps #5512's resting-box test, the wheel test once, then this branch's two tests. Refs #4062
…every region A step the page can't take, with no region named, goes to the region that shows the most. Finding it measured every region's shown box and scroll range on the keystroke, so on a workspace of 801 panes the first `j`'s keydown handlers took 23 to 24 ms, against the 8 ms root AGENTS.md, "Responsiveness", gives a keystroke. The size observer reading-regions.js keeps on every region's host now watches each body too and records its border-box area as it changes. `readingRegionsBySize` lists the regions largest box first, sorted again only after an area or the registry changes, and `regionForStep` walks that list and stops at the first box smaller than the most a region has shown, since no region shows more than its box. The ranking is unchanged: shown area, then scroll range, then reading order. The step reads scroll positions before computed style, so a `k` that finds no pane with room above reads less of each. A body the observer has yet to deliver could be any size, so it comes first and is measured. A `j` held while the runtime loads replays before the first delivery, and counted as no box it moved nothing. Two panes the same size and wholly on screen tie at the stopping edge, and the second must still be read. A new test holds that on a workspace with nothing beside `main`, for a `j` pressed after load and one held through it: the existing test's footer clips both panes as the page scrolls, and it passed with a walk that stopped at the tie. At 801 panes the first `j`'s handlers now take 0.9 to 1.2 ms, beside 1.3 to 1.4 ms for a `j` in a named workspace body on main, which chooses nothing. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…page some scroll A step up chose a pane only on a page that doesn't scroll, so that `k` at a long page's top leaves a following log in view alone. A header or footer beside a full-height workspace's `main` gives the page 53 to 125 px of scroll, which put that workspace among the long pages: on a fresh load `k` moved nothing, where the same workspace without the footer moved its log back from its newest entry. A step up now chooses where the window holds all of `main` (`mainFits`), or of the page where it has none. That answers as before on every page except one whose only scroll stands outside `main`. On a footer workspace whose pane is a log at its newest entry, `k k` now moves the log 60 px each in Chromium and Firefox, and `j j` then moves the page; on a long page with a following log at its top, `k` still moves nothing. Co-Authored-By: Claude Opus 5.5 <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
I found nothing in the code to change. The step now reads the regions in the order the size observer records, so the per-keystroke scan the earlier review raised is gone. The new tests in test_panes.py and pnpm run test:runtime pass on this head.
I'm leaving this as a comment, not an approval, because the description says the rule "is a new policy, for Max to decide" and lists the calls under Calls Max may reverse. Marking the PR ready for review doesn't settle that question. Once you've decided to keep the rule, say so on the PR and it can land.
Ranking by each body's recorded area still measured every pane of a set the same size, since equal boxes tie at the stopping edge. An independent review put 801 panes in fixed 300 px rows, scrolled the workspace body to its end and clicked the page's title: the first `j`'s handlers took 12.1 ms, as before the size order. `regionForStep` now reads each unconcealed region's rect at the key, clipped to the window, and walks them largest first with the same stop rule. A pane off screen has a box of 0 there, so the walk measures what a region shows only for the panes on screen. The size observer no longer watches bodies, and `readingRegionsBySize`, the recorded areas and the rule putting an undelivered body first go with it: a key held through startup now reads its rects when it replays. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`mainFits` compared `main`'s height with the window's, so a short `main` that a site header pushes below the window's foot passed it. An independent review found a fresh `k` moving a following log on such a page, a column page whose 825 px `main` starts about 330 px down a 900 px window. `mainFits` now asks whether `main`'s top and bottom both stand inside the window, as its name says. A workspace with a footer after `main` still passes at the page's top, so `k` there still moves its log. A workspace with a header above `main` no longer passes, since that header pushes `main`'s foot past the window, and `k` on a fresh load there moves nothing, as it did before this PR. A site-header case in the step-up test holds the new answer. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…is clipped from `areaWithin` read each body's own rect, where `shownRect` clips the box `shownBox` gives, which for a `display: contents` element is the box its contents paint. The two differ there: the `code-comparison` playground's rail body has a 0x0 rect but shows 82,128 px² at 1440x900, so its window box was smaller than what it shows, against the premise of the walk's stop rule. That body doesn't scroll, so no choice changed. Reading `shownBox` makes the window box an upper bound on the shown area by construction; on `code-comparison` no region now shows more than its window box. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@leaf-agent The rule stays. It is taken as a call Max may reverse, as #4039's was on #5550, and the description now says so. The head, 9b66ff2, also has the independent review's last fix: On the per-region pass: it stays for now. At 801 panes the first
|
On a fresh workspace load,
j,k,dandumove nothing: nothing names a pane yet, and the page they go to has nothing to scroll. With this change, a step the page can't take goes to the page's largest pane, and names it. This is a new policy, taken as a call Max may reverse; the repair it builds on is #5425.Refs #4062. The focus mark on the active pane and the key that moves from pane to pane stay postponed until a user loses track of the active pane, or tabs through a pane to reach the next one.
The diff against
mainis +338/−14 across 4 files:browser/runtime/navigation.js,browser/runtime/reading-regions.js,docs/ui.htmlandtests/browser/navigation/test_panes.py.The rule
With no region named, the page takes each step it can.
main, top and bottom: on a page that doesn't scroll, or on one that scrolls only by a footer aftermain. On a long page,kat its top moves nothing, as it does today, and so does a shortmainthat a site header pushes past the window's foot.ugives the page back the height of a header or footer besidemainbefore the pane moves, andjtakes it again first. The chosen pane is still named for walks, somgoes on from where the steps reached.The code is
regionForStep,mainFitsandstepReadinginnavigation.js, andchooseReadingRegionandchosenReadingRegioninreading-regions.js.userReadingRegiondoesn't change here, sozand walks answer as they do on #5425 until a step chooses a pane.How a step finds the largest pane
At the key,
regionForStepreads the box each unconcealed region's body shows as (shownBox, the boxshownRectclips), clipped to the window, and sorts the regions by that area, largest first. No region shows more of itself than that box within the window, so the walk measures what each region shows only until it reaches a box smaller than the most a region has shown. A pane off screen has a box of 0 there, so only the panes on screen are measured. A key held while the runtime loads reads the same rects when it replays.Review findings
Each finding was measured in Chromium and Firefox, except the cost, which was measured in Chromium.
maingives the page a little scroll: 53 and 125 px on my test pages, 89 and 125 px in the review's. The first version gave the page the keys whenever it could scroll at all, sojmoved the page twice and then nothing. Now the page takes what it can and the pane takes the rest.current-proposed-comparisonthat one is the shorter. The second ranked by scroll range alone, and at 900x600 onalert-reviewit moved the side list rather than the item beside it. Area, then range, picks the item panel there and Proposed oncurrent-proposed-comparison.k: the second version letkat a long page's top choose a following log in view. With lines arriving, the log was left short of its newest entry and stopped following, and later keys moved the log rather than the page. A step up now chooses only while the window holds all ofmain. That still lets a freshkmove a workspace's following log back from its newest entry, which choosing only on a step down would not.kafter a hand-off never returned the page, so 89 or 125 px stayed scrolled. A chosen pane now stays behind the page.jat 801 panes spent 23 to 31 ms in its keydown handlers, against the 8 ms rootAGENTS.mdgives a keystroke. It now spends 2.1 to 2.3 ms there (see "Cost").jstill measured every pane, 12.1 ms. Clipping each box to the window gives the panes off screen a box of 0; that state now takes 2.8 to 3.0 ms.kbeside a footer (Tend's review, below its bar): the step up asked whether the page scrolls, so on a fresh workspace with a footer aftermain,kmoved nothing, where the same workspace without the footer moved its log. It now asks whether the window holds all ofmain.main's height is not containment (independent review): the intermediate version comparedmain's height with the window's, so a freshkmoved a following log on a column page whose 825 pxmainstarts about 330 px down a 900 px window.mainFitsnow asks whethermain's top and bottom both stand inside the window.jandumoved the pane and left the page where it stood, as onmainfor a pane the user tabbed into. Tab itself scrolled the page by 41 or 53 px to show the focused pane, which Tab onmaindoes too.Evidence
From a fresh load at 1440x900 unless stated, by real key presses. In the "here" column Chromium and Firefox moved the same amounts on every row.
jonmainjhererust-sortreview-queuealert-reviewalert-reviewat 900x600current-proposed-comparisoncode-comparisonThe "on
main" column is Chromium on every row, and Firefox onrust-sortandreview-queue, the two pages I ran there.Down and back,
j j d d u u u u, with the rail beside the detail pane staying at 0 throughout:main(page range 125 px): the page moves to 60, 120 and 125, then the detail pane to 421. The firstureturns the page to 0 with the pane still at 421, and the next returns the pane to 0.main(page range 53 px): the page moves to 53, then the pane to 60, 524 and 732. The firstureturns the page to 0, then the pane goes to 268 and 0.At a long page's end with a log in view,
j jmoves the log to 60 and 120, andk kthen moves the page up by 60 and 60 while the log stays at 120. These probes gave the same output on this version as before the cost change, in both engines.k j j k kfrom a fresh load on pages with a log at its newest entry, the same in both engines:kjreturns the log;k kmove it backmainj jmove the page;k kreturn itmainjmoves the page 53 px;kreturns itmainmainbelow a 330 px site headermainabove a tall site footerCost
The PR's pages are workspaces of 801 panes in a ten-column grid, each pane holding a 400 px paragraph; the panes are too short for their own headers, so the workspace body overflows and, as the largest region, takes a fresh
j. The review's page sets the same panes in 300 px rows; its state scrolls the workspace body to its end and clicks the page's title, which names the page, so the firstjchooses among the panes. Each journey reads, for each keydown:MessageChannelmessage posted at it, the reading the earlier versions of this PR reported. It also counts any frame the browser runs before that message, here the first frame of the glide the step starts;TaskDurationover the 450 ms after the key.Three rounds of
uv run leaf-dev probe <page> --journey <journey> --viewport macbook --base 567c1e78b, alternating the two pages, at load 5 to 10. 567c1e7 is this PR before the cost change, and each probe runs it and this version back to back. Times in ms, at 801 panes:j, handlersj, dispatchkwith no pane to move, handlersj, handlersj, main-thread timeThe key's own work fits the budget in both states. Each region still costs one rect read and its concealment checks at the key. The dispatch reading mostly measures the glide's first frame whenever the browser runs it before the message, and a
jin the named workspace body onmainread 28 to 29 ms there on an earlier run. The main-thread time after ajis mostly that glide's frames: in a profile, most of it was the reading-place recorder (recordPlacesinversion.js, throughblocksOnScreeninreading-place.js), which ajin the named body onmainpays as well.What I ran
tests/browser/navigation/test_panes.py,tests/browser/projection/test_reading_position.py,tests/browser/widgets/test_workspaces_and_bounds.py, and the 21 tests elsewhere that press a reading key or read a workspace walk, by node id, at two workers: 120 passed.pnpm run test:runtime(898) andpnpm run check:browser.test_of_two_panes_the_same_size_on_screen_the_one_with_more_to_scroll_takes_the_steptime out.test_the_page_hands_a_step_it_cannot_take_to_its_largest_pane_and_takes_it_backpasses with it, since its footer clips both panes as the page scrolls, which is why the new test exists;mainFitsbymain's height:test_a_step_up_goes_to_a_log_only_where_the_window_holds_main[site-header]fails;[workspace-footer]case times out.test_the_page_hands_a_step_it_cannot_take_to_its_largest_pane_and_takes_it_back; a region before the page fails that test andtest_a_step_up_goes_to_a_log_only_where_the_window_holds_main[long-page]; no name on the chosen pane fails the first, wheremdoesn't reach#second; a step up choosing on any page fails[long-page], where the log moves 60 px off its newest entry.I did not run WebKit, or
leaf page check --renderover the corpus.leaf-dev benchgenerates no page of panes, so the cost readings come from the probes above, not from the bench. This adds no work on the startup path, so I made no base and head startup comparison.Calls Max may reverse
kto the page after ajat a long page's end has moved a log. The cost is that the log stays where thatjleft it.alert-review, and the range tie-break keeps Proposed oncurrent-proposed-comparison.mainas the test for a step up. A workspace with a header abovemainfails it, so a freshkthere moves nothing, as before this PR. A short page with a tall site footer passes it, sokat its top moves a log in view there.Still failing
Space, PageDown and the arrow keys on a fresh workspace move nothing in Chromium or Firefox (
rust-sort), since they stay the browser's own keys and focus stands on the body.