Repository navigation
fix: handle space insertion during Korean IME composition #3555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AdamMagued
wants to merge
1
commit into
wavetermdev:main
Choose a base branch
from
AdamMagued:fix/issue-3545-bug-korean-ime-space-presse
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| // Copyright 2026, Command Line Inc. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { describe, expect, it, vi } from "vitest"; | ||
| import { isImeCompositionEvent, makeCustomKeyEventHandler } from "./termwrap"; | ||
|
|
||
| function createKeyEvent(opts: Partial<KeyboardEvent>): KeyboardEvent { | ||
| return { | ||
| isComposing: false, | ||
| key: "", | ||
| code: "", | ||
| keyCode: 0, | ||
| ctrlKey: false, | ||
| altKey: false, | ||
| metaKey: false, | ||
| shiftKey: false, | ||
| ...opts, | ||
| } as unknown as KeyboardEvent; | ||
| } | ||
|
|
||
| describe("isImeCompositionEvent", () => { | ||
| it("identifies space pressed during IME composition", () => { | ||
| const ev = createKeyEvent({ | ||
| isComposing: true, | ||
| key: " ", | ||
| code: "Space", | ||
| keyCode: 32, | ||
| }); | ||
| expect(isImeCompositionEvent(ev)).toBe(true); | ||
| }); | ||
|
|
||
| it("identifies enter and punctuation keys pressed during IME composition", () => { | ||
| expect(isImeCompositionEvent(createKeyEvent({ isComposing: true, key: "Enter", keyCode: 13 }))).toBe(true); | ||
| expect(isImeCompositionEvent(createKeyEvent({ isComposing: true, key: ".", keyCode: 190 }))).toBe(true); | ||
| expect(isImeCompositionEvent(createKeyEvent({ isComposing: true, key: ",", keyCode: 188 }))).toBe(true); | ||
| expect(isImeCompositionEvent(createKeyEvent({ isComposing: true, key: "?", keyCode: 191 }))).toBe(true); | ||
| }); | ||
|
|
||
| it("identifies process key and keyCode 229 as IME composition", () => { | ||
| expect(isImeCompositionEvent(createKeyEvent({ key: "Process", keyCode: 229 }))).toBe(true); | ||
| expect(isImeCompositionEvent(createKeyEvent({ key: "Process", keyCode: 0 }))).toBe(true); | ||
| expect(isImeCompositionEvent(createKeyEvent({ key: "Unidentified", keyCode: 229 }))).toBe(true); | ||
| }); | ||
|
|
||
| it("does not treat modifier combinations as IME composition", () => { | ||
| expect(isImeCompositionEvent(createKeyEvent({ isComposing: true, ctrlKey: true, key: "c", keyCode: 67 }))).toBe( | ||
| false | ||
| ); | ||
| expect(isImeCompositionEvent(createKeyEvent({ isComposing: true, metaKey: true, key: "v", keyCode: 86 }))).toBe( | ||
| false | ||
| ); | ||
| expect(isImeCompositionEvent(createKeyEvent({ isComposing: true, altKey: true, key: "a", keyCode: 65 }))).toBe( | ||
| false | ||
| ); | ||
| expect(isImeCompositionEvent(createKeyEvent({ keyCode: 229, ctrlKey: true }))).toBe(false); | ||
| }); | ||
|
|
||
| it("returns false for regular keystrokes outside composition", () => { | ||
| expect(isImeCompositionEvent(createKeyEvent({ isComposing: false, key: "a", keyCode: 65 }))).toBe(false); | ||
| expect(isImeCompositionEvent(createKeyEvent({ isComposing: false, key: " ", keyCode: 32 }))).toBe(false); | ||
| expect(isImeCompositionEvent(createKeyEvent({ isComposing: false, key: "Enter", keyCode: 13 }))).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe("makeCustomKeyEventHandler", () => { | ||
| it("returns false for space pressed during composition without calling keydownHandler", () => { | ||
| const keydownHandler = vi.fn(); | ||
| const handler = makeCustomKeyEventHandler(keydownHandler); | ||
| const ev = createKeyEvent({ | ||
| isComposing: true, | ||
| key: " ", | ||
| code: "Space", | ||
| keyCode: 32, | ||
| }); | ||
|
|
||
| const result = handler(ev); | ||
| expect(result).toBe(false); | ||
| expect(keydownHandler).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("returns false for IME process events without calling keydownHandler", () => { | ||
| const keydownHandler = vi.fn(); | ||
| const handler = makeCustomKeyEventHandler(keydownHandler); | ||
| const ev = createKeyEvent({ | ||
| key: "Process", | ||
| keyCode: 229, | ||
| }); | ||
|
|
||
| const result = handler(ev); | ||
| expect(result).toBe(false); | ||
| expect(keydownHandler).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("delegates normal keystrokes to keydownHandler", () => { | ||
| const keydownHandler = vi.fn().mockReturnValue(false); | ||
| const handler = makeCustomKeyEventHandler(keydownHandler); | ||
| const ev = createKeyEvent({ | ||
| isComposing: false, | ||
| key: "Enter", | ||
| keyCode: 13, | ||
| shiftKey: true, | ||
| }); | ||
|
|
||
| const result = handler(ev); | ||
| expect(result).toBe(false); | ||
| expect(keydownHandler).toHaveBeenCalledWith(ev); | ||
| }); | ||
|
|
||
| it("returns true for normal keystrokes when keydownHandler is undefined", () => { | ||
| const handler = makeCustomKeyEventHandler(undefined); | ||
| const ev = createKeyEvent({ | ||
| isComposing: false, | ||
| key: "a", | ||
| keyCode: 65, | ||
| }); | ||
|
|
||
| const result = handler(ev); | ||
| expect(result).toBe(true); | ||
| }); | ||
|
|
||
| it("delegates modifier shortcuts to keydownHandler even if keyCode is 229", () => { | ||
| const keydownHandler = vi.fn().mockReturnValue(true); | ||
| const handler = makeCustomKeyEventHandler(keydownHandler); | ||
| const ev = createKeyEvent({ | ||
| keyCode: 229, | ||
| ctrlKey: true, | ||
| key: "c", | ||
| }); | ||
|
|
||
| const result = handler(ev); | ||
| expect(result).toBe(true); | ||
| expect(keydownHandler).toHaveBeenCalledWith(ev); | ||
| }); | ||
| }); |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: wavetermdev/waveterm
Length of output: 18221
🏁 Script executed:
Repository: wavetermdev/waveterm
Length of output: 10714
🌐 Web query:
official xterm.js 6.0.0 source attachCustomKeyEventHandler CompositionHelper keydown keyCode 32 229💡 Result:
Allow keyCode 229 events to reach xterm.
@xterm/xterm6.0.0 schedules textarea-change processing for keyCode 229. The current return prevents that path, so IME-produced text may not reach the terminal.Do not allow every IME event through. In xterm 6.0.0,
CompositionHelper.keydowndoes not synchronously commit an active composition for Space keyCode 32. That event proceeds through normal keydown handling if allowed.🐛 Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents