Skip to content

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

Open

Description

@HadrienKerlero

On my iPhone the keyboard suggestions don't work in the terminal. When I tap one, only its first letter shows up. Holding delete is broken too: it never switches to deleting word by word.

Setup: iPhone on iOS 26.5.2, Safari (not added to the home screen), Codeman 1.51.0.
I saw it in an OMP session, but from what I found it shouldn't depend on the session type.

What happens

What I do on the iPhone keyboard What I get in Codeman
type hel, tap the suggestion hello hell
type hello, space, tap a next-word suggestion (inspection) hello i
type hello without a space, tap a next-word suggestion only a space
hold delete it deletes letter by letter and never goes word by word

Every time, only the first character of what the keyboard inserts gets through.

What I tested

I put together a small test page that loads the same xterm and keycode229 recovery scripts as Codeman. It isn't connected to any session, and it logs every key/input event on xterm's hidden textarea along with what xterm emits in onData. I ran the cases above on the phone with it.

When I tap a suggestion, iOS sends one key event that carries the whole text, then an insertText with the same text:

8127  keydown     key="lo" code=Unidentified keyCode=76      textarea=""
8132  keypress    key="lo" charCode=108                      textarea=""
8133    onData "l"                                           <- only the first letter
8141  beforeinput inputType=insertText data="lo" composed=true
8143  input       inputType=insertText data="lo" composed=true  textarea="lo"

That was hel + the hello suggestion, so iOS only sends the missing part (lo). xterm sends the first letter from the keypress (String.fromCharCode(charCode)) and then ignores the input. In 6.0.0 _inputEvent only forwards insertText when !ev.composed || !this._keyDownSeen, and iOS sets composed=true right after a keydown. The keydown on its own does nothing either, because evaluateKeyboardEvent only accepts a key of length 1. The keycode229 recovery sees the same input, but xterm already emitted something for that keystroke (the l), so it backs off. The rest of the text is lost.

The other cases look the same: hello + space + the gives onData "t", and the whole-phrase suggestion Hello World gives onData "H".

The underlying problem is that the hidden textarea never contains what I typed. Normal letters are handled by xterm on keydown and then cancelled (preventDefault), so they never reach the textarea, and only spaces end up in it. iOS predicts from its own memory of what I typed, but its edits land in a box that doesn't hold that text. That's also why a suggestion meant to replace a word (I typed helloworl and tapped Hello World) comes through as a plain insertText and not insertReplacementText: there's nothing in the box to replace. The session ended up with helloworlH.

Hold delete: each repeat is a normal keydown Backspace, and xterm turns it into one DEL. When iOS switches to word by word, it keeps sending one Backspace keydown per repeat and adds a burst of deleteContentBackward input events with no key (I counted 14 in about 0.4 s). xterm ignores those because _inputEvent only handles insertText, so the session keeps getting one DEL per repeat.

I never saw keyCode=229, any composition events, insertReplacementText or deleteWordBackward. isComposing was always false.

A desktop simulation (headless Chromium posing as an iPhone) missed part of this. It gave hello iinspection instead of hello i, because the synthetic events didn't have composed: true. A test for this needs to replay the events exactly, including that flag.

The xterm side looks like a bug for any iOS keyboard, so it may be worth reporting there too. Related: xtermjs/xterm.js#6284 (macOS Safari 26.2, replacements dropped) and xtermjs/xterm.js#5704 (insertReplacementText, not merged).

Activity

  1. Ark0N commented on Nov 17, 2026

    @Ark0N
    Owner

    Thanks for the detailed trace. It made this quick to confirm.

    The code confirms it, and I replayed the event sequence you logged. That was in headless Chromium rather than on an iPhone, against the vendor/xterm.min.js and terminal-keycode229-recovery.js that 1.51.0 ships, with composed: true on the input events. hel plus a lo suggestion comes out as hell, a Hello World suggestion as H, and three Backspace keydowns followed by 14 deleteContentBackward events send exactly three DELs.

    The cause is the one you describe:

    • xterm 6.0.0 sends the first character from the keypress (String.fromCharCode in _keyPress), because evaluateKeyboardEvent only takes a one-character key on keydown. _inputEvent then refuses the insertText. There is one more guard than the composed check: _inputEvent also returns early while _keyPressHandled is set, and that flag stays set from the keypress until keyup. In my replay (keyup after the input) the text was refused even with composed: false, so a fix cannot rely on the composed flag alone.
    • Codeman's recovery in src/web/public/terminal-keycode229-recovery.js is active on an iPhone (it is created whenever (pointer: coarse) matches), but it stands down because xterm emitted the first letter after the keydown snapshot (the canonicalCount > candidate.snapshot check). Its edit-based diff replaces xterm's _handleAnyTextareaChanges, which xterm only calls from CompositionHelper.keydown for keyCode 229, so it never runs here. Its input listener also ignores every inputType except insertText, so nothing in the terminal path reacts to deleteContentBackward.

    Your #815 branch is not involved: that PR does not touch the key handler, onData or the recovery module.

    For now, Compose in the accessory bar is the way to type with suggestions on an iPhone, as you found.

    A PR is welcome. A few things matter for one:

  2. added a commit that references this issue on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions