Skip to content

Act on every key pressed during a glide where the glide lands - #6009

Merged
max-sixty merged 2 commits into
mainfrom
motion-ahead
Nov 15, 2026
Merged

max-sixty merged 2 commits into
mainfrom
motion-ahead

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Max asked for one rule for keys pressed during a glide instead of a decision per case. It is the one #5971 recorded: a key acts as it would once the glide had landed; a wheel or touch takes the page where it stands. The nightly check from #5987 holds every glide-and-key pair to it, and now passes 55 of 56 cases, PageDown included.

Leaf's readings of where the user is already predict the landing. What failed was work that reads the page as it stands, now handled one of two ways:

  • Land first: the browser's answer to Tab and paging keys (landForKey, called by the keyboard controller after its let-go), and the comment box's Floating UI placement for a page target or selection (landGlides). The glide's last ≤140 ms of motion jumps.
  • Aim from the goal: Leaf's nearest reveals measure each region where its glide will leave the destination (readingBandMoves). This replaces Act on a key pressed during a glide as though the glide had landed #5971's rule that such a reveal stops the glide, which left / during d in a diff stopped mid-way.

Where to look: landing on every key was tried and rejected, since a CSS-anchored thread card takes a scroll a frame late and a card a t walk had focused read as off screen. That lag is also why Chromium t then Tab still fails.

Tests: a runtime test and a browser phase that both fail on main, 253 focused browser tests, test:runtime, the matrix twice; Codex reviewed twice and its four findings are fixed. test_a_focused_thread_covers_the_pages_choice_hints fails locally on main too.

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

Max asked for one standard rule for keys pressed during a glide rather than a
decision per case. The rule is the one #5971 recorded: a key pressed while a
glide runs acts as it would once the glide had landed, while a hand on the
page, a wheel or a touch, takes the page where it stands. The nightly check
from #5987 holds each pair of glide and key to it with no expected outcome of
its own, and marked six pairs as still breaking it. Leaf's readings of where
the user is already ask where the glides land (scroll-containers.js,
`seenAhead`). The failures were the three kinds of work that read the page as
it stands instead:

- The browser's own answer to a key. Tab's focus navigation revealed what it
  reached from the page mid-glide: after `m` its reveal of the ask's option
  cut the glide short (3171 px rather than 3503), and Shift+Tab during `d`
  reached a control the glide was carrying away, which the browser centres
  once the page has landed. PageDown pressed during `d` paged from where the
  glide had got to, since scroll keys stopped the glide where it stood.
- A placement Floating UI solves. `c` on the ask `m` was gliding to placed the
  comment box against the ask where it stood, so the box took the side with
  room mid-glide and ended off screen with focus in it; a selection's box did
  the same at a 900x600 window.
- Leaf's own nearest reveals, which measured from where each box stood: `/`
  pressed during `d` in a multi-file diff found the filter still shown and
  left the page stopped mid-way (5630 px, where `d` then `/` typed slowly
  ends at 5708).

So the keyboard controller, once its let-go has read where the glides were
headed, lands them before a key the browser answers: every glide for Tab, and
those on its path for a key the browser scrolls for (scrolling.js,
`landForKey`). `c` lands them before opening its box on a page target or a
selection (`landGlides`). The rest of a glide, at most 140 ms of motion, jumps
when one of these keys arrives mid-way. And the reading band's moves measure
each region where its own glide will leave the destination and aim from that
glide's goal (landing-scroll.js, `readingBandMoves`), so a reveal that finds
nothing to move leaves the glide going. That replaces #5971's rule that such a
reveal stops the glide, which kept the page where it stood rather than where
the same keys typed slowly leave it.

Landing glides on every key, before the let-go, was tried and rejected: a
thread card the page carries by CSS anchoring takes a scroll only at the next
frame, so the card a `t` walk had focused read as off screen, and `c` or `d`
pressed as the walk set off let go of it.

The check now also follows each glide with PageDown. It passes 55 of its 56
cases, stable over two runs; the other five known pairs pass and their entries
go. Chromium `t` then Tab still fails: the browser reveals the card's next
control where the anchored card stood before the landing. Firefox passes it.

Tests: tests/runtime/landing-scroll.test.mjs holds a nearest landing during a
glide to the glide's goal, and test_obligation_walk.py's keys-in-motion test
gains `d` PageDown `d` pressed before a frame; both fail on main. The nightly
check covers the rest.
@max-sixty
max-sixty merged commit 74008ae into main Nov 15, 2026
5 checks passed
@max-sixty
max-sixty deleted the motion-ahead branch November 15, 2026 07:56
max-sixty added a commit that referenced this pull request Nov 15, 2026
The glide matrix from #5987 pressed each key only before the glide's
first frame. Pressed mid-glide with real timing, `t` again during a `t`
walk left the page short of the thread (Firefox 12 of 12 runs, Chromium
8 of 10): every arrival stopped Leaf's glides and landed nearest from
where the page stood, where the thread was already in view.

