Skip to content

Engine: a Chromium click writes the caret before any focus, and answers placed only when the reference box held still (#341) - #349

Merged
SSFSKIM merged 20 commits into
mainfrom
fix/341-scrolled-caret
Nov 9, 2026
Merged

SSFSKIM merged 20 commits into
mainfrom
fix/341-scrolled-caret

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Closes #341

What changed

focusPlacingCaret (WebAreaFocus.swift), the Chromium click into a text field, now works in this order (the design session's ruling 1ea561bc:544):

  1. The offset, with nothing written. The caret's offset comes from the boxes as the screenshot shows them, including the fresh-mode wait for boxes. The wait's cap is unchanged: webAreaRereadDeadline, 2 s, or up to 3 s just after an enablement write.
  2. The caret first. The in-flight input check runs, then AXSelectedTextRange {offset,0} is written. On Chromium that write focuses the field without scrolling it.
  3. AXFocused as the fallback. If the field still is not focused after the settle, the input check runs again and AXFocused is written.
  4. The read-back.

There is a fallback in two other cases. With no offset found, or for a password field, AXFocused works as before and the click answers the same reason.

"Placed" only when proven (condition 1). The box of the character beside the caret is read before the writes and again after the read-back, and may move at most 1 pt. Otherwise the click answers focusedNotPlaced with a new reason, layoutMoved, and a note asking for a new screenshot.

An offset found by a re-read during the wait needs the same element and the same value length; focus is no longer a condition, since the field is not focused yet.

#296's check after the wait now runs before any write. A screen change found there refuses screenChangedSinceScreenshot with nothing written, so the caret reason screenChanged is gone. The design session approved this amendment (ruling 1ea561bc:550), and #296's entry cross-references it.

The record also changes:

  • elementClick.action and focusStep name the write that focused the field;
  • caretMarkShift gives the reference box's move.

WebKit (#313/#324) and Gecko never reach focusPlacingCaret, and are unchanged.

Spec: the #341 Decision Log entry, which amends #283's order. Evidence: docs/evidence/2026-11-08-scrolled-caret/. Version 0.27.22, set at its merge turn (main is at 0.27.21 after #347).

Why

Writing AXFocused scrolls a scrolled Chromium textarea to its old caret within 0–8 ms. Main then read the boxes of the top-scrolled layout and claimed "placed" for a caret on the wrong line. Typing then went somewhere other than where the model clicked, while the engine answered success.

Measurement first

Run https://github.com/SSFSKIM/cua/actions/runs/42568677106 (kit probe/341-measure; Chrome late and fresh, Safari, Firefox; 2 runners × 3).

  • Main's bug: 46 of 60 placed claims were false, on every scrolled field, whether script-scrolled, wheel-scrolled or overflow auto.
  • Read the boxes after focus: wrong.
  • Compute from the scroll's Δ: right, but it pays the same wait and leaves the field at 0.
  • Restore the scroll: no AX means does it.
  • Write the caret before any focus: the caret lands right with the scroll unchanged in 72/72.

A/B (hosted macOS)

Run https://github.com/SSFSKIM/cua/actions/runs/42578081142 (kit probe/341-ab e91c1e6): main 4cb51b3 against the branch, 2 runners × 3, shared mode with TextEdit frontmost.

timing field (expected offset) main: claim / caret+marker right / scrollTop branch: claim / caret+marker right / scrollTop
late top (96) placed / 6 of 6 / 0→0 placed / 6 of 6 / 0→0
late mid (1,408) placed / 0 of 6 / 640→0 placed / 6 of 6 / 640→640
late mida, overflow auto (1,408) placed / 0 of 6 / 640→0 placed / 6 of 6 / 640→640
late end (3,048) placed / 0 of 6 / 1440→0 placed / 6 of 6 / 1440→1440
late huge, 20,499 chars (9,526) placed / 0 of 6 / 4600→0 placed / 6 of 6 / 4600→4600
late wheel-scrolled (1,449/1,531) placed / 1 of 6 / 650→0 4 layoutMoved + 2 placed / 6 of 6 / 650→655
fresh top, mid, mida, end, huge placed / 6, 0, 0, 0, 0 of 6 placed / 6 of 6 each, scroll unchanged
fresh wheel-scrolled placed / 0 of 6 5 layoutMoved + 1 placed / 6 of 6
  • Main: 72 placed claims, 59 of them false.
  • Branch: 63 placed claims, 0 false. The caret and marker are at the point in 72 of 72. The caret's write focused the field every time.
  • Nothing raised (condition 2): TextEdit stayed frontmost and the window order was unchanged in all 144 Chrome cells.
  • The fresh wait (condition 3): fresh clicks took 1.47–2.04 s against main's 1.16–2.05 s. Late clicks got faster: median 57–83 ms against 118–168.
  • Safari: alike on both engines, right in 72 of 72 per path.

Limits

Tests and review

  • WebAreaFocusTests (48, 9 of them new):
    • the caret written first and focusing the field;
    • the fallback with the caret re-read, including a focus that moves the caret;
    • a field that scrolls on focus or on the caret's write is not placed, while a shift within a point is placed;
    • an unreadable reference box is not placed;
    • a field empty both before the writes and at read-back is placed without a box, while one that fills (0→100) or is cleared (100→0) needs the proof;
    • the check after the wait refuses with nothing written;
    • the record and the layoutMoved note;
    • the choice of reference character.
  • The engine's swift test passes: 1,091 tests, with main 95ed66e merged.
  • ci-gate plugin,test,engine-swift,parity-browser is GREEN on d335289, the head merged with main 95ed66e at 0.27.22: https://github.com/SSFSKIM/cua/actions/runs/42592550254. parity-browser passed on a rerun of its failed job; the first attempt hit only the known racy cell api/browser-playwrightlocator/waitfor locator-contract-diagnostics-no-matches (tech-debt-tracker.md, 2026-10-18).
  • reviewer-high, 3 rounds. Round 1 (P2): the empty-field waiver was decided before the writes, so a field a focus handler fills (0→100) could answer placed; fixed in 686866d. Round 2 (P2): the inverse, a field cleared while taking focus (100→0); fixed in 55e704c, the waiver now needing the field empty before the writes and at read-back. Round 3: no material findings.

Residue

Sminos-Session: cursor235#b93055dd (cua on macbook)

…, then x, the linear scan deciding only what the search cannot (refs #290)

A bisection in reading order finds the point's line and its place on it, and #283's linear scan over the few
characters there places the caret; any other answer is the linear scan's over the whole value (within 5,000
characters) or over 5,000 around where the search ended, so no field is refused for its length. Unusable boxes
are stepped past, never inferred across; boxes out of reading order and right-to-left text are not searched.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…sal, nothing read, as no search gives a window near the point (refs #290)

Sminos-Session: cursor235#b93055dd (cua on macbook)
Sminos-Session: cursor235#b93055dd (cua on macbook)
…ed evidence, and 0.27.17 (refs #290)

Sminos-Session: cursor235#b93055dd (cua on macbook)
…efused, not answered from a window near where the search stopped (refs #290)

Sminos-Session: cursor235#b93055dd (cua on macbook)
… precondition, in the entry and the evidence (refs #290)

Sminos-Session: cursor235#b93055dd (cua on macbook)
…aracters, and checks the boxes it read on every way out (refs #290)

Sminos-Session: cursor235#b93055dd (cua on macbook)
…310's 0.27.18 (refs #290)

Sminos-Session: cursor235#b93055dd (cua on macbook)
…ed, an unknown direction authorizing no offset (refs #290)

Sminos-Session: cursor235#b93055dd (cua on macbook)
…y write and places it by AXSelectedTextRange, AXFocused only the fallback, placed only where the field did not scroll (refs #341)

AXFocused scrolls Chromium's textarea to its existing caret, so the boxes read after focus described a layout the
screenshot never showed (46 of 60 placed claims wrong, run 42568677106). The offset, its fresh wait for boxes included,
now comes first; the caret's write focuses the field; a reference character's box read before and after must not move
more than a point. #296's guard after the wait now refuses with nothing written.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…t (refs #341)

Sminos-Session: cursor235#b93055dd (cua on macbook)
…ite first and AXFocused its fallback (refs #341)

Sminos-Session: cursor235#b93055dd (cua on macbook)
…t (refs #341)

Sminos-Session: cursor235#b93055dd (cua on macbook)
…he fallback, placed only where the field did not move) and the hosted A/B's evidence, run 42578081142 (refs #341)

Sminos-Session: cursor235#b93055dd (cua on macbook)
Sminos-Session: cursor235#b93055dd (cua on macbook)
…#348), and #296's amendment approved and cross-referenced (ruling 1ea561bc:550) (refs #341)

Sminos-Session: cursor235#b93055dd (cua on macbook)
…ed at read-back, so a field a focus handler fills is not placed (refs #341)

The review of round 1 (P2): the exemption was fixed before the writes, so a textarea filled and scrolled while taking
focus, its caret still at {0, 0}, answered placed with its scroll unproven. It is now layoutMoved.

Sminos-Session: cursor235#b93055dd (cua on macbook)
… writes and at read-back, so a field a focus handler clears is not placed either (refs #341)

The review of round 2: a field with text, offset 0, cleared by its focus handler read empty at read-back and was waived
the proof with its box unreadable after the writes. Both emptiness reads are now required.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…ret (refs #341)

The spec's Decision Log conflicted at its end: both entries kept, #310's before #341's.

Sminos-Session: cursor235#b93055dd (cua on macbook)
… main merged (refs #341)

Sminos-Session: cursor235#b93055dd (cua on macbook)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T10:18:08.032250Z d335289 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@SSFSKIM
SSFSKIM merged commit 536066f into main Nov 9, 2026
5 checks passed
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.

Engine: a click in a scrolled Chromium textarea places the caret on the line as if the field were scrolled to the top (focus scrolls it first)

1 participant