fix(terminal): don't hijack Space during IME composition (Korean input) - #75
Merged
Merged
Conversation
The push-to-talk handler (doctly#22) intercepted every plain-Space keydown, calling preventDefault() and writing a raw space straight to the PTY. xterm's _keyDown runs the custom key handler BEFORE its composition helper, so during Korean/Japanese/Chinese composition this blocked the commit and reordered/dropped the in-progress syllable (e.g. "녕 " came out as " 녕"). Gate the direct-send path on !isImeComposing(e) (isComposing, or the Chromium keyCode 229 sentinel) so it only fires when no IME is composing — exactly when push-to-talk needs it. During composition the event now falls through to xterm's composition helper for correct commit behavior. Extracts the decision as a pure, exported predicate and adds unit tests. Co-Authored-By: Claude Opus 4.8 (1M context) <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
Korean (and any IME-composed) input is corrupted in terminals: pressing space between words drops or reorders the in-progress Hangul syllable — e.g. typing
녕produces녕or loses the syllable entirely. This makes CLI sessions nearly unusable for Korean/Japanese/Chinese typists.Root cause
The push-to-talk Space handler added in #22 (
public/terminal-manager.js) intercepts every plain-Spacekeydown, callse.preventDefault(), writes a raw' 'straight to the PTY, and returnsfalse.The problem is ordering. In xterm's
_keyDown, the custom key handler runs before the IME composition helper:During Korean composition, the Space
keydownfires withisComposing === true/keyCode === 229. The handlerpreventDefaults it (blocking the composition commit), sends a raw space out of order, and returnsfalseso_compositionHelper.keydown()never runs. Since Korean is space-separated, this breaks essentially every word.Fix
Gate the direct-send path on
!isImeComposing(e)so it only fires when no IME is composing — which is exactly when push-to-talk needs it. During composition the event now falls through to xterm's composition helper for correct commit behavior.Push-to-talk (Hold Space to record) is unaffected: with no IME composing,
isComposingis false andkeyCodeis32, so the direct-send path still fires on every key-repeat.Testing
test/terminal-input.test.js(5 cases: plain space → direct send; composing viaisComposing; composing viakeyCode 229; modifier combos; non-space keys).npm test→ all green.🤖 Generated with Claude Code