Skip to content

Read the user's inputs, press and standing in focus.js alone - #2038

Merged
max-sixty merged 22 commits into
mainfrom
focus-phase-3
Oct 9, 2026
Merged

max-sixty merged 22 commits into
mainfrom
focus-phase-3

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 8, 2026 •

Copy link
Copy Markdown
Owner

focus.js becomes the one reader of the user's inputs as well as of where they stand, so whether they have moved on since a hold began or a delayed move was scheduled has one owner, and so has the press in progress.

Phase 3 of the focus overhaul, after phase 2 (#2036); phase 4 (#2041) stacks on it.

Two counts, decided. A hold and delayed work read different counts, and they stay apart. A hold compares placements, since the user typing in the box it holds is them working there; delayed work compares inputs, since any key, press, wheel or touch since its gesture is a newer word. One count would void every hold on each keystroke. Rejected: merging them into one "since" count. tests/runtime/focus.test.mjs states both rules, and phase 4 writes the decision into focus.js's header.

  • The input count moves from user-intent.js into focus.js (inputCount), which retainUserIntent and handBack's pending return read, the latter in place of the second counter Release hidden focus before a delayed return #2078 added; onUserInput, which observes those inputs at their edge, moves with it. user-intent.js holds no listeners and no longer imports the keyboard.
  • focused() moves from keyboard/scopes.js into focus.js with the label press it reads, and every importer cut over. The press on a label holds the user on the element they stood on until it lands, for every reader: holds and holdStanding read the held element, and no in-between node a press goes through (the body, or a containing thread that takes focus) reaches onStanding or counts as a placement, where before only the keyboard's focused() hid it. The press lands at the label's click, so it covers a tap; a release off the label, a native menu, a cancel, a key, the window losing focus and a runtime placement end it too. Standing is read once more a task later, so a label whose control takes no focus leaves the user nowhere as their own move. scopes.js keeps the focus-ring classes it paints on the held element, as an onLabelPress reader.
  • One reading of the press in progress (pressing, onPress), from the primary pointer's pointerdown to its end, replaces the panel list's pressedPointer, the reading regions' pressing, the margin card's press-away pair and the thread standing's own press listeners. A release completes a press; a cancel, a native menu swallowing the release and the window losing focus end it uncompleted, which the panel list and the margin card had not heard before. The place input (recentPlaceInput) moves into focus.js too, with main's rule that a repeated click can choose the focused destination without moving focus, and MODIFIER_KEYS into control-selectors.js.
  • The delayed focus moves that never asked now ask: the reaction removal's focus on the next render, the composer's response options after the bar places, and the margin card's deferred focus. Each gives way to any input the user made meanwhile. A hold that carries the user to the node a render put in place of theirs records the handoff (carriedFrom), so delayed work begun on the old node still follows them there while they have done nothing since.

No lint rule: the copies this removes read standing or the press through hooks that now live only in focus.js, and a syntactic rule against input listeners would refuse the gesture owners (drawing, held words, aim) that rightly keep their own.

Behavior that changed:

  • During a press on a label, a hold restores the element the user stood on rather than the in-between node, and no reader hears the in-between node.
  • A press whose release a native menu swallowed, or that the window lost, no longer leaves the panel list believing a press is still held.
  • A delayed focus no longer pulls the user back after they pressed, typed or scrolled elsewhere.

Tests: tests/runtime/focus.test.mjs states the rules (a hold survives typing and gives way to a placement; delayed work gives way to any input; a label press through the body, through a focusable container, and onto a control that takes no focus); they fail on the tree before this change. npm run test:runtime (262) and eslint pass. The focus browser suites (chrome contracts, navigation, controls, threads, widgets, margin, anchors, drafts, reactions, aim, read state, interaction layer, send placement) fail 11 and pass 2169, against 6 and 2174 on main (81e0e10), all 6 shared. Of the rest, the reference's filtering at its narrowest viewport, the Tab-stop reading and test_the_reading_page_keys_follow_the_user_into_the_panel fail on main too in interleaved A/Bs, and four navigation tests that timed out under the suite's load pass 3 of 3 on both arms.

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

max-sixty and others added 10 commits October 6, 2026 15:13
A Tab between two controls inside one widget's shadow tree reaches the
document as no focus event, so every reader listening for `focusin` on the
document or on a light-DOM ancestor missed it. On pr-walkthrough, Tab from
a diff's comment button to the next file's title left the shortcut bar
naming the button's keys until a resize or the heartbeat repainted it.
Each of those readers also decided for itself which moves were the
runtime's own returns, or which were keyboard arrivals.

focus.js now owns every focus event, and the readers read its publication:

- `onStanding` calls `read(node, cause, left)`, adding the node the readers
  last heard the user stood on. A reader that moves focus itself starts a
  newer publication, and the older one goes to no later reader. Focus that
  leaves a node for another and comes back to it publishes again, as when
  the Threads list hands its focus on to the title the user stood on.
- A `step` cause joins `return`, `press` and `move`: Tab or Shift+Tab,
  whether the browser moves the user or a Tab handler does in its place.
  `pressLed()` says whether the latest input was a press rather than a key.
- `handBack` compares the placement count instead of a one-shot document
  `focusin`, so a move inside a shadow tree during its retry frame counts.
- `handingBack` is exported for a box closing onto its thread; the unused
  `restoringFocus` and `placingChrome` exports are gone.

Readers moved onto `onStanding`: the standing repaint (repaint.js), the
keyboard controller's disarm, the response-options close, the covering
surface's focus trap, reading continuity's edit record, the reading-region
record, user-intent's place input, the More menu's opener, off-flow
surfaces, the code-copy anchor refresh, the Threads list's landing and title
choice, and the margin's reveal reset, labels, cluster arrival and
`followStanding`.

Behaviour that changed:

- The Threads list skips landing on a `return` instead of reading
  `keepingPlace` and `restoringFocus()`, so a popover closing back into the
  list no longer re-lands its thread. A press held in the list still lands
  when it ends. `standOnThread` hands back through `handingBack`.
- A panel card's title chooses its card on a `move` or `step`, replacing
  the `:not(:active)` guard; a press still chooses at its click, and a
  return chooses nothing. The list hands its own focus on to the open
  card's title under whatever cause gave the list focus, so `#passingFocus`
  is gone: a hold landing on the list while a failed candidate holds the
  user's card from it does not make the stand-in card their choice.
  keyboard/AGENTS.md says so.
- A margin cluster unfolds on a `step` onto one of its controls, as its
  header says, rather than on any focus matching `:focus-visible`; focus put
  there by script no longer unfolds it. Three margin tests that put focus
  on a cluster's control by script now reach it by Tab or Shift+Tab.
- The margin card and the standing unfold read a keyboard arrival from
  `pressLed()` instead of `:focus-visible`, so a press into a text field
  inside a commented target no longer opens its card.
- Held news treats a `step` as an arrival, as it did a `move`.
- An off-flow surface brings itself back for a move within it that is not
  a `return`.

The lint rule `architecture/standing-listeners` refuses `focusin` and
`focusout` anywhere in the layer and its packages (listeners, event-type
lists, comparisons, Lit bindings) and `focus`/`blur` listeners on the
document. Its config names each exception and why: focus.js, the
interaction log's raw recorder, the reply row's entry, the margin cluster's
and card reply row's `focusout`, lf-gloss and lf-toc, each asking about one
element's own subtree in its own tree. It is a custom rule because flat
config replaces `no-restricted-syntax` per config object rather than
merging it.

user-intent.js's place reading now registers its own `keydown`, which
`test_the_register_is_the_only_way_a_key_enters_the_runtime` names as a
fourth listener that answers no press.

`test_tab_between_two_staged_controls_turns_the_shortcut_bar_over` covers
the shadow-tree Tab. It fails on main and passes here.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…oring a pass later

Follow-ups to the onStanding cutover, from its review and an A/B of its flakes.

- A focused node hidden or removed under the user publishes `drop`, read as null and
  against the place readers last heard. On main a hide fired `focusout`, which
  repainted the shortcut bar; after the cutover the bar kept naming the keys of a
  control no longer there until the next input. Readers of where the user stands
  (held news, the More menu's opener, the margin's follow) let a drop pass, since its
  owner puts the user back, and that return is told against the dropped place.
- Where the user stands is read again when a key's, a press's or a click's task ends
  (a tap focuses at its click), so a move between two nodes of a shadow tree no stage
  watches, as a component's own root makes, reaches the readers with the cause that
  input gave it, or `return` where it came out of a layer that closed
  (`test_a_tab_inside_a_shadow_tree_no_stage_watches_still_reaches_standing`, which
  timed out without it).
- Each reader answers alone: one that throws is reported and the rest still hear, and
  a reader that moves focus ends the older reading by a counter, not a node compare.
- The margin opens a cluster's options for the keyboard arriving on it again, a Tab
  or a route a key began, as `:focus-visible` did before the cutover; the cutover had
  narrowed it to Tab alone. A return opens nothing. The margin tests and the AGENTS.md
  wording go back to main's.
- The lint also refuses `focus` or `blur` captured on any node.
- user-place.js returns native anchoring at the rendering pass after a hold's release
  rather than at the release. Two thread renders back to back released one hold and
  took the next in the same script, writing `overflow-anchor` away and back, which the
  write watch reports. The cutover's timing made that 9 runs in 30 of
  `test_replaced_reply_compositions_keep_their_carets_and_leave_commands[send]` under
  load, against 0 in 30 on its base; with this change, 0 in 30 on both. The cost: a
  change made to that scroller with no hold of its own, and laid out between the
  release and that pass, gets no native anchoring. The window is the rest of the
  pass's round where the release falls inside a rendering pass, and up to a frame
  where it falls outside one; every thread-list render takes a hold.
- keyboard/AGENTS.md says where a return choosing no title can leave focus on a closed
  title: a hold put back after the choice moved under it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Every focus the runtime and the packages place now goes through
`focusDestination(node, cause)`, with the cause `move`, `step`, `return` or `press`,
and every reader of where the user stands (`onStanding`) hears that cause. Before,
about a hundred plain `focus()` calls published as the user's own move, and owners
marked their own returns with flags only their own listeners read, so a return
released held news, opened a margin cluster's options or chose a panel card the user
never went to.

- focus.js: `focusDestination` takes the cause; `returningFocus`, `placeChrome` and
  `handingBack`, and the `placing`/`handing` flags behind them, are gone. A placement
  inside another (a component's focus handler forwarding to its child, `forwardFocus`)
  keeps the outer cause; a placement made by a reader of standing names its own and
  counts as a placement. A closing layer's own hand-back, which the platform makes as a
  popover or dialog closes, is no newer word to a waiting hold, the rule
  `returningFocus` stated for one caller. The cause `press` is a route landing on a
  control to press it, as a go-to does, which opens nothing on arrival.
- A stop is lent only to a drawn element that is no control of its own, and landing
  is read as focus on the element or inside a shadow tree it hosts (`standsIn`), so a
  text field whose editor took focus is landed on and not focused twice.
- The survey's returns that published as moves now say `return`: the banner's refocus
  of its door and the control after a removal, the thread panel's invoker, the reaction
  list's own return, the auxiliary surfaces taking focus back, surface.js's return to
  Threads, and in the margin the cluster repaint, the card transfer and
  restoreStanding; so do carries across a re-render (RowFocus, the swipe deck, the
  board's grip, the thread card's hand-on, history and draft restores, a contribution
  activation's hand-on to the entry that replaced the pressed one, and the Asks view's
  restore after a revision).
- Flags deleted: auxiliary-surfaces' `placingFocus`, the margin's
  `settlingOptionsFocus` and `suppressingOptionsArrival`, and the page map's
  `closeOwnsFocus` (every way out of the map now places focus itself as it closes the
  dialog; the `close` event places nothing). The margin's two cluster `focusout`
  listeners and its card's reply-row `focusout` are `onStanding` readers, so switching
  windows no longer folds a margin entry's options and the margin needs no exemption
  from `architecture/standing-listeners`. `fabFocusHandoff` stays: it is a delayed
  focus's token, which the next change takes up with the other delayed moves.
- The auxiliary-surface controller's `focus()` is `landing()`, the node a covering
  surface lands the user on, so `.focus()` means only the element's.
- The lint `architecture/placements` refuses a plain `focus()` outside focus.js and
  the text field (whose own `focus()` hands on to its editor), requires a cause at every
  `focusDestination` call, and refuses passing the function on as a value.
  `focusForNavigation`, a contribution's `focus(entryKey, cause)` and `focusThread`
  take the cause too.

Behavior that changed:
- A go-to or a generated route that lands on a margin control and presses it no longer
  opens the cluster's options and folds them again under the press; a travel landing
  on a margin control is a `move`, which opens a folded cluster as the keyboard
  arriving does.
- `lf-diff`'s hunk walk and `lf-sample`'s return borrow a stop that leaves with the
  user instead of leaving `tabindex="-1"` on the rows and the sample host.
- Fallbacks that called `document.body.focus()`, which did nothing, are gone.
- Resolving a panel thread still lands the next thread in view and undoing it lands
  the reopened one as an arrival (`move`), so its news shows, as before.

Tests: the focus browser suites (threads, read state, drafts, margin, anchors,
navigation, controls, reactions, application boundary, widgets, chrome contracts and
the interaction layers) fail exactly the 14 tests that fail on this branch's base and
on main (67307c6) alone; `npm run test:runtime` and eslint pass.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	eslint.config.mjs
#	skills/leaf/assets/runtime/auxiliary-surfaces.js
#	skills/leaf/assets/runtime/composing/selection.js
#	skills/leaf/assets/runtime/focus.js
#	skills/leaf/assets/runtime/keyboard/controller.js
#	skills/leaf/assets/runtime/thread/landing.js
#	skills/leaf/assets/runtime/thread/thread-list-view.js
#	skills/leaf/packages/default/runtime/annotation-overlay/margin-projection.js
tests/runtime/focus.test.mjs asks focus.js, under happy-dom, that a move, a return and
a step each reach onStanding as the cause the placement names, and that a placement
naming none is refused. It fails before the change that gave focusDestination its cause,
where every placement read as a move.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…one's

The fold that replaced the cluster's focusout reads the node the user left, as the blur
did: a node hidden under the user leaves the cluster and folds what it opened, and a
node removed from under them folds nothing, since the render that removed it hands
them on to its replacement, often a frame later. Tracking the cluster per reading
instead folded on that removal and closed options a re-render was still handing back
(test_reactions_keep_all_six_buttons_on_an_occupied_target and nine more).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
focus.js becomes the one reader of the user's inputs as well as of where they stand,
so whether they have moved on since a hold began or a delayed move was scheduled has
one owner, and so has the press in progress.

- The input count moves from user-intent.js into focus.js (`inputCount`), which
  `retainUserIntent` reads; user-intent.js holds no listeners and no longer imports the
  keyboard. The count of placements stays beside it rather than merged into it: a hold
  compares placements, since the user typing in the box it holds is them working
  there, and delayed work compares inputs, since any key, press, wheel or touch since
  its gesture is a newer word. One count would void a hold on every keystroke, which
  tests/runtime/focus.test.mjs now states.
- `focused()` moves from keyboard/scopes.js into focus.js with the label press it
  reads, and every importer cut over. The press on a label holds the user on the
  element they stood on until it lands, for every reader: holds and `holdStanding` read
  the held element, and no in-between node a press goes through (the body, or a
  containing thread that takes focus) reaches `onStanding` or counts as a placement,
  where before only the keyboard's `focused()` hid it. The press now lands at the
  label's click, whose default focuses the control, so it covers a tap, whose click
  follows its release; a release off the label, a native menu, a cancel, a key, the
  window losing focus and a runtime placement end it too. Standing is read once more a
  task later, so a label whose control takes no focus leaves the user nowhere as their
  own move rather than with no reading at all. scopes.js keeps the focus-ring classes
  it paints on the held element, as an `onLabelPress` reader.
- One reading of the press in progress (`pressing`, `onPress`), from the primary
  pointer's `pointerdown` to its end, replaces the panel list's `pressedPointer`, the
  reading regions' `pressing`, the margin card's press-away pair and the thread
  standing's own press listeners. A release completes a press; a cancel, a native menu
  swallowing the release and the window losing focus end it uncompleted, which the
  panel list and the margin card had not heard before. The place input (`recentPlaceInput`)
  moves into focus.js too, and `MODIFIER_KEYS` into control-selectors.js, which focus.js
  may import.
- The delayed focus moves that never asked now ask: the reaction removal's focus on
  the next render (inputs only, since the render may carry focus to the replacement
  control), the composer's response options after the bar places, the swipe deck's
  Return after the log answers, and the margin card's deferred focus. Each gives way to
  any input the user made meanwhile. A hold that carries the user to the node a render
  put in place of theirs records the handoff (`carriedFrom`), so delayed work begun on
  the old node still follows them there while they have done nothing since, as it did
  a container's handoff (`passOn`).

No lint rule this time: the copies this removes read standing or the press through
hooks that now live only in focus.js, and a syntactic rule against input listeners
would refuse the gesture owners (drawing, held words, aim) that rightly keep their
own.

Behavior that changed:
- During a press on a label, a hold restores the element the user stood on rather than
  the in-between node, and no reader hears the in-between node.
- A press whose release a native menu swallowed, or that the window lost, no longer
  leaves the panel list believing a press is still held.
- A delayed focus no longer pulls the user back after they pressed, typed or scrolled
  elsewhere.

Tests: tests/runtime/focus.test.mjs states the rules (a hold survives typing and
gives way to a placement; delayed work gives way to any input; a label press through
the body, through a focusable container, and onto a control that takes no focus);
they fail on the tree before this change. The focus browser suites and the render
gate fail only the tests that fail on main (55ba7de), and once
test_focus_paint_releases_every_text_box_crossed_before_a_frame, which an interleaved
A/B under load passes 30 of 30 on both arms.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Main's native auxiliary dialog (#2006) and the code it moved conflicted with this
phase's placements. Main's version stands, carried onto focusDestination: the
covering surface's `focus` is `landing`, its Tab wrap places with `step` and its entry
with `move`, and the swipe deck's and the playground's restores say `return`.

Main wrapped its native layer transitions (`transitionNativeAncestor`, the
auxiliary envelope's re-seat) in `returningFocus`, which this phase deletes. Those
are a dialog's own showModal and close, whose focus moves no focusDestination can
make, so focus.js gains `nativeLayerSteps(steps)`: what they do with focus is the
layer's return, and no newer word to the hold waiting across them.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Main's code, through phase 2's merge, conflicted with this phase's moves on import
lines and two listeners. `focused` comes from focus.js beside main's new imports
(target-picker, reading-place, panel-elements, surface, page.js, held-news).
reading-regions keeps main's click reader of reading input and drops its own press
flag for focus.js's `pressing`. The swipe deck takes main's synchronous Return, which
focuses the next card in the press's own turn, so it has no delayed move to ask
`retainUserIntent` about.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty and others added 2 commits October 8, 2026 00:33
Main's in-place image inspector (#2037) conflicted in media.js, where the viewer's Close takes focus as it opens: it does so through focusDestination as a move.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty and others added 2 commits October 8, 2026 09:40
Main's newer code conflicted with this phase's placements and is carried onto
focusDestination:

- auxiliary-surfaces: main's `edge` joins the registration's requirements, and its
  covering entry, which main wrapped in `returningFocus`, lands the surface's
  `landing` as a `return`.
- The target picker's page search, after main reserves its count, takes focus as a
  `move`; the floating response's withheld bar returns to Threads, now also where a
  covering surface took the room, as a `return`.
- lf-draft's rewritten close returns the user to the draft or its Edit control as a
  `return`; thread/panel.js keeps main's `rowWalk` beside its focus import.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Main's newer code conflicted where this phase moved `focused` and the place input
into focus.js. thread/panel.js and reading-place.js take `focused` from focus.js
beside main's imports. Main taught user-intent.js's place input that a repeated click
can choose the focused destination without moving focus; the place input is
focus.js's here, so focus.js reads that click itself, and user-intent.js stays free
of listeners.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty and others added 5 commits October 8, 2026 13:37
Two import lines conflicted: media.js keeps main's `offered` beside this phase's focusDestination, and lf-command keeps main's `worksInside` beside it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Main's recording review (#2100) focuses a timeline marker and the image canvas on pointerdown, where a plain focus() would publish as a move; each now places with `press`, the cause of a press landing on the control it pressed.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Main's change releasing hidden focus before a delayed return (#2078) counted the
user's inputs in focus.js a second time (`inputEpoch`); `handBack`'s pending return
now reads this phase's `inputCount`, so a key, press, wheel, touch, text input or
window blur cancels it, and the second counter is gone. Main's `onUserInput`, which
observed the same inputs from user-intent.js, joins them in focus.js, and widget-api
exports it from there, so user-intent.js still holds no listeners.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
leaf-agent previously approved these changes Oct 8, 2026
Base automatically changed from focus-phase-2 to main October 9, 2026 01:08
@max-sixty
max-sixty dismissed leaf-agent’s stale review October 9, 2026 01:08

The base branch was changed.

max-sixty and others added 3 commits October 8, 2026 18:09
Phase 2 landed as 00691d6. Every conflict is that squash meeting the phase 2 commits this branch already holds, so each conflicted file is re-merged against phase 2's tip (27da30f) as the base, leaving only main's own seven later changes to meet this phase's; none conflicts. The swipe deck lost a duplicate focusDestination import the old base produced. The branch's diff against main is now exactly phase 3's.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
controller.js takes main's `quickShortcuts` from bindings.js beside this phase's MODIFIER_KEYS from control-selectors.js and `focused` from focus.js. Main's quick-shortcuts switch (#2121) put the user back on the More menu's door with a plain focus(), which phase 2's lint refuses on main as well; it is a `return` through focusDestination here.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Main fixed the keyboard-shortcuts entry's door focus the same way this branch had (#2122), so shortcut-bar.js is main's.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 1e9fad2 into main Oct 9, 2026
6 checks passed
@max-sixty
max-sixty deleted the focus-phase-3 branch October 9, 2026 03:41
max-sixty added a commit that referenced this pull request Oct 9, 2026
)

The last phase of the focus overhaul gives layers and widgets the
primitives they were each writing for themselves: closing a layer and
landing the user as one act, recording where a layer opened from,
holding a place in a keyed list, and a group's one Tab stop. Widgets
reach them through widget-api.js, and a lint refuses a layer return made
beside them.

Phase 4, the last of the focus overhaul, after phase 2 (#2036) and phase
3 (#2038).

- **`closeLayer(close, land)`** closes a layer the user may stand in and
hands them on as one act. Whatever focus does while `close` runs (the
platform's own hand-back as a dialog or popover closes, the drop to the
body as a focused node hides) reaches no reader of where the user stands
and counts as no placement; `land` then puts the user where the close
takes them, and readers hear one reading. A close inside another lands
nobody and tells nobody: the outer close's landing takes the user on, or
the first inner one where it names none, and nothing an inner close
deferred outlives the outer one, a throw included. A native layer closed
and shown again in one act, as the auxiliary dialog's posture change and
`transitionNativeAncestor` re-seat it, closes through it too, replacing
phase 2's `nativeLayerSteps`: the re-seat's landing puts the user back
through the hold put across it, or lands a user entering a covering
surface from outside on its landing.
- **`openLayer(layer, opener)` and `openerOf(layer)`** record where a
layer was opened from, the control the user stood on by default and
nowhere for the body. They replace the page map's `from`, the command
reference's origin, the media viewer's origin, the target picker's
opener, the drawers' `openedBy` and react mode's `reactFrom`. The
auxiliary surfaces (Threads, the drawers) register an `opener`, their
`hide` moves no focus, and closing hands a user who stood in one back to
its opener, lets them go where it is gone, or follows the closer's
`land`, as the Escape step's `letGo` does; two surfaces on one edge
(Threads and Questions) swap inside the same close.
- **Every close that hands the user back goes through `closeLayer`**:
the thread panel and drawers, the page map, the command reference (after
the repaint that draws the shortcut bar's More again), the versions menu
and a More menu entry, the media viewer, the target picker (which lets
go when opened from nowhere), the margin card (`landOnEntry` for its own
Close and Escape, a let-go otherwise), the margin's fold (`land`
replaces `returnFocus`), react mode (`closeReact`), and the composer.
The composer keeps main's anchor-derived return: `putAwayFab()` hands
the user back to the bar's subject, `letGoOfFab()` lets them go onto the
page, and `showFab(null)` moves no focus, so its `returnFocus` option is
gone. React mode reads which way back is owed before the close and which
candidates are drawn after it, so one the close shows is a way back and
one it hides is not.
- **`layerLanding(land)`** marks a landing several closes share and
built away from the call (the margin's `landOnEntry` and `landOnToggle`,
the composer's `landingFromBar`); it throws if it runs at any time other
than as a close's landing.
- **`holdFocus(scope, { key })`** holds the user's place in a keyed
list: its restore tries the item now carrying the same key, then the
nearest surviving one after it, then before it, then the caller's
stand-ins, landing on the control like the one the user stood on. It
reads rows in the shadow tree they stand in, prefers drawn rows, and
counts a key that marks several nodes once. `RowFocus`
(retained-face.js) is deleted; the Queue and Leaves lists,
lf-targeting's target and change lists, lf-diff's lines (`data-lf-line`,
whose counterpart lookup is deleted), lf-visual-review's dispositions
and the margin's re-presented cluster (`data-lf-margin-entry-identity`,
owner and key) hold keyed. Not keyed, by design: lf-command's
`projectionFocus` hands focus between view roots, and the Asks, carry,
draft and margin standing restores span a document replacement that no
live hold spans.
- **`rove(items, stop)`** sets a group's one Tab stop, replacing the
margin's, lf-tabs', the swipe deck's and the command reference results'
loops. `standingIn(scope)` says whether the user stands in a scope
across shadow trees.
- **Two counts**, stated in focus.js's header: a hold reads placements,
delayed work reads inputs (the decision is in #2038).
- **Lint `architecture/layer-returns`** admits `handBack(...)` only in a
landing's own synchronous body: the function passed as a close's `land`,
through the `&&` or `?:` that picks it, or one `layerLanding` wraps. A
`handBack`, `focusDestination` or `letGo` written in a close's `close`
is refused, as is a `focusDestination(…, "return")` outside a landing
after a statement that hides something by the platform's means (`hide`,
`hidePopover`, `close`, `hidden = true`, a style taking the box out of
view), and aliased imports of both are tracked. That last found one:
withholding the composer bar now closes through `closeLayer`.
tests/runtime/layer-returns-rule.test.mjs runs the rule over acorn's
tree, since eslint lives in pre-commit's environment. The
keydown-listener test counts listeners from the parsed source
(tests/keydown_listeners.mjs) rather than a grep.
- Climbs across shadow trees read a host only off a shadow root: a
document names `<form name="host">` as `document.host`, and a climb
reading `.host` off the document looped for good.
- module-authoring.md documents `openLayer`/`openerOf` and Escape as a
command row; evals/widget-list-keeps-focus asks for a keyed list and a
popup that hands back.

Behavior that changed:
- Closing the thread panel, a drawer, the page map, the command
reference, react mode or the composer tells the shortcut bar and every
other reader of standing once, where the user lands, instead of passing
through the control that reopens the layer.
- Removing a target or change in lf-targeting keeps focus in the list:
on the next row's Remove, or on Select element when none is left. A diff
line or margin entry a re-render removed leaves the user on the nearest
surviving one rather than the file's summary or the cluster's primary.
- Where no way back stands as the reaction choices close, the user is
let go on the page at once.
- Cancelling Page Map, by Escape or its Close control, returns the user
to where they stood as it opened, or to their reading position where
they stood nowhere; activating an entry still navigates to it.

Tests: tests/runtime/focus.test.mjs adds a keyed hold through a shadow
tree, a layer close heard once, an opener handed back with a nested
close, an inner landing under a close that names none, a roving group, a
`layerLanding` refused outside a close, and a keyed hold that reads the
rows once however many held keys have gone;
tests/runtime/reactions.test.mjs closes a list whose close hides the
opener and shows the trigger, which landed on the body before. `npm run
test:runtime` (273) and eslint pass. The focus browser suites (chrome
contracts, navigation, controls, threads, widgets, margin, anchors,
drafts, reactions, aim, read state, interaction layer, send placement)
fail 9 and pass 2173 with one write-watch error, as main (1e9fad2)
does; all but one are main's own, the other is
`test_the_reading_page_keys_follow_the_user_into_the_panel`, which fails
on main in interleaved A/Bs, and the Resume journey passes. `wt hook
pre-merge` fails only `test_send_grows_thread_around_the_words[size2…]`,
which fails on main. Evals (Claude Code and Codex, candidate against the
merge base): widget-list-keeps-focus passes 5 of 6 candidate runs and 0
of 6 base runs; view-reveal-arrival, widget-controller-lifetime,
widget-owned-context-keys and shared-contribution-actions pass 8 of 8 on
the candidate and 7 of 8 on the base.

> _This was written by Claude Code on behalf of max-sixty_

---------

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