avoid premature message submission when using IME
Description
When using Japanese Input Method Editor (IME), the Enter key is also used for finalizing character conversion. This conflicts with pressing the Enter key to submit a message, and causes premature message submission and frustration for Japanese users who are in the middle of inputting text.
This PR ensures that the Enter key will only send the message if the user is not in the middle of an IME conversion, which should provide a more intuitive experience for users typing in Japanese.
NOTES: not sure but this might also happen in other languages which use IME such as Korean and Chinese.
Solution
- track whether the user is in the middle of an IME conversion by using the compositionstart and compositionend events
- modify handleKeyDown to only send the message if the Enter key is pressed and the user is not in the middle of an IME conversion.
Reference
- https://en.wikipedia.org/wiki/Japanese_input_method#Kana_to_kanji_conversion
- https://developer.mozilla.org/en-US/docs/Web/API/Element/compositionstart_event
- https://developer.mozilla.org/en-US/docs/Web/API/Element/compositionend_event
To avoid any confusion in the future about your contribution to Weaviate, we work with a Contributor License Agreement. If you agree, you can simply add a comment to this PR that you agree with the CLA so that we can merge.
beep boop - the Weaviate bot 👋🤖
PS:
Are you already a member of the Weaviate Slack channel?
Agree with CLA
Oh nice catch, thanks a lot for the PR! 🚀