Skip to content

fix(mobile): keep the cursor and keyboard when tapping an autocorrected word on Android - #36947

Merged
AmoabaKelvin merged 1 commit into
mainfrom
samsung-autocorrect-focus-36747
Nov 1, 2026
Merged

AmoabaKelvin merged 1 commit into
mainfrom
samsung-autocorrect-focus-36747

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​49 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​48
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​41 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​36

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

  • 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:

  • Blur later, on the next touch outside the field, instead of on close. No timer, but the field would stay focused after Back, which fix(mobile): keep the android keyboard closed when you scroll or swipe the terminal #32038 relies on not happening. It also never brings the keyboard back, so tapping the word again just reopens the menu.
  • 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.

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.

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

  • 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)

@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

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: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely identifies the Android mobile fix for preserving the cursor and keyboard when tapping an autocorrected word.
Linked Issues check Passed 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 Passed 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 Passed 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 Passed 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.

Share

@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.

Nitpick comments: 1
mobile/src/platform/keyboard-close-blur.web.test.ts: 1

69-94: Trivial · Functional Correctness · Quick win

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.

Suggested fix
       field.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true }))
       TextInputState.focusTextInput(field)
+      field.value = 'word'
+      field.setSelectionRange(1, 1)
       shellReports(300)
       const focusSessions = vi.fn()
       field.addEventListener('focus', focusSessions)
@@
       expect(document.activeElement).toBe(field)
       expect(focusSessions).toHaveBeenCalledOnce()
+      expect(field.selectionStart).toBe(1)
+      expect(field.selectionEnd).toBe(1)

Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6124985b-d718-4886-9d8d-b2dc55c4c05e
Commits

Reviewing files that changed from the base of the PR and between 0054cd6 and 907ef92.

Files selected for processing: 2
  • mobile/src/platform/keyboard-close-blur.web.test.ts
  • mobile/src/platform/keyboard-close-blur.web.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

@Lenibi

Lenibi commented Nov 1, 2026

Copy link
Copy Markdown

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!

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.

[Bug]: Android (Samsung Keyboard): tapping an autocorrected word closes the keyboard and loses the cursor in the chat box

2 participants