fix(@wterm/dom): don't leak first IME composition key to PTY#79
Open
vmxmy wants to merge 1 commit into
Open
Conversation
When IME composition starts, compositionstart fires AFTER the keydown that triggered it. Without checking isComposing / keyCode 229 / key === "Process", the first key (e.g. 'r' of pinyin) leaks into the PTY before compositionend delivers the committed text. Guard handleKeyDown with the three standard IME signals.
|
@vmxmy is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When using an IME (e.g. Chinese pinyin) inside a wterm-backed terminal, the
first key that triggers an IME composition is forwarded to the PTY as
a normal character — before
compositionstartfires and flipsInputHandler.composingtotrue.Concrete example with the Vite +
@wterm/ghosttyexample:typing pinyin for
如何, the PTY receivesr你何orr如何(a strayrahead of the committed text) instead of just
如何.This is presumably a contributor to #70 ("IME tentative input doesn't appear
all"), though that issue is also about IME window positioning.
Cause
InputHandler.handleKeyDownalready returns early whenthis.composingistrue, but the opening keydown of a composition dispatches before
compositionstart. Sothis.composingis stillfalsewhen the firstkeydown is handled, and the key is forwarded via
onData(seq).Fix
Skip a keydown whenever any of the three standard IME signals is set:
e.isComposing— WHATWG flag, true while an IME composition is inprogress and (in browsers that follow the spec) on the keydown that
opens one
e.keyCode === 229— long-standing IME signal supported by everymajor browser
e.key === "Process"— Chromium's.keyvalue for the composition-starting keydown
This matches the approach used by xterm.js, the Monaco editor,
CodeMirror 6, and Chromium's own native text inputs.
Testing
pnpm turbo run build --filter=vite...) andserve it pointing at any backend PTY.
nihao→ select你好).Before this patch, the PTY receives
n你好(straynfrom the keydownthat opens the composition). With the patch, the PTY receives only
你好.I'm happy to add a Playwright test that synthesises composition events
under
e2e/if you'd like — just say the word.