Detect keycode for keyDown
in Safari's IME
#4186
Merged
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.
Why
Fixes #4178
Chrome, Firefox, etc. handle the IME very well. If the IME is visible and the key is the enter key, it just dismisses the IME and inserts whatever selection into the input. Naturally though, Safari must not have the same behavior, otherwise our jobs would be too simple.
Specifically, on other browsers,
onCompositionEnd
is fired after theonKeyDown
event is fired. This means that ourisComposing
value is still true when we decide whether to submit the message or not. However, on Safari,onCompositionEnd
is fired before!Therefore, on Safari, we can check if the
Enter
press has a keycode of229
. If it does, we do not submit the message.I also moved the
isSafari
andisFirefox
checks into a separate filebrowsers.ts
and made abrowsers.native.ts
version that just returns false. We are using these a little more and they are getting duplicated, so might as well add them to one place. I didn't want to use the existingconstants.ts
since we won't have a.web
version of that file.Test Plan
Same as other browser for IME. Enable the IME, and type some text. Press the enter key to see if it submits or does not. With this PR, Safari should not submit on enter press while the IME is still open.
Screen.Recording.2024-05-22.at.8.52.18.PM.mov