Skip to content

fix(mobile): show live input caret and preserve selection edits - #31477

Merged
AmoabaKelvin merged 4 commits into
mainfrom
nwparker/mobile-live-caret
Oct 29, 2026
Merged

AmoabaKelvin merged 4 commits into
mainfrom
nwparker/mobile-live-caret

Conversation

@nwparker

@nwparker nwparker commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​161 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​159
Prod 12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​176 $\color{#cf222e}{\Huge{\mathbf{−}}}$​99 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​77

ELI5

Live input now shows the real text cursor. You can move into the middle of a command, delete a letter there and keep typing where the cursor is, and the terminal line stays in step with the field.

What Changed

  • Before: the terminal captured typing in an invisible 1×1 input and showed a separate text preview. The caret, selection and horizontal scrolling were hidden, and the accessory bar's Backspace/Delete always edited the end of the text (Delete did nothing at all).
  • After: the existing input is the visible field. Accessory Backspace/Delete edit at the field's caret or selection, read from the input when pressed, and put the caret back afterwards. The field mirror still sends the change to the PTY as erase + retype from the line end, so the PTY cursor never moves.
  • Hardware Left/Home (and Right/End unless the caret is already at the field end) move only the field caret while it holds text, like Backspace/Delete already did. Right/End at the end still reach the shell, so accepting a fish/zsh autosuggestion keeps working. On Android the key binding used to catch these keys and send them straight to the PTY; plain caret keys now go through the same decision.
  • The dictation/upload status covers the field instead of adding a row, so the dock, and with it the PTY size, stays the same when dictation starts or stops.

Why

Fixes the hidden caret and end-only deletion in #27829. The session screen only renders in the web shell (RN-Web in the app's WebView), so the live input ref is the DOM input and its selectionStart/selectionEnd are the caret at the moment of the press. That replaced an earlier version of this PR that tracked selection-change events and paired them with text events, which needed extra state and guards for out-of-order reports.

Linked Issue

Fixes #27829

Visual Proof

Caret (from Neil's iOS simulator run): before, no caret at offset 3; after, the caret sits between c and d.

Before: hidden caret at offset 3 After: visible caret at offset 3
Before: abcdef with no caret at selection 3 After: blue caret between c and d

After accessory Delete and typing X:

After editing: abcXef with matching field and terminal sink

Command dock in iOS 27 Safari (real WebKit), main vs this branch, idle and while dictating. The dock is 78 px tall in both states on this branch.

main this branch
Idle dock-main-idle.png dock-branch-idle.png
Dictating dock-main-dictating.png dock-branch-dictating.png

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

On a real target, I ran the production commit hook in a page bundle built from this branch, with an in-memory terminal sink:

  • iOS 27 simulator Safari (WebKit), hardware-keyboard keys and real taps:
    • abcdef, three Left presses, accessory Delete, type X: the field and terminal both read abcXef.
    • Select cX, accessory Backspace, type Y: both read abYef.
    • Paste a🙂b👍🏽c, then arrows and accessory keys around the surrogate pairs: each edit removes one code point and the bytes match.
    • Right at the end of git ch sends ESC[C. Left, Left, Right stays local.
  • Android emulator, Chrome with Gboard:
    • Compose abc, tap the caret into the word, accessory Delete, type x: both read axc.
    • Compose, accessory Backspace, type: correct.
  • Automated:
    • 224 focused mobile tests, including caret maths, surrogate pairs, selection replace, raw smart punctuation and the caret-key decisions.
    • 13 rendered live-input browser checks, 7 rendered command-dock checks, and the RPC recording goldens.
  • Not covered: a physical iPhone's spacebar-trackpad drag, and a paired host.

AI Disclosure

Review

Two reviewers (Codex and Claude) ran four rounds. Fixed from review:

  • Hardware arrow keys moved the PTY cursor away from the mirror.
  • Right/End at the field end stopped accepting autosuggestions.
  • On Android, the key binding caught caret keys before that decision.
  • The status row changed the dock height, so the PTY resized on dictation start/stop.
  • A test only exercised the native writer, which never runs on a phone.

Rejected: "accessory Delete corrupts an active Android composition". It came from a synthetic CDP composition, and Gboard on the emulator does not reproduce it (see Testing). Main's Backspace already writes the field the same way.

Known gaps, unchanged from main: the accessory-bar arrows still send to the PTY in the middle of a session. After a shell autosuggestion is accepted with Right/End, the field doesn't know about the accepted text, so a later Backspace from the field erases from the suggestion's end.

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

Mobile-only, client-side. No RPC, host-version or workspace-kind change, so mixed phone/desktop versions are unaffected. Ported and adapted community PR #28294 by @Kyino-Pan; the commit includes Co-authored-by: Kyino <[email protected]>.

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 Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9c5892b7-34cd-40e8-a149-41032e138006
📥 Commits

Reviewing files that changed from the base of the PR and between 84af8ef and c855dd292be8bb3a5bb0d12bfc17317276e3f499.

📒 Files selected for processing: 15
  • config/scripts/mobile-web-app-live-input-probe-route.mjs
  • config/scripts/mobile-web-app-terminal-live-input-render.test.mjs
  • mobile/src/session/MobileSessionCommandDock.tsx
  • mobile/src/session/MobileTerminalLiveInputStatus.tsx
  • mobile/src/session/mobile-session-command-input-styles.ts
  • mobile/src/session/use-mobile-session-terminal-runtime.ts
  • mobile/src/terminal/terminal-live-input-text-write.test.ts
  • mobile/src/terminal/terminal-live-input-text-write.ts
  • mobile/src/terminal/terminal-live-input-text-write.web.ts
  • mobile/src/terminal/terminal-live-text-commit.test.ts
  • mobile/src/terminal/terminal-live-text-commit.ts
  • mobile/src/terminal/use-terminal-live-accessory-input-commit.test.ts
  • mobile/src/terminal/use-terminal-live-accessory-input-commit.ts
  • mobile/src/terminal/use-terminal-live-input-commit.test.ts
  • mobile/src/terminal/use-terminal-live-input-commit.ts

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

Walkthrough

The live-input field is now visible and editable, and it reports native selection changes. Accessory backspace and delete operations use the field’s text and selection, then update the caret and mirror normalized text. Native and web text writers can restore a supplied selection. The session runtime and probe pass selection changes to the commit hook. Tests cover caret-aware edits, selection event ordering, and field rendering.

Fixed issue severity: <fixed_issue_severity>Low</fixed_issue_severity>

Priority: Normal

Merge Risk: Minimal · up to c855d

The reviewed selection and accessory-edit paths have no identified issue requiring a fix before merge. Physical-device validation remains follow-up work.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary changes: showing the mobile live-input caret and preserving selection-based edits.
Linked Issues check Passed The PR meets the coding requirements in [#27829]. MobileSessionCommandDock now renders the live input as an editable, visible TextInput, so native caret, selection, and scrolling remain available.…
Out of Scope Changes check Passed The changes stay within [#27829]. The modified production files implement the visible live input, selection tracking, accessory editing, native/Web text writes, and runtime wiring. The modified tests …
Description check Passed The description follows the template well. It has an ELI5, a What Changed section with before/after, a Why section that explains the mechanism and the rejected earlier approach, a Linked Issue (Fixes …
Full details: Linked Issues check

Explanation

The PR meets the coding requirements in [#27829]. MobileSessionCommandDock now renders the live input as an editable, visible TextInput, so native caret, selection, and scrolling remain available. onSelectionChange records UTF-16 selection state without sending terminal controls. Accessory Backspace/Delete uses the matching selection, preserves the resulting caret, updates the field, and mirrors the normalized edit. The hook suppresses deletion when text and selection snapshots do not match. Focused unit and rendered browser tests cover middle deletion, selection replacement, surrogate pairs, event ordering, and subsequent insertion.

Full details: Out of Scope Changes check

Explanation

The changes stay within [#27829]. The modified production files implement the visible live input, selection tracking, accessory editing, native/Web text writes, and runtime wiring. The modified tests cover these behaviors. The status and style changes support the same input-row replacement. No unrelated protocol, remote-host, workspace, or desktop behavior changes are introduced.

Full details: Description check

Explanation

The description follows the template well. It has an ELI5, a What Changed section with before/after, a Why section that explains the mechanism and the rejected earlier approach, a Linked Issue (Fixes #27829), Visual Proof with before/after images and a dock comparison, a detailed Testing section with platforms (iOS 27 simulator Safari, Android emulator Chrome/Gboard) and automated test counts, a Review section, an Agent skill upstream boundary checkbox, Notes, and a Checklist. The AI Disclosure section is empty, which is the one gap, and the template says it applies to non-StablyAI contributors. The checklist items are all checked. Overall, the description is mostly complete.

✨ 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

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

@nwparker
nwparker force-pushed the nwparker/mobile-live-caret branch from c855dd2 to dca762a Compare October 21, 2026 08:52
@nwparker
nwparker changed the base branch from main to nwparker/mobile-p3-prompt-tap October 21, 2026 08:52
@AmoabaKelvin
AmoabaKelvin changed the base branch from nwparker/mobile-p3-prompt-tap to main October 28, 2026 17:32
@AmoabaKelvin
AmoabaKelvin force-pushed the nwparker/mobile-live-caret branch 2 times, most recently from 41437c1 to 752ed93 Compare October 28, 2026 22:55
@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The changes since the last review appear safe to merge.

Summary

The PR makes the live terminal field visible and adds caret-aware accessory edits.

  • The mobile terminal dock shows the live input field and its caret.
  • Accessory edits and caret keys follow the field cursor while keeping the terminal line in sync.
  • Dictation and upload status appears over the input without changing dock height.

Reviews (4) · Last reviewed commit: "chore(mobile): allowlist the live input ..." · Reviewed by Greptile

nwparker and others added 3 commits October 29, 2026 00:58
Display the existing input directly so its native caret shows. Accessory
Backspace/Delete edit at the field's caret, read from the input when pressed,
so edits that keep the caret (IME composition) still delete, and the caret is
restored for subsequent typing.
Port and adapt community PR #28294 to the current command dock.

Co-authored-by: Kyino <[email protected]>
Hardware Left/Right/Home/End moved both the visible field caret and the
PTY cursor, so the mirror erased at the wrong place. With field text they
now move only the field caret, like Backspace and Delete; Right/End at the
field end still reach the PTY so shells can accept an autosuggestion. On
Android the key binding lets plain caret keys through to that decision
instead of sending them to the PTY. The dictation and upload status covers
the field instead of adding a row, so starting or stopping either no longer
resizes the terminal.
@AmoabaKelvin
AmoabaKelvin force-pushed the nwparker/mobile-live-caret branch from 12df646 to ac9b36a Compare October 29, 2026 01:01
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]: iOS Live input hides the local caret when moving the insertion point

2 participants