Skip to content

Release hidden focus before a delayed return - #2078

Merged
leaf-agent merged 2 commits into
mainfrom
fix/ci-37775867395-resume-reveal
Oct 8, 2026
Merged

leaf-agent merged 2 commits into
mainfrom
fix/ci-37775867395-resume-reveal

Conversation

@leaf-agent

Copy link
Copy Markdown
Collaborator

What changed

A closing layer now releases a focused control immediately if it has already become hidden. The return target still gets its next-frame chance to appear. A newer key cancels that pending return, so rapid Escape, g, i reaches Resume writing instead of going to a hidden comment field.

The focus-owner regression test now covers a new key arriving while a return is pending.

Evidence

  • Main CI run 37775867395 failed the draft Resume journey. Local key traces showed g and i targeting the hidden <leaf-text> after Escape.
  • uv run pytest 'tests/test_render_controls.py::test_a_closing_layer_hands_the_user_back_to_the_first_place_that_takes_them' 'tests/test_render_aim.py::test_resume_reveals_an_open_draft_when_its_existing_subject_hides' -q --tb=short passes.
  • uv run pre-commit run --files skills/leaf/assets/runtime/focus.js tests/test_render_controls.py passes.

This was written by Codex on behalf of max-sixty

A closing response can hide its focused field while handBack waits one frame for its target. Rapid g i then goes to the hidden editor and Resume writing never runs. Yield hidden focus immediately, and let a newer key cancel the pending return. Keep the existing next-frame target retry and focus-placement guard for other returns.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pending return can override a newer landing that briefly takes focus and then blurs back to the page. The yielded branch checks only that the body is active, so it misses that placement; in the browser regression I added, handBack(shut) followed by open.focus(); open.blur() ends focused on shut after the frame. Keep the placement count check for both branches so a later let-go remains the user's latest destination.

Comment thread skills/leaf/assets/runtime/focus.js Resolved
A layer close releases hidden focus through a borrowed body stop. Its later blur is not another placement, while a genuine landing followed by blur is. Count both correctly so the pending return yields to the user's newer place.
@leaf-agent
leaf-agent merged commit e06a672 into main Oct 8, 2026
5 checks passed
@leaf-agent
leaf-agent deleted the fix/ci-37775867395-resume-reveal branch October 8, 2026 21:34
max-sixty added a commit that referenced this pull request Oct 9, 2026
…2036)

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.

This is phase 2 of the focus overhaul, the first of three stacked PRs:
this one against `main`, phase 3 against `focus-phase-2`, phase 4
against `focus-phase-3`. Phase 1 landed as #1967.

- 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
cause `press` is a route landing on a control to press it, as a go-to
does, which opens nothing on arrival, or a control focusing itself under
the user's press, as lf-trace's timeline markers and image do.
- A native layer's own opening and closing steps (`showModal`, `close`,
`hidePopover`), which move focus the platform's way, run inside
`nativeLayerSteps(steps)`: what they do with focus is the layer's
return, and no newer word to a hold waiting across them. Main's native
auxiliary dialog (#2006) re-seats its envelope and the layers above it
this way, where it had used `returningFocus`.
- 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 returns that published as moves now say `return`: the banner's
refocus of its door and of the control after a removal, the thread
panel's invoker, the reaction list's own return, surface.js's return to
Threads, the margin's cluster repaint, card transfer and
`restoreStanding`, and the 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, the Asks view's restore after a revision, the
playground's return from a native range, lf-draft's return to the draft
or its Edit control as its editor closes, and the covering surface's
entry, which main had wrapped in `returningFocus`).
- 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. The fold reads the node the user left: a node hidden
under the user 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.
- An auxiliary surface'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.

Tests: tests/runtime/focus.test.mjs asks that a move, a return and a
step each reach `onStanding` with the cause the placement names, and
that a placement naming none is refused; it fails before
`focusDestination` took a cause. `npm run test:runtime` (255) 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 7 and pass 2164, the same 7 that
fail on main (dc26922);
`test_resume_reveals_an_open_draft_when_its_existing_subject_hides`, the
Resume journey #2078 fixed, passes.

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

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty added a commit that referenced this pull request Oct 9, 2026
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 #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_

---------

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.

1 participant