You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(mobile): keep the cursor and keyboard when tapping an autocorrected word on Android - #36947
On Android, tapping a word that Samsung Keyboard autocorrected closed the keyboard, and the chat box lost its cursor. Now the cursor stays where you tapped and the keyboard comes back, so you can fix the word.
What Changed
Before: you type "run the nlx tests" and autocorrect turns it into "Run the next tests". Tap next to fix it: the keyboard closes, the chat box drops, and the cursor is gone. You have to tap after the word and backspace through it.
After: the cursor stays where you tapped and the keyboard comes back. Back still closes the keyboard and ends focus, as before.
Mechanism (mobile/src/platform/keyboard-close-blur.web.ts, Android page only): the hook still runs on every keyboard close. It now remembers the last touch. If the close comes within 1 s of a touch inside the focused field, it treats the close as Chromium's suggestion menu. It keeps focus, then 50 ms later blurs and refocuses the field so Android raises the keyboard again; the caret is restored. A tap only counts once. Any other close calls Keyboard.dismiss() as before.
Why
Root cause: #32038 made this hook blur the focused field on every keyboard close, assuming the close was Back. But Chromium hides the keyboard itself when it opens its suggestion menu for a tapped autocorrected word. The menu is a focusable native popup (SuggestionsPopupWindow: setFocusable(true), INPUT_METHOD_NOT_NEEDED), and while it holds window focus the keyboard closes. The hook blurred at that moment.
The page can't observe Back or the native popup directly: the keyboard consumes Back, and Chromium sends the page no blur when a popup takes window focus. The one signal the page does have is that the menu close always follows a touch on the field, and Back doesn't. Alternatives I ruled out:
A native signal from the shell (activity window lost focus). Exact, but it needs a new bridge field and a phone app release. The page ships with the desktop, so this fix reaches users without either.
Only skip the blur, without reopening. The reporter tested this on device: the cursor stays, but the keyboard stays closed. Tapping near the word reopens the menu, so the word still can't be fixed.
Count a tap only when the field was focused before it. Breaks tapping the underlined word after Back, where that same tap focuses the field and opens the menu.
Trade-off: pressing Back within 1 s of tapping the field brings the keyboard back once. A second Back closes it, because a tap only counts once.
No capture from me: there's no Samsung device here, and the emulator images only have Gboard, which doesn't open this menu. The reporter's Galaxy S24+ recording of this mechanism (keep focus, then blur and refocus to bring the keyboard back) is in #36751. Kelvin or the reporter should check on a Samsung phone before merge.
To try (Samsung phone, Samsung Keyboard, page built from this branch): worktree /Users/kelvinamoaba/orca/workspaces/orca/samsung-autocorrect-focus-36747.
In a session's chat, type run the nlx tests so autocorrect turns nlx into an underlined next, then tap next: the menu shows, the keyboard comes back and the cursor stays in the word.
Vitest mobile/src/platform/keyboard-close-blur.web.test.ts: the two "keeps focus and reopens the keyboard" cases (field already focused, and field focused by the tap after Back) fail on main and pass here. A touch elsewhere, or a Back 5 s after touching the field, still blurs. iOS is still left alone.
oxlint, oxfmt, the changed-code quality gate, React Doctor changed-lines and the mobile test typecheck are clean on the changed files.
Not tested on a device (see Visual Proof).
I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Codex and Claude reviewed it. Fixed: a handled tap could excuse a second Back inside the same second. Rejected: requiring the field to be focused before the tap (it breaks tapping the word after Back), and dropping the reopen as ineffective while the menu is open (the reporter's device test shows the keyboard comes back).
Agent skill upstream boundary
Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.
Notes
Android page only (hostOs() === 'android'). iOS, desktop, native screens, SSH and folder workspaces are untouched. No wire change, so mixed phone and desktop versions keep working. The pointerdown listener does constant work per tap.
Checklist
This PR is small and focused
I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
Before/after screenshots or videos attached for UI changes, or N/A with reason
Self-reviewed for correctness, security, and performance
Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)
On Android, keyboard-close handling now records the most recent pointer target and time. After the keyboard closes, the code reopens a still-active field when a touch occurred within it during the previous 1,000 ms. It otherwise dismisses the keyboard. Tests cover autocorrect taps, touches elsewhere, and a delayed Back action.
Severity of issue fixed: Medium
Merge Risk: Minimal · up to 907ef
No merge-blocking defect was established. A caret-position assertion would strengthen the autocorrect tests.
Pre-merge checks: 5
Check name
Status
Explanation
Title check
The title clearly and concisely identifies the Android mobile fix for preserving the cursor and keyboard when tapping an autocorrected word.
Linked Issues check
Issue #36747 requires that tapping an autocorrected word on Android keeps the cursor at the tapped position, so the user can fix the word. The hook in mobile/src/platform/keyboard-close-blur.web.ts no…
Out of Scope Changes check
The diff changes two files, both in the Android-only platform hook area. The source change in keyboard-close-blur.web.ts implements #36747. The test file adds cases for that behavior. Its supporting e…
Docstring Coverage
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Description check
The pull request description is complete and relevant. It explains the user impact, implementation, rationale, linked issue, testing, scope, risks, and checklist status. It does not include visual att…
Full details: Linked Issues check
Explanation
Issue #36747 requires that tapping an autocorrected word on Android keeps the cursor at the tapped position, so the user can fix the word. The hook in mobile/src/platform/keyboard-close-blur.web.ts now records the last pointerdown target and time. On a keyboard close, if the focused HTMLElement contains that target and the touch was 1000 ms or less earlier, the hook keeps focus. It then runs blur() and focus() on the field after 50 ms, which reopens the keyboard. Any other close calls Keyboard.dismiss(), as before. The tap case covers the 'tricky part' in the issue, because any touch inside the field counts, including a tap directly after the last letter. The tests in keyboard-close-blur.web.test.ts cover both tap cases (field already focused, and field focused by the tap). They assert that focus is kept and that exactly one refocus session occurs. They also assert that a touch elsewhere or a Back 5 s after a field touch still ends focus. The tests do not assert caret position. Caret retention depends on browser behavior when an input is refocused. The PR reports a Samsung device recording in #36751, which I could not read, so device-level caret and keyboard behavior is not verified here. The PR documents an accepted trade-off: a Back within 1 s of a field tap reopens the keyboard once. This does not contradict #36747.
Full details: Out of Scope Changes check
Explanation
The diff changes two files, both in the Android-only platform hook area. The source change in keyboard-close-blur.web.ts implements #36747. The test file adds cases for that behavior. Its supporting edits are: the Android user agent fixture changes from Android 15 to Android 16 through a shared ANDROID constant, and fake timers are enabled and restored in beforeEach and afterEach. These edits support the new tests and do not change the outcome of the existing focus-ending test. No iOS, desktop, native screen, SSH, folder workspace, or wire-format code changed. One non-scope observation: the field check accepts any HTMLElement, including document.body when nothing is focused. A keyboard close with body active and a recent touch anywhere would skip Keyboard.dismiss(). Blurring body has no effect, so the practical impact appears small. This does not show an unrelated change.
Full details: Docstring Coverage
Explanation
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 2 files.
Full details: Description check
Explanation
The pull request description is complete and relevant. It explains the user impact, implementation, rationale, linked issue, testing, scope, risks, and checklist status. It does not include visual attachments and does not mark the Visual Proof section as N/A, but it clearly documents why device capture was unavailable and requests Samsung-device verification before merge.
Finishing Touches
Generate docstrings
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Assert the tapped caret position after the delayed reopen.
The autocorrect tests should set a non-terminal caret position and assert both selection endpoints after the blur/refocus. This checks the cursor-retention requirement instead of only checking focus.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.
Tested this on my Galaxy S24+ with Samsung Keyboard (built the 1.4.245 mobile page with this PR applied). Tapping an autocorrected word brings the keyboard back with the cursor where I tapped (3/3), and Back still closes the keyboard as expected. Thanks for landing it!
KELVIN_36947_SAMSUNG_TEST_2026-11-01.mp4
One small request about attribution: my PR #36751 implemented and tested the same 1-second touch window and 50 ms refocus approach used here. Since my PR was closed rather than merged, would you be open to crediting that implementation in this PR's description? I understand the final version includes some refinements.
I really enjoy using Orca and would be happy to keep contributing fixes for bugs I come across in the future. Thanks again!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
On Android, tapping a word that Samsung Keyboard autocorrected closed the keyboard, and the chat box lost its cursor. Now the cursor stays where you tapped and the keyboard comes back, so you can fix the word.
What Changed
mobile/src/platform/keyboard-close-blur.web.ts, Android page only): the hook still runs on every keyboard close. It now remembers the last touch. If the close comes within 1 s of a touch inside the focused field, it treats the close as Chromium's suggestion menu. It keeps focus, then 50 ms later blurs and refocuses the field so Android raises the keyboard again; the caret is restored. A tap only counts once. Any other close callsKeyboard.dismiss()as before.Why
Root cause: #32038 made this hook blur the focused field on every keyboard close, assuming the close was Back. But Chromium hides the keyboard itself when it opens its suggestion menu for a tapped autocorrected word. The menu is a focusable native popup (
SuggestionsPopupWindow:setFocusable(true),INPUT_METHOD_NOT_NEEDED), and while it holds window focus the keyboard closes. The hook blurred at that moment.The page can't observe Back or the native popup directly: the keyboard consumes Back, and Chromium sends the page no blur when a popup takes window focus. The one signal the page does have is that the menu close always follows a touch on the field, and Back doesn't. Alternatives I ruled out:
Trade-off: pressing Back within 1 s of tapping the field brings the keyboard back once. A second Back closes it, because a tap only counts once.
Linked Issue
Fixes #36747
Visual Proof
No capture from me: there's no Samsung device here, and the emulator images only have Gboard, which doesn't open this menu. The reporter's Galaxy S24+ recording of this mechanism (keep focus, then blur and refocus to bring the keyboard back) is in #36751. Kelvin or the reporter should check on a Samsung phone before merge.
To try (Samsung phone, Samsung Keyboard, page built from this branch): worktree
/Users/kelvinamoaba/orca/workspaces/orca/samsung-autocorrect-focus-36747.run the nlx testsso autocorrect turnsnlxinto an underlinednext, then tapnext: the menu shows, the keyboard comes back and the cursor stays in the word.Testing
Vitest
mobile/src/platform/keyboard-close-blur.web.test.ts: the two "keeps focus and reopens the keyboard" cases (field already focused, and field focused by the tap after Back) fail on main and pass here. A touch elsewhere, or a Back 5 s after touching the field, still blurs. iOS is still left alone.oxlint, oxfmt, the changed-code quality gate, React Doctor changed-lines and the mobile test typecheck are clean on the changed files.
Not tested on a device (see Visual Proof).
I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Codex and Claude reviewed it. Fixed: a handled tap could excuse a second Back inside the same second. Rejected: requiring the field to be focused before the tap (it breaks tapping the word after Back), and dropping the reopen as ineffective while the menu is open (the reporter's device test shows the keyboard comes back).
Agent skill upstream boundary
Notes
Android page only (
hostOs() === 'android'). iOS, desktop, native screens, SSH and folder workspaces are untouched. No wire change, so mixed phone and desktop versions keep working. The pointerdown listener does constant work per tap.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)