Skip to content

Let keys pressed while the page moves add up as if each motion had landed - #5227

Merged
max-sixty merged 3 commits into
mainfrom
keys-during-smooth-scroll
Nov 3, 2026
Merged

max-sixty merged 3 commits into
mainfrom
keys-during-smooth-scroll

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Pressing u while m was still scrolling to its obligation did nothing, and pressing m while a d or u step was still gliding did nothing either. In each case the later key lost to the scroll already under way. The step's glide read the landing's motion as another hand on the page and stood down, and the glide's next write cancelled the landing's smooth scroll.

Leaf's keys pressed while Leaf's own motion still moves the page now add up as if each motion had landed. Every engine's paging keys behave this way when pressed in quick succession: PageDown then PageUp chains from the pending destination in Chromium, Firefox and WebKit.

  • A reading-page step (d/u/j/k) measures from where the page is headed. That is the goal of a step still gliding, or the destination of a landing still under way (m, t, a link, Back). A quick m u therefore ends where m and then a slow u end: half a page above the obligation, which stays in view.
  • A landing takes the page from a step's glide, so d m lands the obligation.
  • A walk decides whether its destination is already framed by reading the page where the motion will leave it. So m followed at once by Shift+m returns to the obligation m left, and j m beside an obligation j leaves in view moves the page no further than j does.

The engines differ only mid-way through a script's smooth scroll. There Firefox's paging keys chain from the destination, as Leaf now does. Chromium's and WebKit's page on from where the scroll has reached. Followed here, a quick m u would end wherever u happened to catch the landing, or would do nothing if u came before the landing's first frame.

How it works:

  • startScroll(box, top) records where each landing is headed. The record lasts until the landing's scrollend, a stopScroll, or a glide taking over the box.
  • scrollGoal(box) returns where a box is headed. Steps read it, and so do travel's readableDestination and the obligation walk's framed.
  • The glide moves from navigation.js into scrolling.js, beside startScroll and stopScroll, so both directions of the handoff live in the module that owns scroll positions.
  • glideTo takes an absolute goal. A glide taking over a landing holds the box until its own write first moves it, and starts from wherever that frame finds the box. Without this, Firefox's main-thread scrollTop lags its smooth scroll on a busy page, and Firefox ignores a write to that position. Every other glide claims the box at the press, so a hand that moves the box before the first frame wins, as before.
  • go-to-sequence.js now imports the glide instead of having it injected.

Unchanged: a scroll the browser itself drives, such as Space or a wheel, keeps the page until it ends, so d pressed during one is still dropped.

Evidence: final scrollTop on a page whose first obligation lands at ~2574
Keys main (Chromium) This branch: Chromium / Firefox / WebKit
m, then u 0 ms later 2574 (u lost) 2091 / 2092 / 2091
m, then u 150 ms later 2574 (u lost) 2091 / 2092 / 2091
d, then m 60 ms later 482 (landing cancelled) 2574 / 2575 / 2573
From the top, d, then u 3 ms later 482 (u lost) 0 / 0 / 0
On ask-1, m, then Shift+m 20 ms later 5342, ask-2 on screen, focus on ask-1 off screen 2574 / 2575 / 2573, focus on ask-1
ask-1 framed, j, then m 15 ms later 2356 2356 / 2357 / 2355, the same as j m typed slowly
At the top, g g, then a wheel 30 ms later 600 600 / 600 / 600

Tests:

  • The new test_keys_pressed_while_the_page_moves_act_as_if_it_had_landed fails on main. It also fails if the landing destination is dropped, or if travel treats a moving page as unreadable.
  • pnpm run test:runtime, check:browser and pre-commit pass. So do 60 focused browser tests over the reading keys, panes, samples, the obligation walk, go-to and Back.
  • test_motion_preference_changes_are_heard_without_reloading fails locally on macOS, and on main as well. It passes on CI's Linux runner, so this change didn't cause it.

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

…nded

`u` pressed while `m` was still scrolling to its obligation did nothing, and
`m` pressed while a `d` step still glided was cancelled by the glide. A step
now measures from where the page is headed: the glide's goal, or the
destination of a Leaf landing still under way, which `startScroll` records.
A landing takes the box from a glide, and a glide taking over a landing holds
the box until its own write moves it. Travel's readability check and the
obligation walk's framing read the page where that motion will leave it, so
`m` then `Shift+m` returns to the obligation `m` left.

The glide moves from navigation.js to scrolling.js, beside startScroll and
stopScroll, and go-to-sequence.js imports it rather than having it injected.

