Skip to content

fix(web): synchronize iOS keyboard edits (#830) - #839

Open
HadrienKerlero wants to merge 2 commits into
Ark0N:masterfrom
HadrienKerlero:fix/830-ios-keyboard
Open

HadrienKerlero wants to merge 2 commits into
Ark0N:masterfrom
HadrienKerlero:fix/830-ios-keyboard

Conversation

@HadrienKerlero

Copy link
Copy Markdown

Fixes #830

Keep xterm's helper textarea in sync with native iOS editing instead of supplementing xterm's first-character keypress output.

Changes

  • Give iOS WebKit one native-input owner per main/split/grid terminal. Other platforms retain the existing keyCode-229 recovery.
  • Reconcile suggestion insertion, word/phrase replacement, keyless accelerated deletion, dictation and composition as one ordered edit transaction; send individual DEL operations before replacement text.
  • Preserve ordinary spaces with white-space: pre. Keep dictated line breaks editable in the native field but project them to spaces, as requested by the reporter; only explicit Enter submits.
  • Show the native trackpad caret with a visual marker, without injecting arrows into the receiving CLI. Local-echo geometry comes from the overlay's actual layout.
  • Capture session destinations and reserve existing delayed Enter/paste operations in a per-session FIFO. Reset native ownership at toolbar/programmatic-input boundaries, including background insertion into a live unfocused pane.
  • Remove complete Unicode code points from local echo without changing its existing UTF-16 offset bookkeeping.

Clean-code review

Device acceptance

The reporter tested the standalone probe and then the integrated isolated beta on their iPhone and confirmed the remaining keyboard features work. Copy/paste feature work was explicitly excluded; existing Codeman clipboard features are preserved.

The browser replays preserve the logged iOS event order, multi-character key values, first-letter charCode, and composed: true. They are regression coverage, not a claim that Chromium emulates the iOS keyboard.

Delivery boundary

The FIFO guarantees session destination and enqueue ordering through Codeman's existing reliable transport. It does not introduce new ACK/completion guarantees or redesign reconnect, wake-buffering, or named-key transport behavior.

Verification on current upstream master

  • npm test: 757 test files passed, 17,284 tests passed; 1 file / 13 tests skipped by the repository's existing conditions.
  • Browser input/IME/split/voice suites: 5 files, 55 tests passed, including 23 iOS integration cases.
  • Overlay package regression suites: 3 files, 165 tests passed.
  • npm run build, typecheck, lint, format:check, check:frontend-syntax, check:frontend-dead, check:browser-excludes, check:public-assets, and check:lockfile: passed.
  • Codeman's pre-commit formatting hook passed. The branch is based on current upstream master (e99b42c3), not the reporter's modified installation.

Keep one native-input owner per iOS terminal and reconcile keyboard edits without duplicate producers.
Preserve session-bound input ordering, local-echo Unicode deletion, and visual caret geometry.
Cover device event sequences and lifecycle handoffs; remove obsolete helpers and source-text-only regression tests.

Fixes Ark0N#830
@Ark0N

Ark0N commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thank you for this, and for the device testing with the reporter. The PR gives each terminal pane on iOS a native-input owner, so suggestions, phrase replacement, dictation and held delete reach the PTY as one ordered edit. It also adds a per-session FIFO that keeps delayed Enter and paste writes with the session they were typed for. The gate passes here (757 files, 17,284 tests), as do the new iOS browser suite and the overlay package. A few things need to change before merge:

  1. Slash-command keys now submit the unsent draft (src/web/public/keyboard-accessory.js:1350). sendCommand() passes flushEcho: true, so with local echo on (every phone, Android too), a draft hel followed by a /compact tap goes out as the prompt hel/compact and the command never runs. On master the command went to an empty composer and the draft stayed in the overlay. Please drop flushEcho there (keep the plain _prepareInput so the iOS owner still settles) and change the command case in test/terminal-input-fifo.test.ts:671 to expect only /help then \r. The flush before Esc, Opt+Enter, Tab and the arrows matches the typed path, so that part can stay.

  2. Some out-of-gate tests still stub the old send path. test/shift-enter-keypress.browser.test.ts fails 2 of 5: pressMain() (line 111) stubs _sendInputAsync and uses a probe session that is not in app.sessions, and _enqueueInput now drops that session's input. The nightly browser suite is green on master, so this would turn it red. test/mobile/keyboard.test.ts fails 7 more cases than master for the same reason (local-echo typing and the six one-shot Ctrl shell-bar cases). With the stubs retargeted to _enqueueReliableInput and the probe session added to app.sessions, shift-enter passes 5/5 and the mobile file is back to master's own failures. Please commit those harness updates, as you already did for terminal-keycode229-recovery.browser.test.ts.

  3. Please keep the fix(terminal): Shift+Enter no longer submits after inserting a newline #520 guard in the gate. test/shift-enter-keypress-swallowed.test.ts was the only npm test check that the Shift/Ctrl+Enter gate swallows keypress as well as keydown. Restore it with a pattern that accepts your iOS clause: match the ev.key === 'Enter' && (ev.shiftKey || ev.ctrlKey) prefix, and keep the check that the condition never tests ev.type. The browser test header (lines 17-18) still points at it.

  4. The overlay lost its prompt fallback (packages/xterm-zerolag-input/src/zerolag-input-addon.ts:643). else if (!this._lastPromptPos) became else, so the overlay now hides whenever the finder returns null instead of painting at the last known prompt. The OpenCode finder returns null whenever the cursor row has no ┃, so on every touch device, unsent OpenCode text blinks out during redraws. Please keep the fallback (the anchor can still come from that layout), or explain why it has to go and confirm OpenCode typing on an Android device.

  5. The new xterm privates need pinning. terminal-ios-native-input.js requires _inputEvent, _handleTextAreaBlur, _finalizeComposition and _compositionView. If an xterm upgrade renames one, create() returns null, iOS gets neither the owner nor the recovery, and iPhone keyboard: tapping a suggestion only sends its first letter, and hold-delete never goes word by word #830 comes back with no signal. Add them to the shipped-bundle name list and the version message in test/xterm-private-api.test.ts (around line 72).

  6. Docs: src/web/CLAUDE.md:81 still says the composer delivers through _sendInputAsync. The per-session FIFO belongs in docs/architecture-invariants.md under "Input delivery and WS resilience" (gaps order enqueueing, not ACKs; ids missing from app.sessions are dropped; delete clears the FIFO). docs/ios-native-input.md:20 points at IOS_DIAG.md, which is not in this repository, so either link the sequence in iPhone keyboard: tapping a suggestion only sends its first letter, and hold-delete never goes word by word #830 or drop the sentence.

Push the fixes to this branch and the PR goes back into review.

Keep the unsent draft out of slash-command keys; settle the iOS owner without flushing local echo.
Restore the overlay last-prompt fallback and the Ark0N#520 Shift/Ctrl+Enter gate guard.
Pin the xterm privates the iOS owner needs; retarget browser/mobile harnesses to the session FIFO edge.
Document the session FIFO invariants and link Ark0N#830 for the device sequences.
@HadrienKerlero

Copy link
Copy Markdown
Author

Thanks for the thorough review. All six points are addressed in 89d6a9e on this branch.

  1. Slash commands keep the draft. sendCommand() now calls the plain _prepareInput(undefined, 'accessory-command'), so the iOS owner still settles but local echo is not flushed. The command case left the shared producer table in test/terminal-input-fifo.test.ts and became its own test: with echo on, the wire carries only /help then \r, and hel stays in the overlay. With echo off, hel had already been typed into the PTY, as on master. The flush before Esc, Opt+Enter, Tab and the arrows is unchanged.
  2. Out-of-gate harnesses. test/shift-enter-keypress.browser.test.ts: pressMain() stubs _enqueueReliableInput, registers the probe session in app.sessions and removes it afterwards, and clears only that id from the _pendingInput map instead of overwriting the map with ''. Result: 5/5. test/mobile/keyboard.test.ts: all ten send stubs now target _enqueueReliableInput (the probe sessions there were already registered). Result: 5 failures, a subset of master's own 6 measured on e99b42c3 in the same run. The extra codex write-through failure passes now.
  3. fix(terminal): Shift+Enter no longer submits after inserting a newline #520 guard restored in the gate as test/shift-enter-keypress-swallowed.test.ts. It matches the if (ev.key === 'Enter' && (ev.shiftKey || ev.ctrlKey)…) { gate in both terminal-ui.js and terminal-tile.js, accepts the trailing iOS clause, and fails if that gate's condition tests ev.type. The browser test header points at it again.
  4. Overlay prompt fallback restored (else if (!this._lastPromptPos)). The anchor still comes from the renderer layout, so while the finder briefly returns null, the overlay and the iOS caret both stay at the last known prompt. The anchor test that expected null now asserts that the overlay stays visible at the same anchor through a prompt-less redraw.
  5. xterm privates pinned. _inputEvent, _handleTextAreaBlur, _finalizeComposition and _compositionView are in the shipped-bundle name list of test/xterm-private-api.test.ts. They are also named in its version message and failure message, along with what breaks if they go missing.
  6. Docs. src/web/CLAUDE.md now describes Compose delivery through the session FIFO (_enqueueInput / _sendBracketedPaste()). docs/architecture-invariants.md has a Session FIFO paragraph under "Input delivery and WS resilience": gaps order enqueueing, not ACKs; ids missing from app.sessions are dropped; _cleanupSessionData() clears the FIFO and its gap timer. docs/ios-native-input.md now links the logged sequences in iPhone keyboard: tapping a suggestion only sends its first letter, and hold-delete never goes word by word #830 instead of IOS_DIAG.md.

Verification on this branch:

  • npm test: 758 files passed, 17,286 tests passed (1 file / 13 tests skipped by existing conditions).
  • Browser suites (ios-native-input, terminal-keycode229-recovery, shift-enter-keypress, split-pane-terminal, voice-input): 5 files, 52 tests passed.
  • test/mobile/keyboard.test.ts: 48 passed, 5 failed; the 5 are among master's own 6 failures (e99b42c3, same machine, same run).
  • Overlay package zerolag-input-addon.test.ts: 94 passed.
  • npm run build, typecheck, lint, format:check, check:frontend-syntax, check:frontend-dead, check:browser-excludes, check:public-assets, check:lockfile: passed.

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.

iPhone keyboard: tapping a suggestion only sends its first letter, and hold-delete never goes word by word

2 participants