Skip to content

fix(chat): send after IME composition so the last character is not dropped - #80

Open
ljk0071 wants to merge 1 commit into
formulahendry:mainfrom
ljk0071:fix/ime-composition-last-char
Open

ljk0071 wants to merge 1 commit into
formulahendry:mainfrom
ljk0071:fix/ime-composition-last-char

Conversation

@ljk0071

@ljk0071 ljk0071 commented Nov 12, 2026

Copy link
Copy Markdown

Problem

With an IME-based layout (reproduced on macOS with the Korean 2-set IME, but the same applies to Japanese/Chinese and other composing input methods), pressing Enter while a composition is still active fires a keydown with isComposing === true / keyCode === 229. The handler called handleSend() right away, before the IME had committed the composing character.

As a result the prompt was sent without its last character (e.g. typing 안녕하세요 and pressing Enter sent 안녕하세), and the missing character was usually left behind in the input box.

Fix

Defer the send until the composition has been committed:

  • an Enter keydown with isComposing === true (or keyCode === 229) no longer sends immediately; it only marks the send as pending,
  • the compositionend handler then sends once, on the next tick, so textarea.value already contains the committed character,
  • the regular (non-composing) Enter path clears the pending flag, so a second keydown never sends the prompt twice,
  • a 500 ms timeout clears the pending flag in case no compositionend ever arrives.

This is related to #75, which ignores the composing keydown and relies on a second, non-composing keydown to send. This patch also handles IMEs that only deliver the composing keydown, while the pending-flag reset keeps the double-send from #75 fixed.

Testing

  • npx tsc -p . --noEmit — passes
  • npx eslint src --max-warnings 0 — passes
  • npm run compile — passes

Non-IME input is unchanged: plain Enter still sends and Shift+Enter still inserts a newline.

…opped

Pressing Enter while an IME composition is still active (Korean, Japanese,
Chinese, etc.) sent the prompt before the composition was committed, so the
last character was missing from the sent message (and often stayed behind in
the input).

Defer the send to the compositionend event instead. A short timeout clears the
pending flag if the composition never ends, and the regular Enter path clears
it as well so the prompt is never sent twice.
@ljk0071
ljk0071 force-pushed the fix/ime-composition-last-char branch from 886082e to 707dea3 Compare November 12, 2026 07:57
@ljk0071 ljk0071 closed this Nov 12, 2026
@ljk0071
ljk0071 deleted the fix/ime-composition-last-char branch November 12, 2026 08:00
@ljk0071
ljk0071 restored the fix/ime-composition-last-char branch November 12, 2026 08:02
@ljk0071 ljk0071 reopened this Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant