Skip to content

[Bugfix #1886] Stop dropping repeated hardware keys on touch devices - #1888

Merged
waleedkadous merged 3 commits into
mainfrom
builder/bugfix-1886-touch-dedup
Nov 9, 2026
Merged

waleedkadous merged 3 commits into
mainfrom
builder/bugfix-1886-touch-dedup

Conversation

@waleedkadous

@waleedkadous waleedkadous commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On a touch device (an iPad with a hardware keyboard, for example), the dashboard terminal dropped repeated keys. Holding Backspace or an arrow key deleted or moved a fraction of what the user expected, and fast double letters lost a letter (hello arrived as helo). Now every key arrives.

Fixes #1886

Root Cause

The exact-duplicate guard from #517 drops any onData payload equal to the previous one within 150 ms. #517 made it always on for (pointer: coarse), against late duplicates from xterm's multiple textarea emitters (keydown, compositionend, input event) double-firing on soft-keyboard input.

Since PR #1884 (the fix for issue #1883, mobile autocomplete duplicating text), the IME bridge owns soft-keyboard text on touch devices:

  • composition and input events never reach xterm;
  • keydown 229 is the bridge's;
  • the bridge's own edits bypass the guard.

So on a touch device the always-on arm only ever saw hardware keys, paste and terminal replies, and the only thing it caught was real repeats. The #517 comment's tradeoff note ("default keyboard repeat rates (>250ms) are above the 150ms window") confused the initial repeat delay with the repeat interval, which is ~30–80 ms.

Fix

apps/web/src/components/Terminal.tsx: the guard is composition-window only. The composition arm (during a composition, and up to 150 ms after compositionend) is unchanged, so desktop CJK input and the #517 doubled period keep their protection on desktop.

On a touch device this means the guard is off. The bridge's capture-phase shield stops composition events before the guard's listeners see them, so the composition window never opens there. That was already true since PR #1884; the touch arm was the only part still active. The comment now records both.

Test Plan

  • Failing-first, jsdom (Terminal.ime-dedup.test.tsx, on a touch device): fast double letters (h e l l o), a held Backspace and arrow, and Enter twice. All three fail on main. They replace the Mobile: duplicate letters and extra periods when typing #517 touch tests that pinned dropping the second l of "hell". The Mobile: duplicate letters and extra periods when typing #517 "extra period" test moved to the composition suite, where it still passes. The touch "same character after 150 ms" test was removed: with no composition it passed whatever the timing, so it pinned nothing.
  • Failing-first, real browser (playwright/ime-replace.spec.ts): real hardware keydowns on an emulated touch device. hello, three auto-repeat Backspaces, then p!. On main the line arrived as help! (the second l and two of three repeats dropped). With the fix it is hep!, and the frames are exactly one per key, which also shows the IME bridge never double-sends a hardware key.
  • apps/web: 582 unit tests pass; tsc --noEmit is clean; Playwright 12/12 (36/36 under --repeat-each=3).
  • Manual on an iPad with a hardware keyboard (owner): hold Backspace in a shell line, and type hello quickly.

Not covered here, because it needs a real device: whether an iOS soft keyboard ever sends letters as real keydowns whose default insert xterm's cancel doesn't stop. If it does, the bridge would see that insert too. The guard's touch arm could not have caught that case either, because bridge edits bypass it.

…ices

The #517 duplicate guard was always on for (pointer: coarse), against xterm's textarea emitters double-firing on soft-keyboard input. Since the IME bridge (#1883) owns soft-keyboard text on touch devices, keeping it away from those emitters, the guard only saw hardware keys, paste and terminal replies there. It dropped real repeats: a held key's auto-repeat and fast double letters on an iPad keyboard.

The guard is now composition-window only, and the composition arm is unchanged. Failing-first tests: jsdom (double letters, held Backspace/arrow, Enter twice on a touch device) and Playwright (real hardware keydowns on an emulated touch device; on main "hello"+3 Backspace+"p!" arrived as "help!").
@waleedkadous

Copy link
Copy Markdown
Contributor Author

Tight fix, thank you. The guard is now composition-window only, the desktop CJK arm is untouched, and the failing-first tests cover held Backspace, arrows, double letters and Enter twice on touch, plus real hardware keydowns in Chromium. The comment correctly records why the old tradeoff note was wrong (initial repeat delay versus repeat interval). Nothing to change. CI is still running; merge waits on green and the owner's word.

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.

Touch-device duplicate guard drops repeated hardware keys (iPad key repeat, fast double letters)

1 participant