Skip to content

Commit efeacec

Browse files
fix: Block triggering key after composition end
When pressing space or period to end Korean IME composition, the keydown event fires before compositionend. This caused the triggering character to be output before the composed text (e.g., "세요" becomes "세 요"). Added compositionJustEnded flag that blocks the first keydown after composition ends, preventing the character order reversal. Fixes hongsw#1 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 3180b52 commit efeacec

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

lib/input-handler.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ export class InputHandler {
195195
private mousemoveListener: ((e: MouseEvent) => void) | null = null;
196196
private wheelListener: ((e: WheelEvent) => void) | null = null;
197197
private isComposing = false;
198+
private compositionJustEnded = false; // Block keydown briefly after composition ends
198199
private isDisposed = false;
199200
private mouseButtonsPressed = 0; // Track which buttons are pressed for motion reporting
200201
private lastKeyDownData: string | null = null;
@@ -374,6 +375,13 @@ export class InputHandler {
374375
return;
375376
}
376377

378+
// Block the key that triggered composition end (e.g., space, period)
379+
// This fixes the "세요" -> "세 요" bug where keydown fires before compositionend
380+
if (this.compositionJustEnded) {
381+
this.compositionJustEnded = false;
382+
return;
383+
}
384+
377385
// Emit onKey event first (before any processing)
378386
if (this.onKeyCallback) {
379387
this.onKeyCallback({ key: event.key, domEvent: event });
@@ -690,6 +698,14 @@ export class InputHandler {
690698
if (this.isDisposed) return;
691699
this.isComposing = false;
692700

701+
// Set flag to block the next keydown event (the key that triggered composition end)
702+
// This prevents "세요" becoming "세 요" when space/period is pressed
703+
this.compositionJustEnded = true;
704+
// Clear flag after a short delay to allow normal keydown processing
705+
setTimeout(() => {
706+
this.compositionJustEnded = false;
707+
}, 10);
708+
693709
const data = event.data;
694710
if (data && data.length > 0) {
695711
if (this.shouldIgnoreCompositionEnd(data)) {

0 commit comments

Comments
 (0)