Skip to content

Engine: the caret's offset searched by line, then x, with #283's linear scan deciding only the few characters it ends at (#290) - #342

Merged
SSFSKIM merged 9 commits into
mainfrom
fix/290-caret-search
Nov 9, 2026
Merged

SSFSKIM merged 9 commits into
mainfrom
fix/290-caret-search

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Nov 9, 2026

Copy link
Copy Markdown
Owner

Closes #290

What changed

Before this change, #283 placed a clicked caret in a Chromium text field by reading AXBoundsForRange for each character from the start until one held the point, and refused a field longer than 5,000 characters (pointOutsideText).

caretOffset (WebAreaFocus.swift) now searches:

Each box is read at most once, and a run of unusable boxes is stepped past, at most 64 of them.

What the search trusts, after the review:

  • The text's direction is read first, from the first two neighbouring characters with boxes that do not wrap. Vertical or leftward text is not searched.
  • Right-to-left text (holdsRightToLeft) is not searched.
  • A text whose first characters have no boxes yet is not searched.
  • Every way out of the search checks the boxes it read for reading order.

Such text gets the linear scan within 5,000 characters, and past that #283's refusal, or noCharacterBoxes for the wait on arriving boxes to re-read.

Spec: the #290 Decision Log entry. Version 0.27.19 (0.27.16–18 are held by #330, #303 and #310).

Why

A click deep in a long field cost one read per character before it, about 0.1 ms each on the hosted runner, and a field past 5,000 characters could not be clicked into at a point at all.

Live (hosted macOS, Chrome for Testing 156)

Run https://github.com/SSFSKIM/cua/actions/runs/42560301611: two runners, main 364e017 against 93bc212, kit probe/290-measure a21b1d7. Each field is scrolled mid-way; the click lands at row 2.5 of its four shown lines, and a typed marker follows.

field engine cells claim page caret offset under the point (unfocused dump) late click, median
3,074 chars main 12 placed 96 1,408 188 ms
3,074 chars branch 12 placed 96 1,408 122 ms
20,499 chars (at a line, past a line's end, far) main 24 pointOutsideText 0 9,526 / 9,552 / past 10,000 51–62 ms
20,499 chars branch 24 placed 96, 122 past the end 9,526 / 9,552 / past 10,000 108–144 ms

Both engines place offset 96 on the 3,074-character field because of #341, not because of this change. Focusing Chromium's textarea scrolls it to its caret before the offset is read, so the boxes read describe the field scrolled to its top. The live cells therefore show:

  • the branch answering as main where main answers;
  • the branch placing on a 20,499-character field, where main refuses every time;
  • the typed marker landing at the claimed offset.

The search's correctness rests on the offline replay. The branch's caretOffset (extracted from the head) and #283's linear scan were both run over each runner's unfocused box dump, at the click and at a grid of 24,400 points per field:

dump at the click: search at the click: linear scan grid agreement
3,074 chars 1,408 in 29 reads 1,408 in 1,409 reads 24,400 / 24,400
20,499 chars (AXValue capped at 10,000) 9,526 in 29 reads 9,526 in 9,527 reads 24,400 / 24,400
far point, past 10,000 pointOutsideText in 5,002 reads the same in 10,000 reads 24,400 / 24,400

The A/B ran on 93bc212. The review's changes after it touch only text whose boxes do not run rightward on a line, which no cell has; the replay was rerun on the head. Evidence: docs/evidence/2026-11-08-caret-search/.

Cost

At a hit, about 29 reads, 3 ms, where #283 read up to 5,000. A miss (a point outside the text, or past the AXValue cap) still costs the bounded linear scan: up to 5,000 reads, about 500 ms.

Limits

Tests and review

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)
@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-09T06:48:14.814075Z 0f60e5f 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.

@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: 0f60e5f7f7

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

samples.sort { $0.index < $1.index }
for (earlier, later) in zip(samples, samples.dropFirst()) where earlier.index != later.index {
if earlier.box.minY >= later.box.maxY { return false }
if onLine(earlier.box), onLine(later.box), earlier.box.minX > later.box.minX { return false }

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 Validate right-edge ordering before trusting the x search

When character boxes overlap horizontally, increasing minX does not guarantee the increasing maxX required by the x bisection. The current guard therefore accepts layouts where the search skips an earlier character containing the click and returns a different offset. For example, four boxes with (x, width) values (0, 30), (10, 5), (15, 5), (20, 5), all at y = 0 with height 20, pass this check; at (22, 10), the extracted implementation returns offset 3 while the original linear scan returns 1. This affects overlapping styled text and bypasses the full-range fallback even for short values. Check the right-edge ordering used by the search and fall back when it is violated.

Useful? React with 👍 / 👎.

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: the focus route's caret scan searches a field's character boxes by line, then x, instead of linearly

1 participant