Skip to content

fix(mobile): keep terminal caret visible without focus - #10101

Merged
nwparker merged 1 commit into
stablyai:mainfrom
bbingz:fix/mobile-visible-caret-8313
Jul 24, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
bbingz:fix/mobile-visible-caret-8313

Conversation

@bbingz

@bbingz bbingz commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

fix(mobile): keep terminal caret visible without focus

Summary

On the mobile terminal, the text caret disappeared because xterm is permanently "inactive" while the native keyboard input owns focus; this restores a visible caret.

ELI5

When typing in the phone terminal, the little blinking cursor was invisible, so you couldn't tell where your text would go. This makes the cursor show up again.

Root cause & fix

On mobile, the native TextInput owns keyboard focus, so xterm is always in its "inactive" state. With cursorInactiveStyle: 'none', the caret was hidden in that state — permanently, on mobile. The fix changes cursorInactiveStyle from 'none' to 'bar' in terminal-webview-html.ts, keeping the caret visible while xterm still honors application-driven cursor hiding (DECTCEM), so full-screen TUIs that intentionally hide the cursor are unaffected.

Evidence

Validated & rebased onto latest main during a bug-bash triage on 2026-07-23.

  • Files changed: mobile/src/terminal/terminal-webview-html.ts (fix) and mobile/src/terminal/terminal-webview-init-surface.test.ts (test). Clean rebase onto origin/main.
  • On branch (fix present): 1 passed test file, 2 passed tests.
  • New test keeps xterm's inactive cursor visible across replacement surfaces covers all 3 init surfaces (desktop, phone-resize, phone-scrollback).
  • Reverting only the fix to origin/main (keeping the test) fails, proving the test captures the bug:
Tests  1 failed | 1 passed (2)
expected ... to match object { cursorStyle: 'bar', cursorInactiveStyle: 'bar' }
- Expected: "cursorInactiveStyle": "bar"
+ Received: "cursorInactiveStyle": "none"
  • Lint clean: oxlint src/terminal/terminal-webview-html.ts exits 0.

Trade-offs

None — pure fix.

Regression risk

Zero-regression: only the mobile WebView cursorInactiveStyle value changes, affecting caret style solely in the inactive state. Application-driven cursor hiding (DECTCEM) is independent and still honored, so TUIs that hide the cursor render identically. Non-affected paths are byte-identical, and the passing test proves the intended behavior across all three replacement surfaces. This is mobile-only; no Electron/desktop path changes.


Credit to @bbingz for the original fix. Validated, rebased, and (where applicable) hardened via automated bug-bash review; original fix design preserved.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The terminal WebView now configures both active and inactive xterm cursors with a visible bar style. The initialization-surface tests capture terminal constructor options, clean up registered window listeners after each test, and verify that repeated surface replacement messages create terminals with both cursor styles set to bar.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The change addresses #8313 by keeping the mobile terminal caret visible while preserving xterm-driven cursor hiding.
Out of Scope Changes check ✅ Passed The added test cleanup and option plumbing directly support the cursor-visibility fix and do not introduce unrelated behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed Clearly describes the main change: keeping the mobile terminal caret visible when unfocused.
Description check ✅ Passed Detailed and mostly complete: it covers summary, root cause, evidence, testing, trade-offs, and regression risk.

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.

@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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d3ef89a8-73bc-4f79-b6fc-812cc99b7853

📥 Commits

Reviewing files that changed from the base of the PR and between c445f26 and 2c28633662c76d8a1c887c56cf82acbf330d77b9.

📒 Files selected for processing (2)
  • mobile/src/terminal/terminal-webview-html.ts
  • mobile/src/terminal/terminal-webview-init-surface.test.ts

Comment on lines +91 to +110
let registeredWindowListeners: RegisteredWindowListener[]
let terminalOptions: TerminalOptions[]
let terminals: TerminalStub[]
let writeCallbacks: Array<() => void>

beforeEach(() => {
animationFrames = []
registeredWindowListeners = []
terminalOptions = []
terminals = []
writeCallbacks = []
const addWindowEventListener = window.addEventListener.bind(window)
vi.spyOn(window, 'addEventListener').mockImplementation(((
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions
) => {
registeredWindowListeners.push({ type, listener, options })
addWindowEventListener(type, listener, options)
}) as typeof window.addEventListener)

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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Clean up document listeners between tests.

XTERM_HTML registers a message handler on document as well as window (Lines 1862-1864), but this harness only records and removes window listeners. Later tests that dispatch document-level messages can invoke stale IIFE handlers and leak prior terminals. Track both targets and remove both in afterEach.

Also applies to: 133-138

@nwparker
nwparker force-pushed the fix/mobile-visible-caret-8313 branch from 2c28633 to 3828a09 Compare July 23, 2026 11:49
@nwparker
nwparker merged commit 2cf41ab into stablyai:main Jul 24, 2026
@nwparker

Copy link
Copy Markdown
Contributor

Thanks so much for this, @bbingz — keep terminal caret visible without focus. Reviewed, rebased on latest main, and merged. Really appreciate the contribution! 🙏

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.

2 participants