Repository navigation
Send a committed IME composition before the custom key handler sees the key - #6330
Open
wonjangcloud9 wants to merge 1 commit into
Conversation
…he key
The macOS Korean IME commits the syllable being composed when Enter is
pressed, before the Enter keydown arrives, and CompositionHelper sends
the committed text from a setTimeout(0). The custom key event handler
runs before CompositionHelper.keydown, so a key an embedder acts on
there went out first. In VS Code, a Shift+Enter keybinding that sends a
newline sequence to the terminal put the last syllable on the next line
("안녕하세" "\\\r\n" "고" instead of "안녕하세" "고" "\\\r\n").
Run the pending send before calling the custom handler. It is the same
send the timeout would make, so a key that reaches the terminal itself
behaves as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
With the macOS Korean IME in VS Code's terminal (seen in Cursor, VS Code 1.128 base), pressing Shift+Enter while the last syllable is still being composed puts that syllable on the next line. Typing
안녕하세요and pressing Shift+Enter sends안녕하세, then the newline, then요. VS Code's Shift+Enter keybinding (workbench.action.terminal.sendSequence, which tools like Claude Code install for multi-line input) is a common setup, and Korean users hit this on every line break.Cause
When Enter ends the composition, the IME commits the syllable (
compositionend) and then the Enter keydown arrives.CompositionHelpersends the committed text from asetTimeout(0)aftercompositionend.CompositionHelper.keydownalready sends it right away for a key that reaches it, which is why a plain Enter works. But_keyDowncalls the custom key event handler beforeCompositionHelper.keydown. When the embedder acts on the key there (VS Code runs the keybinding and the handler returnsfalse), its data goes out before the committed text.Fix
Before calling the custom key event handler,
_keyDownasksCompositionHelperto send a composition that has ended but is still waiting to be sent (flushCommittedComposition). It runs the same send the timeout would run, so the text is the same and it is only sent once. It does nothing while a composition is still in progress or for the keyskeydownleaves to the IME (229, CapsLock, modifiers), and it is skipped when composition is ignored for Alt withmacOptionIsMeta.Tests
CompositionHelper.test.ts: the ended composition is sent at once and not again by the timeout; 229 and modifier keys leave it to the timeout; a composition still in progress is not sent.Terminal.test.ts: the flush runs before the custom handler (fails without the_keyDownchange).Verification
A page with the built
lib/xterm.mjsand a handler shaped like VS Code's (the custom handler returnsfalsefor Shift+Enter and a windowkeydownlistener records the "sendSequence"), typed on with the real Korean IME (2-Set Korean, macOS 27.0, Chrome 157). Typing안녕하세요, then Shift+Enter while요is still being composed:A plain Enter at the same point sends
"요"then"\r"with both builds.The same page in headless Chromium 155 with the IME driven through the DevTools protocol (
Input.imeSetComposition, then the 229 keydown,Input.insertTextwith the committed syllable and the Enter keydown sent back to back):The same order with the DOM events dispatched in one task: master
sendSequence,"고"; this PR"고",sendSequence.Related: #6275 fixes wrong text when keys arrive before the helper's pending timers run. This PR is about the order between the helper and the custom key handler; the two touch different parts of
_finalizeCompositionand don't depend on each other.🤖 Generated with Claude Code