Skip to content

Clear keyboard focus rings during panel resizing - #937

Merged
max-sixty merged 4 commits into
mainfrom
codex/fix-resize-focus
Sep 22, 2026
Merged

max-sixty merged 4 commits into
mainfrom
codex/fix-resize-focus

Conversation

@max-sixty

@max-sixty max-sixty commented Sep 22, 2026 •

Copy link
Copy Markdown
Owner

Dragging a resize handle after keyboard use kept its tall keyboard focus outline visible. Let native pointer focus clear that state, then restore focus when a drag ends or is cancelled so mouse and touch both retain arrow-key resizing. The shared handler covers the thread panel and tray edge.

Keep resize presses out of composer dismissal, and only snap text selections for gestures that began in page content. Resizing therefore preserves an open draft and an existing partial-text selection. Selection-snapping tests now arrange complete pointer gestures, including releases across shadow roots.

Validation includes mouse, touch, and cancelled-touch regressions on both edges, direct before/after browser checks, the full browser gate, selection and draft browser tests, runtime tests, and pre-commit. The complete anchor and MCP browser files pass all 105 tests. The selection/draft run passed 122 tests; its remaining failure (test_a_refused_comment_takes_its_message_back_and_returns_the_words) reproduces on base c1f6b33b and is already covered by #917. The mouse-ring regression fails on the unchanged baseline; the expanded regression reproduced the composer dismissal and selection rewriting before the repair.

This was written by Codex on behalf of max-sixty

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Removing event.preventDefault() does buy the native pointer focus this fix needs, but that line was doing two jobs and only one is re-established. It also kept the edge press out of the compatibility mouse events, and the chrome reads a document mousedown as a press on something else: standDown in composing/surface.js — the document.addEventListener("mousedown", …) whose branch calls showFab(null, null, { returnFocus: "page" }), and hideComposer() with the full composer up. So on this branch a drag on either edge closes an open comment field and discards what the reader had typed into it, and the mouseup handler in the same file then runs snapSelection() over their standing selection. Widening the panel to read a draft better is the gesture that loses the draft.

Measured on both edges in the merged tree, with main at c1f6b33b as the control:

gesture c1f6b33b this branch
mouse drag on the edge with the comment field open and half a comment typed field open, text intact field closed, text gone
same drag with agraph 1. F selected in the page selection unchanged selection rewritten to Paragraph 1. Filler.
touch drag cancelled mid-gesture focus on the edge, arrows still resize focus on body, arrows dead (see the inline note)

Two places the rule could go. Locally, the edge can keep its own press out of that reading — edge.addEventListener("mousedown", (event) => event.stopPropagation()) leaves the native focus intact, and I measured the composer and the selection surviving with the new case still green. Or the chrome's stand-down reading can say that a press on apparatus owning its own gesture is not an outside press, which is where it belongs if more furniture will want it; standDown's exempt list is already a list of surfaces rather than a rule.

The new case pins the ring, and nothing pins either duty the removed line held. A drag taken with a composer open and a selection standing is what would have caught this, and it belongs beside the ring assertions rather than in a case of its own.

Happy to push both fixes if you say which direction you want for the first.

How each row was measured

All three rows ran -n0 against the merged tree, once with skills/leaf/assets/runtime/drawn-edge.js as this branch writes it and once with git show c1f6b33b: of the same file, on the EDGES fixtures at a 1400×900 viewport.

Composer row: open the thread panel or tray, Alt-click the first paragraph, type into .lf-fab-input, then mouse-drag the handle 80px. Reading .lf-fab-bar visibility and the field's value after the release.

Selection row: setStart/setEnd at offsets 3 and 14 of the second paragraph's text node, then the same drag, reading getSelection().toString(). snapSelection() is reached because the mouseup handler's own guard — if (!pageWords(ev.target) && !pageSelection()) return; — passes on the standing selection.

Cancelled-touch row: focus the handle, press ArrowRight to raise the ring, then Input.dispatchTouchEvent with touchStart, touchMove, touchCancel through CDP, reading document.activeElement and whether a following ArrowRight still moves the region's width.

The preventDefault()-preserving shape is not an option: with the press refused, edge.blur() on pointerdown plus edge.focus() on release puts the ring back, and the new case's mouse half fails on it. The native pointer focus this PR adopts is what actually clears the ring.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

test_real_page_passages_can_be_quoted goes red on four example pages on this branch — pr-walkthrough, feature-gallery, ship-review, visual-review-gallery — and passes on the merge base c1f6b33b. Each reports one passage that "raised no Comment button", so the sweep stops covering it.

The sweep stands a bare document.dispatchEvent(new MouseEvent('mouseup')) in for a reader's drag: it places a range through the Selection API and then releases. !selectedOnPage reads a press that never happened, so the release no longer owns those words. The rule itself is the right one — a real drag sets pointerSelecting on its own pointerdown, and the new gate case proves it end to end — but the sweep's arrangement is now a gesture the runtime does not recognise, and it was the arrangement that reached the snap.

The second consequence is the larger one. That guard returns on every iteration of the sweep, not only the four that fail: the Comment button the others still raise now comes from the selectionchange route, and snapSelection() — whose one call site sits past that return — is no longer reached anywhere in the file. So the sweep's missed and astray assertions, which are what prove a captured quote lands inside the words that were selected, now read unsnapped ranges on every page it sweeps.