- An arrival now stops only a scroll the browser drives
(`stopBrowserScroll`); a glide of Leaf's goes on, and the landing aims
from its goal, as #6009 made the reading band do. Back and Forward still
stop glides.
- `g` lands the glides instead of stopping them, as `c` and Tab do.
- An instant landing takes the box from a glide, landing it now where
the glide already headed for the destination; a sideways reveal on the
way leaves a vertical glide going (landing-scroll.js).
- The matrix presses each key at once and under way, two frames after
the glide first moves; `held_frames` freezes the page's frame clock and
yields `step()`, so that point doesn't drift with load. `g` joins the
keys. 127 of 128 pass in both engines; on the base, `t t` and `m t`
under way and every glide then `g` fail.

Where to look: the one known case, Chromium `t` then Tab at once, is an
engine gap now recorded in notes/browser-support.md: an anchored box
takes a script's scroll at the next frame, and Chromium reveals a
control in one by scrolling the page.

Also fixes `test_a_focused_thread_covers_the_pages_choice_hints` on
macOS 26's fonts.

Max asked to work through #6009's open items. Tests: the matrix,
real-timing `t t` (38 of 38 runs end as typed slowly), runtime tests for
both landing fixes (fail on main), 61 focused browser tests,
`test:runtime`, `check:browser`. Codex reviewed it.

> _This was written by Claude Code on behalf of max-sixty_
max-sixty added a commit that referenced this pull request Nov 24, 2026
…t by its source text (#6987)

`test_sample_browser_boundary_contains_focus_scroll_and_parent_access`
has failed on main since #6951 (`fb8b0cc1e7`): it passes at that
commit's parent and fails from it on. #6951 made
`Element.prototype.scrollIntoView` Leaf's wrap around the browser's
method in every Leaf document, a live sample's included, and the test
asserted that the method's source text reads `[native code]`.

What that assertion stood for still holds: a reveal a sample's script
makes itself does what the browser's does. The test now makes that call
and checks what it moves, which is the sample's own page and, through
the sample's frame, the page around it. Leaf's own `scrollIntoView`
leaves the page around the sample still, as the test already checked.
`focus` keeps its source-text check, since nothing wraps it. No runtime
code changes.

To weigh: the new check relies on the browser scrolling the host page
for a reveal made inside a sandboxed frame, as Chromium and Firefox both
do today. `module-scroll-and-motion.md` already says that Leaf's
`scrollIntoView`, unlike the native one, stays inside a live sample.

The session running the package-interface redesign asked for this, after
an agent found six browser tests failing on main. This is the only one
of the six that a pull request of the redesign caused; the others trace
to #6796, #6947 and #6009 and are left alone. Max hasn't read the diff.

Tests: the test by node id in Chromium, also under `--cpu-throttle 8`,
and its body in Firefox with the fixture swapped by hand. It fails when
the wrap drops the browser's call, and when the script's call is swapped
for Leaf's contained one.

> _This was written by Claude Code on behalf of max-sixty_
leaf-agent added a commit that referenced this pull request Nov 24, 2026
…7054)

Pressing ArrowDown in the file tree while the page was still gliding to
a file made the rest of the glide jump under the focused row. The cause
is in `scrollsFor`
([`scrolling.js`](https://github.com/max-sixty/leaf/blob/48acfcf7272d81e1d1e4d6e21b142a0881b79dd5/browser/runtime/scrolling.js#L108-L118)).
It matched the tree's `<button role="treeitem">` rows against the
selector `button` in `PLAIN_PRESSES`, which says the browser scrolls for
an arrow key pressed on that control. So the keyboard controller's
capture listener landed the glide first (`landForKey`, from #6009), but
the tree takes the arrow itself and the browser never scrolls. #7045's
shift watch error was this scroll: on a fast machine the key arrives
before the glide lands, while on CI runners it arrives after.

An element's explicit `role` overrides its tag's, so `PLAIN_PRESSES`,
`LINKS` and `RADIOS` in `control-selectors.js` now count a native tag
only where it has no `role`. A row in a tree, or an `<a href
role="tab">` in a tab list, now falls under "every other control takes
those keys itself". `scrollsFor` is the only reader of those three
selectors. This keeps #6009's rule as written: a key the browser scrolls
for lands the glide, and a key a widget takes acts as it would once the
glide had landed, which here means the glide goes on.

Verification:
- **Forced order.** A scratch copy of
`test_file_tree_lands_at_the_file_start_after_reading_down` pressed
ArrowDown once the glide to `third.md` had started. Before the fix, the
`[document]` case failed with the issue's error 2 times out of 2 on the
Linux runner ("a scroll during the keydown ArrowDown on button … moved
it by (0, 31)px"). With the fix it passed 3 times out of 3, the key
arriving mid-glide with the glide carrying on.
- **Unit test.** A new runtime test in
`tests/runtime/scrolling.test.mjs` checks that ArrowDown and PageDown on
a `<button role="treeitem">`, and ArrowRight on an `<a href
role="tab">`, aren't read as browser scrolls. It fails on `main` and
passes with the fix.
- **Other checks.** The original journey test, `pnpm run test:runtime`
(1116 pass) and pre-commit pass.

The selectors behind `CONTROLS` and `PRESSES` also match `button` by tag
whatever its role. Nothing here showed one of their readers misreading a
role-overridden button, so they are unchanged.

Closes #7045 — automated triage

Co-authored-by: leaf-agent <[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