Skip to content

Engine: a shared-mode click into a background Chrome text field focuses it through Accessibility with the caret at the point (#283) - #291

Merged
SSFSKIM merged 12 commits into
mainfrom
fix/283-web-text-focus
Nov 6, 2026

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

Summary

Before this change, a click into a text field on a background Chrome page was refused in shared mode (#282's backgroundClickRefused, walkStopped editable). So a "click the field, then type" sequence failed at its first step. Now the click gives the field keyboard focus through Accessibility, with no mouse event and no window ordering, and places the caret at the clicked point. The result's text says what was done and where typing will go. A hosted macOS runner proved it live (below).

Closes #283

What changes

The route. In shared mode, a plain single left click whose #282 walk stops at an editable element now takes a focus route instead of the refusal.

  • The target. The hit itself when it is a text-entry role (AXTextField, AXTextArea, AXComboBox, AXSearchField, AXSecureTextField) whose AXFocused is settable. Otherwise, the nearest such element up its parents, reached through editable and macOS engine: a left click into a background Chrome page is swallowed as the window's activating click, and cua reports success #282-passable children only. A contenteditable region's hit is its AXStaticText.

    • The target's ancestry must read up to the AXWebArea.
    • A text-entry role whose AXFocused is not settable, any other role, the web area and an unread ancestry are refused, as before (walkStopped).
  • The focus. Route 1, no activation. AXFocused is written, then polled for up to 300 ms. The click counts only once it reads back true; a write's own success answer never counts (Chromium answers success on a static text and does nothing). A field that never reads focused answers clickUnconfirmed.

  • The caret. The offset comes from the characters' boxes (AXBoundsForRange {i, 1}) over the whole value, up to 5,000 characters:

    • in the box under the point, before or after the character by its half;
    • past a line's end, at that line's end, only where the end is established;
    • an empty field is 0.

    It is then written as AXSelectedTextRange {offset, 0} and read back. In a contenteditable region, the hit's local offset is mapped into the region's offsets by finding each of its texts in order in the region's AXValue (a <br> counts one character there and has no element).

  • Not placed (focusedNotPlaced, with caret saying why). It is a success with the field focused.

    • secure: a password field is focused only; its value and ranges are never read.
    • pointOutsideText: no box holds the point; an offset is never guessed.
    • noCharacterBoxes: the boxes are still empty.
    • selectionMismatch: the read-back differs.
    • unmapped, unreadable: the region's text or the value can't be mapped or read.
  • A fresh Chrome (the design session's rulings 37d4c12c and 9ba80c48). Chromium's character boxes are empty until its complete accessibility mode arrives, about 1.5 s after the first observation.

The answer.

  • elementClick {plan action, action AXFocused, reason focusField | focusedNotPlaced, pressedRole, pressed hit | ancestor, walk, caret}.
  • The result's note, which the service now passes for click as it does for paste and type_text:
    • placed: "focused through accessibility, with the caret at the point. No mouse event was sent, so the page saw no click."
    • not placed: typing goes to the field's existing selection or its start; use select_text or set_value first.

Unchanged. A double click, a drag and focusField's fallback into a background web page stay refused (#289). AXPress isn't used: after complete mode it makes Chrome play trusted pointer events into an input.

Docs.

Live proof (hosted macOS runner)

docs/evidence/2026-11-05-web-text-focus/ holds the final run https://github.com/SSFSKIM/cua/actions/runs/42155227806 and its repeat https://github.com/SSFSKIM/cua/actions/runs/42155231373, at af4bd33. Both reps agree in every cell.

  • Config: Chrome for Testing 156 behind a frontmost TextEdit, on macOS 26.6.2 and 26.7.2.
  • main: every text-field click is refused, and typed text goes nowhere.
  • The branch:
    • The input, the textarea, a one-node and a multi-node contenteditable (in its 2nd and 3rd text node, after a <br>), a field with a prior selection, and a point past a line's end are all focused, with the caret at the expected offset and type_text landing there.
    • Answers come in 55–199 ms 3 s after the observation, and in 1.5–1.9 s when clicked 0.1 s after it (the re-read). In the repeat run, 32 of 32 fresh clicks were placed.
    • The password field is focused only (secure). A click in the padding is focused but not placed (pointOutsideText).
    • In every cell: zero pointer or mouse events, TextEdit frontmost, Chrome not raised.
  • Measurement rounds before the build (probe/283-hosted, which stays off main):
    • AXFocused focuses all three kinds before and after complete mode.
    • AXRangeForPosition always answers {0,0} and AXTextMarkerForPosition answers no value, hence the box scan.
    • AXVisibleCharacterRange answers the whole text, or {0,0} on a static text.
  • The earlier A/B (run 42152333871, at 2c016f7) found two bugs, both fixed in af4bd33. A contenteditable's caret was never placed, because the scan honored the static text's {0,0} visible range. And 1 in 10 fresh textarea clicks settled not-placed while boxes were half-arrived. The engine's answers were honest in both.

Limits

Tests and review

  • Engine: WebAreaFocusTests 39 and BackgroundPointerTests 26 pass. The service's 36 tests and the doc pins pass.
  • CI: ci-gate GREEN on the final head bf01271 (engine-swift, sandbox-live, test, plugin, parity-browser): https://github.com/SSFSKIM/cua/actions/runs/42159014283. An earlier run on 5e7c31f failed only parity-browser's vendor-host api/browser-cuaapi/scroll cell, which this change doesn't touch; the cua host passed all 290 cases.
  • reviewer-high on 5fd8915..36422dc, then bounded re-reviews of each fix range. Lens: "no success without a known effect, and nothing read or posted that the rulings forbid".
    • Fixed: an unreadable value counted as empty, an unestablished line end, a failed subrole read failing open, an empty next box taken as a soft wrap, an unread role in the region walk, the secure requalification before each re-read, and surrogate pairs.
    • The bounded round on 2c016f7..5601bb0 was CORRECT.
    • The round on 5601bb0..af4bd33 found one more case, surrogate pairs, fixed in 6ba2aaa. I checked that diff myself rather than in another round.

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

…ocuses it through AXFocused, accepted once it reads back true, and places the caret at the point from the field's character boxes (refs #283)

Sminos-Session: cursor235#b93055dd (cua on macbook)
…Decision Log for #283's focus route; 0.24.0 (refs #283)

Sminos-Session: cursor235#b93055dd (cua on macbook)
…ine end that is established, and a field whose subrole read fails is secure (refs #283)

An AXValue that does not read as a string is the new CaretNotPlaced case unreadable, never an empty field;
fieldCaretOffset answers Result<Int, CaretNotPlaced> through the testable textCaretOffset. caretOffset's line-end
fallback takes the rightmost character's end only when the next offset is the text's end, a line break, or a
character whose box starts on a lower line. The subrole seam is SubroleRead (subrole, none, failed), and a failed
read classifies the field secure: focused only, nothing of it read.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…ever an empty one such as CGRect.zero (refs #283)

At negative screen y (a display above the primary one) an empty next box lies below the line in coordinates and
made the line's end look established; the next character's box must now have width and height, as the scan's own.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…mapped into the region's offsets by finding its texts in order; no usable box at all is noCharacterBoxes (refs #283)

Round 2 of the hosted probe (run 42150236590) measured the region's five AXStaticText children and no element for a
<br> that is a character of the region's AXValue: regionTextStart walks the region's descendants depth-first (at
most 2,000 nodes) and finds each static text's value onward from the previous one, and the hit's local offset from
its own boxes is added to that start; AXSelectedTextRange is written and read back on the region. Anything it cannot
establish stays unmapped. caretOffset answers a Result and tells an empty set of boxes (before complete mode) from a
point outside the boxes read. AXVisibleCharacterRange answers the whole text, as the doc comment now says.

Sminos-Session: cursor235#b93055dd (cua on macbook)
… is re-read for up to 2 s, and its offset written only once the field re-validates (refs #283)

The design session's ruling 37d4c12c: focus is written and confirmed at once; where the caret answers
noCharacterBoxes and the process is fresh by #282's rule, caretAwaitingBoxes computes the offset again every 100 ms
for up to 2 s, posting nothing, and stops at the first other answer. An offset found by a re-read is written only if
the field still reads focused, the hit still resolves to the same element (CFEqual, not secure), and its value's
length is unchanged; otherwise, still empty at 2 s, or not fresh, the caret is noCharacterBoxes.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…d the wait for boxes requalifies the field before each re-read (refs #283)

regionTextStart skipped a node whose role could not be read, so an earlier static text was lost and a later repeated
word mapped to the earlier occurrence; every visited node now needs a readable role. caretAwaitingBoxes re-read a
field that had turned into a password field during the wait; sameTarget (the same element, not secure) is now
checked before each re-read, and the wait stops with noCharacterBoxes when it fails.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…still arriving is re-read in a fresh Chrome (refs #283)

Run 42152333871 (the live A/B at 2c016f7): a static text reads AXVisibleCharacterRange {0, 0}, so the region's
caret was never placed; the range is no longer read and the scan covers 0..<length under caretScanLimit. A fresh
textarea's boxes arrive line by line: caretOffset now tells a miss with some expected box empty (boxesIncomplete,
never recorded) from a complete one, and caretAwaitingBoxes re-reads it like noCharacterBoxes within the same 2 s,
answering pointOutsideText when not fresh or still incomplete at the bound. Under the design session's conditions
(9ba80c48) line breaks, whitespace, format characters, combining marks and surrogate halves never count as missing.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…ji line still arriving is re-read (refs #283)

mayLackBox exempted both halves of a surrogate pair, so a supplementary character with no box never counted as
missing and a fresh "a\n😀" settled on pointOutsideText. A pair is now one character: its trailing half needs no
box, its leading half carries the character's, exempt only when the scalar is.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…ull re-read (refs #283)

Sminos-Session: cursor235#b93055dd (cua on macbook)
…y text-field click; the branch focuses all five kinds with the caret at the point, the password field focus only)

Sminos-Session: cursor235#b93055dd (cua on macbook)
Sminos-Session: cursor235#b93055dd (cua on macbook)
@SSFSKIM
SSFSKIM marked this pull request as ready for review November 6, 2026 04:01
@chatgpt-codex-connector

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

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-06T04:04:24.937877Z bf01271 Draft marked ready
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bf0127187d

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +134 to +135
if box.minX <= point.x, point.x < box.maxX { return .success(point.x < box.midX ? index : index + 1) }
if lineEnd.map({ box.maxX >= $0.x }) ?? true { lineEnd = (index + 1, box.maxX, box) }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Advance past the whole surrogate pair when placing the caret

For a field containing a non-BMP character such as 😀, clicking its right half returns an offset inside the surrogate pair: with the glyph's box on UTF-16 index 0 and no box on index 1 (the representation already modeled in WebAreaFocusTests), textCaretOffset returns 1 instead of 2. focusPlacingCaret then writes that offset directly to AXSelectedTextRange, so the click either fails placement verification or positions subsequent typing inside the character rather than after it. Use character boundaries for the returned offset and line-end candidate; the surrogate handling in mayLackBox currently only affects missing-box classification.

Useful? React with 👍 / 👎.

if lineEnd.map({ box.minX >= $0.x }) ?? true { lineEnd = (index, box.minX, nil) }
continue
}
if box.minX <= point.x, point.x < box.maxX { return .success(point.x < box.midX ? index : index + 1) }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Account for text direction when choosing a character boundary

For Hebrew or Arabic text, the left half of a glyph is its logical trailing edge, not its leading edge. This unconditional left-to-right mapping therefore places the caret on the opposite side of the clicked character. For example, with אב laid out right-to-left, clicking the right half of א returns offset 1 instead of 0; the selection read-back can confirm that incorrect offset and report placed, causing subsequent typing to land at the wrong position. Determine the run's direction before choosing the boundary, or report the caret as not placed when direction cannot be established.

Useful? React with 👍 / 👎.

@SSFSKIM

SSFSKIM commented Nov 7, 2026

Copy link
Copy Markdown
Owner Author

Update from #287: the configs this PR's Limits named as unmeasured are now measured (hosted macOS, main's engine at 51b473f, 2 reps).

Findings: #287 (comment)
Evidence: https://github.com/SSFSKIM/cua/blob/main/docs/evidence/2026-11-07-other-browsers/README.md

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.

macOS engine: a background Chrome text-field click in shared mode focuses the field through AXFocused, and says the caret was not placed

1 participant