Behavior change: a quick `m u` now ends half a page above the obligation,
as `m` then `u` typed slowly does, in Chromium, Firefox and WebKit.
# Conflicts:
#	dist/kernel/kernel.json
leaf-agent
leaf-agent previously approved these changes Nov 3, 2026
# Conflicts:
#	dist/kernel/kernel.json
@max-sixty
max-sixty merged commit 0603306 into main Nov 3, 2026
4 checks passed
@max-sixty
max-sixty deleted the keys-during-smooth-scroll branch November 3, 2026 19:16
max-sixty added a commit that referenced this pull request Nov 3, 2026
With an entry per navigation step, `m m` typed quickly left a Back stop at
wherever the first `m`'s glide had reached when the second left: Back
put the page at 42px with focus on the first obligation, 3,100px below
(Chromium; Firefox the same at 627px). #5227 made keys pressed while
Leaf still moves the page act as if the motion had landed, and the
working-place checkpoint now follows that rule: `readPlace` records the
page's offset as `scrollGoal(pageScroller)`, so Back after a quick `m m`
returns to the obligation the first `m` landed on (3146px, as typed
slowly, in Chromium and Firefox).

Test: `test_keys_pressed_while_the_page_moves_act_as_if_it_had_landed`
adds Back after a quick `m m`; it fails with the checkpoint reading
`scrollY` (Back lands at 0).
max-sixty added a commit that referenced this pull request Nov 3, 2026
…d reference (#5232)

After `t` to a thread and `m` to an obligation, browser Back skipped the
thread and went to where the user was before `t`: consecutive navigation
steps shared one history entry while the last landing still showed,
whatever trip each was. Rather than add a `g b` key with its own record
of where the user had been, Back itself now returns to the item, and the
`?` reference lists it.

## Back returns to the item each step left

Every navigation step that arrives and moves the page adds an entry
where the user stood, as a followed link does. The navigation group is
gone: its state, the reading-input listener that ended it, the `landing`
and `intent` arguments every caller passed, the replace path in
`prepareEntry`, and `openingPassage`.
`browser/runtime/anchor-travel.js`'s header records the decision and the
alternative it rejected.

A first version kept one entry per run of one walk, on the grounds that
Shift retraces a walk. Review found two cases it still got wrong:
answering an obligation takes it out of On me, so neither Back nor
Shift+m returned to it, and an `lf-tally` Next on me merged with `m`
though its stops differ. Both come from sharing an entry, so no steps
share one.

`navigateToDatum` keeps main's #5034 behaviour: its entry names the
widget key, and a step that doesn't move renames the current entry to
that URL.

A Back stop records where the page is headed. With an entry per step, `m
m` typed quickly left a stop wherever the first `m`'s glide had reached
when the second left: Back put the page at 42px with focus on the first
obligation 3,100px below. Following #5227's rule that keys pressed while
Leaf moves the page act as if the motion had landed, `readPlace`
(`history.js`) records the offset as `scrollGoal(pageScroller)`, so Back
returns to the obligation the first `m` landed on, as typed slowly
(3146px in Chromium and Firefox).

Behavior that changed:

- `t` then `m`, then Back, returns to the thread's place, and Back again
to where the user was reading. Main returned straight to the reading
place (measured with `leaf-dev probe` in Firefox and Chromium).
- A run of `m` or `t` takes one Back per stop to undo, where it took
one. Back after answering an obligation and stepping on returns to it.

## The command reference lists Back and Forward

`keyboard/page.js` declares a run-less page row beside caret browsing's
F7, in the platform's spelling: ⌘[ and ⌘] on a Mac, Alt+← and Alt+→
elsewhere. A run-less row never matches in the dispatcher, so the press
still reaches the browser. Back's description reads "Return to the place
the last walk, Go-to or link left". `bindings.js` exports its `MAC`
check so the row uses the platform reading the key spelling already
does.

## Tests

- `test_back_returns_from_an_obligation_the_walk_travelled_to` covers
`t` then `m`, and an `m` walk across an answered obligation; it fails on
main (one entry where it asserts two).
- `test_back_returns_from_a_thread_the_walk_travelled_to` asserts a `t`
walk adds an entry per thread and Back and Forward retrace it.
- `test_a_new_reading_passage_ends_a_travel_group` is now
`test_back_returns_the_passage_chosen_between_trips`, with the same
assertions.
- `test_same_passage_and_controls_keep_a_mixed_travel_group` is deleted:
it held clicks and controls from ending a group that no longer exists.
- `test_keys_pressed_while_the_page_moves_act_as_if_it_had_landed` adds
Back after a quick `m m`; it fails with the checkpoint reading `scrollY`
(Back lands at 0).
- `test_an_option_that_runs_from_nowhere_still_says_its_keys_and_why`
also checks that Back is a disabled option whose accessible description
gives its key and description.
- `pnpm run check:browser` and `pnpm run test:runtime` (754) pass, as do
the Back, keys-during-motion, widget-key URL and hidden-fragment browser
tests.

`docs/ui.html` "Back and Forward" states the rule; the glossary drops
Navigation group.

Inherited: six keyboard tests fail locally on main's own tree as on this
branch (checked by node id with this branch's files checked out from
main):
`test_the_reference_runs_available_commands_and_explains_the_rest` and
`test_the_reference_keeps_local_search_state_on_one_lit_surface` in
`navigation/test_command_reference.py`;
`test_a_command_button_owns_activation_and_the_native_form_default`,
`test_a_text_box_keeps_its_keys_from_the_widget_around_it` and
`test_a_focused_scope_owns_its_declared_key_while_the_command_is_unavailable`
in `navigation/test_key_scopes.py`; and
`test_route_corner_hint_overrides_the_rows_face_in_obligation_and_widget`
in `controls/test_command_routes.py`.

> _This was written by Claude Code on behalf of max-sixty_
max-sixty added a commit that referenced this pull request Nov 4, 2026
…very reader (#5285)

Landings (`m`, `t`, a link, Back) now glide as the reading keys do,
instead of riding the browser's smooth scroll, and one module decides
when a scroll ends for every reader. Follows #5227.

### One glide for every Leaf motion

A script's smooth scroll is slow by each engine's design and has no way
to set its pace: Chromium lengthens it with the distance (about 450 ms
for a page, 870 ms for three), and Firefox's spring settles in about 550
ms, both past the 300 ms that motion the user waits on may take
(`browser/AGENTS.md`). Leaf now drives every smooth vertical move
itself, as Vimium does: 140 ms of easing out, written as instant
scrolls. A landing measured on a tall page took about 870 / 630 / 245 ms
in Chromium / Firefox / WebKit on main and takes 140–160 ms in each
here.

The handoff between the two mechanisms goes with it: the record of where
a native landing was headed, the glide's takeover of a landing, and the
`moving` map that told them apart. Glides are per box, so a landing
glides each nested scroller it moves together. An `auto` move in a box
whose CSS asks for `scroll-behavior: smooth` glides too.

### Steps pressed while the page moves

- After Space or PageDown, whose destination no script can read, a
reading-page step waits for the browser's scroll to land and steps on
from there (`afterBrowserScroll`), and further steps wait behind it in
the order pressed. They used to be dropped. Only the inputs that set the
browser scrolling (its scroll keys, a pointer, a wheel or a touch)
decide whether its scroll is a key's, so a `d` in between doesn't change
that.
- During a wheel's or a touch's momentum, which has no destination, a
step takes the box at once.
- A step after one of Leaf's own glides measures from that glide's goal,
as before.

### One owner for a scroll's end

`arrivals.js` hears `scroll` and `scrollend` in the document, every
shadow stage and any tree a module enrolls (`hearScrollsIn`), and ends
each box's scroll once: at its `scrollend`, or after 80 ms and two
rendering updates with no movement. A glide holds the box
(`holdScroll`), so its many frames end the scroll once. `browserScrolls`
says whether the browser, rather than a script, is moving a box: a
scroll under way that no hold keeps open, and that has taken the box
from where a script last put it. The choice bookkeeping in
`scrolling.js`, continuity's place recording in `version.js` and the
margin's re-placement subscribe through `watchScrollEnds`, and a lint
rule (`architecture/scroll-ends`) keeps runtime code from listening to
`scrollend` itself. A `d` glide no longer records the reading place on
every frame: 254 ms of `recordPlaces` on main, 64 ms here, in Chromium
on the probe page.

### Behavior changes

- Landings take about 140 ms in every engine.
- `d` pressed during Space or PageDown adds to it in Chromium and
Firefox. WebKit fires `scrollend` on each frame of a keyboard scroll, so
there the step starts early and lands short (`notes/browser-support.md`
records it with a recheck).
- A page's own `scrollend` listener hears one event per frame of a Leaf
landing, as it already did for the reading keys.

### Testing

The typeahead test
(`test_keys_pressed_while_the_page_moves_act_as_if_it_had_landed`) gains
PageDown-then-`d` and PageDown-then-`d d` phases, and the runtime unit
test for held scrolls covers ending once and telling a script's settling
scroll from the browser's. Firefox and WebKit were checked by probes:
Space+`d`, PageDown+`d`, wheel+`d`, `m u` and `d m` in each engine.

> _This was written by Claude Code on behalf of max-sixty_
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