Giving the sweep the press its gesture implies settles both: dispatching a pointerdown on blocks[i] before the mouseup puts all four back to green. It's outside this diff — say the word and I'll push it.

One note on the validation in the description: test_render_anchors.py is in the nightly selection, so uv run pytest tests skips it and a green local gate would not have shown this. It reaches main's complete suite once the everyday gate there is green.

How each claim was measured

All runs were in the merged tree (refs/pull/937/merge), against installed Chrome.

Branch, whole file plus the everyday-gate file that shares the arrangement: uv run pytest tests/test_render_anchors.py tests/test_render_mcp.py -n 4 → 6 failed, 99 passed. Four are the sweep above. The other two, test_a_diff_surface_keeps_the_complete_thread_lifecycle_inline[light] and [dark], fail identically with c1f6b33b's copies of both runtime files in place, so they are not this branch's. test_render_mcp.py dispatches the same synthetic mouseup in three places and stays green — none of them asks for the snap.

Control: git show c1f6b33b: of composing/surface.js and drawn-edge.js written over the branch's, everything else untouched. pr-walkthrough and feature-gallery pass under -n0; restoring the branch's two files fails both again under -n0, so it is not a parallel-selection or ordering effect.

Repair, on the branch: one line added to the sweep, before the mouseup,

blocks[i].dispatchEvent(new PointerEvent('pointerdown', {
    bubbles: true, composed: true, isPrimary: true, button: 0}));

and both node ids pass under -n0. selectionDragged stays false, so the release takes neither the escaped nor the completed branch and reaches snapSelection() the way a stationary press does.

tests/test_render_gate.py::test_dragging_an_edge_preserves_reader_state passes on the branch, 6/6.

@max-sixty
max-sixty merged commit b6404db into main Sep 22, 2026
5 checks passed
@max-sixty
max-sixty deleted the codex/fix-resize-focus branch September 22, 2026 19:02
max-sixty added a commit that referenced this pull request Sep 23, 2026
…the gesture (#982)

"Keep the reader's place" had been fixed one surface at a time (#919,
#922, #937, #946, #954, #955, #956, #971). The thread list had a good
hold that no other surface could use. The Page Map restored its raw
`scrollTop`, so a group arriving above the view pushed the rows the
reader was on down by that group's height. The margin card relied on
native anchoring. The panel's visible band was measured three different
ways. Separately, `reveal()` took its reader intent when it was called,
so an async caller that forgot to pass one got a late capture, and
`lf-diff` moved focus and scroll after a network wait no matter what the
reader had done since.

## What changed

- **`runtime/reader-place.js`**: `placeKeeper(scroller, {items,
identity})` holds one reference node's content offset through a
mutation. It picks the reference from the pointer, then focus, then the
visible band. It suspends `overflow-anchor` while the hold lasts, hands
the place to whatever node a render put under the same identity, and
follows a running fold. The thread list (keyed by thread id), the Page
Map's `renderSheet` (keyed by `data-lf-map-key`), and the margin card's
re-render of the same thread (keyed by event id) all use it. A node with
an empty identity hands the place to the next candidate and is never
matched to another node that also lacks one.
- **`geometry.js`**: `visibleBand` (the shown band minus stuck
`.lf-pinned` covers) and `landingBand` (minus the declared
`scroll-padding`). Read acknowledgement, the thread card's being-read
check, conversation landing, and anchor travel now read these instead of
measuring for themselves.
- **Reader intent**: `reveal(el, intent)` now requires the intent
retained at the gesture and throws without one. `lf-diff`'s `stepHunk`
and `nextUnreviewed` capture intent before they load a file, and land
only if that intent still stands. `references/packages.md` states the
contract. `scroll` is still not a cancelling input: the runtime's own
landings fire it. `reader-intent.js` now lists the input that begins
each way a reader can scroll. A probe confirmed that pressing a
scrollbar fires `pointerdown` on the scroller.
- **The #954 ordering rule is now the interface**: `chrome-layout.js`
exports `takeShell(key)` in place of a frame that took a callback. A
surface owner therefore has no way to render inside the frame that
native anchoring depends on.

## Behavior that moved

- With no pointer or focus to lead, the thread list's hold now uses the
topmost visible card, which is what its header said. Before, it used the
second.
- A card entirely under a stuck heading no longer counts as visible.
- The Page Map keeps the rows the reader was looking at, not a scroll
offset.

## Tests

- `tests/runtime/reader-place.test.mjs` covers candidate order, the
clamp-aware correction, band insets, the identity hand-across, and an
empty identity that must not hand the place across. Each hand-across
case was checked by disabling the hand-across and watching the case
fail.
- `test_chrome_contracts.py` (everyday) gets a new Page Map continuity
test. It fails against the base `page-map-dialog.js` (row moved 36px).
The file also takes
`test_taking_the_panels_strip_leaves_the_reader_on_the_same_words` from
the nightly controls file.
- `test_render_anchors.py` gets a nightly test: a hunk step still
waiting on a file leaves a reader who has pressed elsewhere. It fails
against the base `lf-diff.js`.
- Local: `npm run test:runtime` 60 passed. A focused browser selection
across margin, controls, widgets, projection, anchors, and chrome
contracts: 142 passed.
`test_render_navigation.py::test_pressing_a_page_mark_stands_in_the_thread_it_opens[long]`
fails the same way on the unchanged base.

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

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

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.

2 participants