Repository navigation
Engine: a shared-mode click into a background Chrome text field focuses it through Accessibility with the caret at the point (#283) - #291
Conversation
…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)
…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)
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
| 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) } |
There was a problem hiding this comment.
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) } |
There was a problem hiding this comment.
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 👍 / 👎.
|
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) |
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.
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:
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, withcaretsaying 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}.note, which the service now passes forclickas it does for paste and type_text: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.
docs/cua-api/agent-cursor.md) and its pins, the surface inventory's Table 3 addition and PROVENANCE.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.<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.secure). A click in the padding is focused but not placed (pointOutsideText).Limits
Tests and review
WebAreaFocusTests39 andBackgroundPointerTests26 pass. The service's 36 tests and the doc pins pass.api/browser-cuaapi/scrollcell, which this change doesn't touch; the cua host passed all 290 cases.Sminos-Session: cursor235#b93055dd (cua on macbook)