Repository navigation
fix(mobile): focus Kimi terminal input after touch - #11865
Conversation
📝 WalkthroughWalkthroughThe session route now uses 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
Greptile SummaryThis PR fixes a remount regression where WKWebView's
Confidence Score: 5/5Safe to merge; the change is narrowly scoped to the terminal tap-focus path with no touch points on PTY I/O, session state, or non-terminal UI. The new hook correctly defers native focus past the WKWebView first-responder handoff, guards every deferred callback against stale handle/session/connection state, and cancels pending work on both navigation blur and lifecycle key changes. The notifyTerminalSurfaceTap signature change is minimal and the focusKeyboard flag cleanly separates touch from pointer-click semantics. Tests cover all lifecycle scenarios. Files Needing Attention: No files require special attention.
|
| Filename | Overview |
|---|---|
| mobile/src/terminal/use-terminal-live-input-focus.ts | New hook encapsulating deferred native-input focus for terminal taps; uses contextRef pattern for stale-closure safety, lifecycle cleanup via useLayoutEffect, and handle revalidation before firing the deferred callback. |
| mobile/src/terminal/terminal-webview-url-tap.ts | Adds focusKeyboard parameter to notifyTerminalSurfaceTap; touch taps now emit terminal-tap after mouse bytes, pointer clicks retain prior skip-tap-in-mouse-mode behaviour. |
| mobile/app/h/[hostId]/session/[worktreeId].tsx | Replaces inline focusLiveInput/handleTerminalTap callbacks with useTerminalLiveInputFocus hook; adds useFocusEffect cleanup to cancel pending focus when a pushed screen covers this route. |
| mobile/src/terminal/use-terminal-live-input-focus.test.ts | New comprehensive test file covering initial mount, remount, reconnect, stale-handle, and navigation-blur scenarios for the new hook; 8 test cases. |
Reviews (3): Last reviewed commit: "fix(mobile): reset deferred terminal foc..." | Re-trigger Greptile
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
mobile/src/terminal/terminal-webview-url-tap.ts (1)
208-252: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winAdd missing pointer-click coverage for
drag/anytracking modes.
isClickMouseTrackingMode(mode)already treats any non-nonemode as click-tracking, includingdragandany. Add a pointer-click test fordrag/anyalongside the existingvt200case so noterminal-tapis posted in those active modes.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d804e558-117a-4f78-979d-ab0bf1a3c2da
📒 Files selected for processing (10)
mobile/app/h/[hostId]/session/[worktreeId].tsxmobile/src/terminal/terminal-live-input-affordance.test.tsmobile/src/terminal/terminal-webview-mouse-click-drag-injected.tsmobile/src/terminal/terminal-webview-mouse-click.test.tsmobile/src/terminal/terminal-webview-scroll-routing.test.tsmobile/src/terminal/terminal-webview-tap-dispatch-injected.tsmobile/src/terminal/terminal-webview-tap-routing.test.tsmobile/src/terminal/terminal-webview-url-tap.tsmobile/src/terminal/use-terminal-live-input-focus.test.tsmobile/src/terminal/use-terminal-live-input-focus.ts
* fix(mobile): focus terminal input after TUI touch * fix(mobile): defer terminal focus after WebView taps * fix(mobile): reset deferred terminal focus on route blur
What changed
Kimi and other mouse-aware terminal TUIs consume a touch as terminal mouse input. Mobile now preserves those PTY mouse bytes and requests native live-input focus after the WebView finishes the touch gesture.
The focus request lives in a bounded lifecycle hook. It revalidates the active terminal, connection, client identity, and live-input mode before focusing; replaces earlier pending work; and clears on route blur, client replacement, disconnect, or unmount. The visible native keyboard control keeps its immediate focus behavior.
Links/files, selection dismissal, TUI mouse bytes, native chat, buffered input, reconnect gating, SSH/folder-workspace routing, and terminal hot paths are otherwise unchanged. The fix adds no polling or persistent listeners and keeps at most one replaceable timer per accepted terminal tap.
Root cause and user impact
The first implementation posted
terminal-tapafter the SGR click but called the hidden nativeTextInput.focus()synchronously from the WebView message callback. On a fresh route or host reconnect remount, WKWebView could still be completing the mouse-awaretouchend/first-responder handoff, so the native focus request was lost even though SGR press/release bytes reached the PTY.At the prior regressing head
fe16936c2b8be9dd0aa7d7bfffee629a0946ab97, initial input could work after focus was already established, but navigation/remount and full host reconnect/remount reproduced mouse bytes with dropped typed text. The continuously re-armed SGR fixture exposed that cold-remount failure.At final head
eb963fc419b4ad7086769f62fa55da592624c1ef, touch still reaches the TUI first, then native focus occurs after the gesture. A review-discovered P2 follow-up also clears deferred focus on retained-route blur and ties cleanup to the current client lifecycle identity, preventing stale delayed focus after navigation or client replacement.Mouse-aware external-pointer clicks keep sending only terminal mouse input. Plain external-pointer clicks retain their prior keyboard-focus behavior.
Review verdict
gpt-5.6-sol/xhighreviewer found the retained-route blur cleanup gap described above; it was fixed and covered by tests.CLEANfor exact final headeb963fc419b4ad7086769f62fa55da592624c1ef(tasktask_78b4fdeb5a43, dispatchctx_bdf09fba89ae).Automated validation
pnpm build:clipassed.pnpm build:electron-vitepassed.activity-portal-readiness-loop.react185.test.tsxpassed locally 4/4; failed CI jobs were rerun and the final PR check rollup is green.Native validation at the exact final head
Validated only through Orca's documented emulator surface on approved iPhone
50FD514C-96F6-446E-AC90-D07A24CAB3A0, using its stream at port 3100. The exact final-head runtime served on port 53901, and the dev client loaded the final-head Expo bundle from port 8128.MOCK_TUISGR1002/1006fixture visibly received mouse press/release bytes and submittedlivekimipass.mouse-terminal1-finalafter exact-runtime reconnection and client remount.nav-finalwith fresh SGR press/release bytes.nonmouse-finalanddirect-input-finalsubmissions without SGR mouse bytes.Final-head evidence
Initial mouse-aware submission:
Mouse-aware submission preserved after background/foreground:
Navigation-away/back submission after exact-bundle remount:
Non-mouse comparison after remount:
Validation limitations
kimibinary is installed. The closest shipped fixture is the continuously re-armedMOCK_TUISGR1002/1006lane.$electronskill is unavailable. Per repository instructions, no Computer Use, AppleScript, OS automation, or input injection was substituted.simctl, rawserve-sim, or emulator kill command was used.Residual native risk is limited to actual Kimi-specific behavior, a visibly rendered software-keyboard lifecycle, and injectable external-pointer behavior that the approved surface could not exercise. This PR remains open and was not merged.