Skip to content

fix(cua-driver/linux): prefer focused pyatspi editable#2030

Open
injaneity wants to merge 1 commit into
trycua:mainfrom
injaneity:fix/1947-pyatspi-focused-editable
Open

fix(cua-driver/linux): prefer focused pyatspi editable#2030
injaneity wants to merge 1 commit into
trycua:mainfrom
injaneity:fix/1947-pyatspi-focused-editable

Conversation

@injaneity

@injaneity injaneity commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Prefer a focused AT-SPI EditableText node before falling back to the first editable in tree order.
  • Keep the existing first-editable fallback for unfocused/background windows.

Testing

  • Not run; Linux AT-SPI path not available in this macOS environment.

Fixes #1947

Summary by CodeRabbit

  • Bug Fixes
    • Improved text entry targeting so typing is more likely to land in the currently focused editable field.
    • If no focused editable field is available, the app now falls back to the first editable field it can find.
    • Made editable-field detection more reliable across window contents, reducing missed input targets.

@vercel

vercel Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

@injaneity is attempting to deploy a commit to the Cua Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f414a3f6-bded-424a-bade-cf358d199f68

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

type_into_editable now prefers a focused EditableText node during the pyatspi search, and only falls back to the first editable node in tree order when no focused editable is found.

Changes

Focused editable selection

Layer / File(s) Summary
Prefer focused editable before fallback
libs/cua-driver/rust/crates/platform-linux/src/atspi/mod.rs
The embedded Python search adds helpers for editable and focused state, adds a focused-editable tree walk, and changes window traversal to search for a focused editable before a general editable fallback.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I hop through trees with focused eyes,
I sniff the text-field where the caret lies.
If none is lit, I try the first,
Then type my hops where words quench thirst.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately describes the main change to prefer the focused pyatspi editable.
Linked Issues check ✅ Passed The change matches #1947 by preferring a focused EditableText node and preserving the first-editable fallback.
Out of Scope Changes check ✅ Passed The patch stays within the Linux pyatspi typing path and adds no clear unrelated changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@injaneity injaneity force-pushed the fix/1947-pyatspi-focused-editable branch 2 times, most recently from 8545981 to 2cfb118 Compare June 25, 2026 17:15

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
libs/cua-driver/rust/crates/platform-linux/src/atspi/mod.rs (1)

102-145: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Optional: single-pass walk and narrower exception handling.

Two minor points on the helpers:

  • In the no-focused-editable case, the tree is traversed twice (find_focused_editable then find_editable), and each node incurs per-node AT-SPI D-Bus calls (queryEditableText, getState). A single recursive walk that records the first focused-editable and the first editable would halve the round trips on the fallback path. The unused depth parameter could be dropped as well.
  • The bare except: clauses also swallow KeyboardInterrupt/SystemExit; prefer except Exception:.

Both are non-blocking given this only runs in the AT-SPI fallback path.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@libs/cua-driver/rust/crates/platform-linux/src/atspi/mod.rs` around lines 102
- 145, The AT-SPI helpers in find_focused_editable, find_editable, has_editable,
and is_focused currently do extra work and use overly broad exception handling.
Refactor the traversal so a single recursive walk can record the first focused
editable and first editable node instead of scanning the tree twice, and remove
the unused depth parameter from the recursive helpers. Also replace the bare
except blocks in these helpers with except Exception so KeyboardInterrupt and
SystemExit are not swallowed.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@libs/cua-driver/rust/crates/platform-linux/src/atspi/mod.rs`:
- Around line 152-162: The Python fallback in find_editable is missing the
document-scope preference that Rust’s pick_editable uses, so it can choose the
browser chrome instead of the page field. Update find_editable to track whether
an editable is inside a document/web-doc context and prefer those candidates
before falling back to tree order, using the existing focused-editable pass and
the fallback loop in this section to mirror Rust tiering.

---

Nitpick comments:
In `@libs/cua-driver/rust/crates/platform-linux/src/atspi/mod.rs`:
- Around line 102-145: The AT-SPI helpers in find_focused_editable,
find_editable, has_editable, and is_focused currently do extra work and use
overly broad exception handling. Refactor the traversal so a single recursive
walk can record the first focused editable and first editable node instead of
scanning the tree twice, and remove the unused depth parameter from the
recursive helpers. Also replace the bare except blocks in these helpers with
except Exception so KeyboardInterrupt and SystemExit are not swallowed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4c725a0d-de04-4e70-b5a5-6b784c7e6581

📥 Commits

Reviewing files that changed from the base of the PR and between 46efc5f and 5ed907e.

📒 Files selected for processing (1)
  • libs/cua-driver/rust/crates/platform-linux/src/atspi/mod.rs

Comment on lines +152 to +162
# Prefer focused editable across the whole window before falling
# back to first editable in tree order.
for win in app:
editable = find_editable(win)
editable = find_focused_editable(win)
if editable:
break
if editable is None:
for win in app:
editable = find_editable(win)
if editable:
break

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Confirm pick_editable's tiering and whether any other pyatspi path mirrors in_web_doc.
rg -nP 'in_web_doc|pick_editable|find_editable|find_focused_editable' libs/cua-driver/rust/crates/platform-linux/src/atspi/

Repository: trycua/cua

Length of output: 2092


Align Python fallback logic with Rust's in_web_doc tier

Verified that pick_editable explicitly prioritizes document-scoped editables. The current Python fallback (find_editable) lacks an in_web_doc filter, causing it to select the first editable in tree order (often the address bar) instead of the page field for unfocused browser windows.

Please update find_editable to track/document scope and prefer editables within a document role to match the Rust tiering.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@libs/cua-driver/rust/crates/platform-linux/src/atspi/mod.rs` around lines 152
- 162, The Python fallback in find_editable is missing the document-scope
preference that Rust’s pick_editable uses, so it can choose the browser chrome
instead of the page field. Update find_editable to track whether an editable is
inside a document/web-doc context and prefer those candidates before falling
back to tree order, using the existing focused-editable pass and the fallback
loop in this section to mirror Rust tiering.

@injaneity injaneity force-pushed the fix/1947-pyatspi-focused-editable branch from 2cfb118 to cd892bd Compare June 26, 2026 02:40
@injaneity

Copy link
Copy Markdown
Collaborator Author

Updated per review:

  • The pyatspi fallback now mirrors native Rust AT-SPI editable tiering: focused editable, then editable under document/web content, then first editable in tree order.
  • Replaced bare except: clauses in this embedded helper path with except Exception:.
  • Removed the unused depth traversal parameter.

Validation:

  • git diff --check
  • Extracted and compiled the embedded Python snippet with compile(...) to verify syntax.

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.

pyatspi type_into_editable should prefer the focused editable (parity with #1938)

1 participant