ai-chatbot icon indicating copy to clipboard operation
ai-chatbot copied to clipboard

fix: handle IME composition to prevent unintended submissions (#785)

Open cgoinglove opened this issue 11 months ago • 1 comments

Summary:

This PR fixes the IME composition error (#785) that causes the chat input field to retain the last word when submitting messages using an IME for languages such as Chinese, Korean, and Japanese. The error occurs because the Enter key event is processed while text composition is still in progress.

Issue Details:

When using an IME (for example, for Chinese, Korean, or Japanese input), text composition occurs in stages. The original submission condition was:

if (event.key === 'Enter' && !event.shiftKey)

This condition did not account for active text composition. As a result, pressing Enter during composition immediately processes the event, leaving the final composed word in the input field.

Fix:

The submission condition has been updated to include a check for ongoing text composition. The new condition is

if (event.key === 'Enter' && !event.shiftKey && !event.nativeEvent.isComposing)

This fix specifically addresses the IME composition error, and it should improve the behavior for other languages that rely on similar input methods.

cgoinglove avatar Feb 12 '25 09:02 cgoinglove

@cgoinglove is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Feb 12 '25 09:02 vercel[bot]

implemented from https://github.com/vercel/ai-chatbot/commit/cec3784536dcaf8343074bdbb01eaa164818f556

Rajaniraiyn avatar Mar 14 '25 14:03 Rajaniraiyn