Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When in Japanese input, 'enter' should not immediately send the message #2103

Open
dvcrn opened this issue Dec 19, 2024 · 6 comments · May be fixed by #2175
Open

When in Japanese input, 'enter' should not immediately send the message #2103

dvcrn opened this issue Dec 19, 2024 · 6 comments · May be fixed by #2175

Comments

@dvcrn
Copy link

dvcrn commented Dec 19, 2024

Describe the bug

In Japanese IME, you typically type text, then hit enter to "commit" the correct Kanji. For example, if I type テスト then it will be underlined until I hit 'enter', in effect confirming that I've finished writing and picked the correct Kanji/characters

Cinny binds to enter, so even though I am not done typing and only committed a word, as soon as I hit enter, Cinny sends the message

It's a very common problem when using onkeyup as listener, eg: https://stackoverflow.com/questions/46812908/enter-keyup-event-in-japanese-input

Reproduction

No response

Expected behavior

No response

Platform and versions

macOS Desktop 4.2.3, macOS 15.2

Additional context

No response

@kfiven
Copy link
Collaborator

kfiven commented Dec 19, 2024

There's an option to change the behavior of Enter in settings, have you tried that?

@dvcrn
Copy link
Author

dvcrn commented Dec 20, 2024

Yes that works, but it's not the expected behavior. Hitting enter when in Japanese (or other asian) IME should not trigger sending of a message, since it will send an incomplete sentence/word

@programmablereya
Copy link

I haven't encountered this yet, but I can definitely speak to this being undesired, buggy behavior.

Between compositionstart and compositionend events - i.e., when KeyboardEvent.isComposing is true, the keydown and keyup events should be ignored by the editor. This is because at that time, the IME is composing the user's next character(s). While in an IME, the browser ignores all keystrokes, even ones with modifiers; Ctrl+T does not open a new tab, Ctrl+W does not close the current tab, Tab does not navigate the focus to the next element, etc. The only keystrokes that are expected to still function are system-wide keystrokes like Alt+F4.

The keydown events are still delivered to the browser (and thus to your code), but they should be ignored; they are fired primarily for you to be able to do things like have your code respond to the length of the partially-composed text, not to be treated as input directly to you. See the guidance here for another source on how to handle keydown events with IMEs.

You can experience an IME and see how it behaves in most programs by installing an input language with one (e.g., Japanese) and switching to it in your input selector. Or, if you're using GNOME, you can press Ctrl+Shift+E to enter an IME for inputting special characters (particularly emoji, but it lists all Unicode characters).

@programmablereya
Copy link

Safari bug image, showing an example where Safari sends compositionend-keydown-keyup and Firefox and Chrome send keydown-compositionend-keyup

Okay - it looks like the issue is specifically that Safari sends compositionend before sending the Enter keydown event, whereas other browsers send it between keydown and keyup. isComposing is just a helper property to avoid having to capture compositionstart and compositionend yourself, so it will also be affected by this.

And it's not guaranteed that the next keydown/keyup after compositionend is the keypress that ended composition, even in Safari; there are ways to end composition that don't require a keypress! (e.g., clicking a suggestion with the mouse or a touch input)

However, it does look like Safari respects the idea that keyCode must be 229 during composition (but not that key must be Unidentified...). Which should let us intercept this.

I'll adapt my in-progress patch to make use of this information.

programmablereya added a commit to programmablereya/cinny that referenced this issue Jan 21, 2025
On most browsers, pressing Enter to end IME composition produces this
sequence of events:
* keydown (keycode 229, key Processing/Unidentified, isComposing true)
* compositionend
* keyup (keycode 13, key Enter, isComposing false)

On Safari, the sequence is different:
* compositionend
* keydown (keycode 229, key Enter, isComposing false)
* keyup (keycode 13, key Enter, isComposing false)

This causes Safari users to mistakenly send their messages when they
press Enter to confirm their choice in an IME.

The workaround is to treat the next keydown with keycode 229 as if it
were part of the IME composition period if it occurs within a short time
of the compositionend event.

Fixes cinnyapp#2103, but needs confirmation from a Safari user.
@programmablereya
Copy link

@dvcrn - could you build the PR version and test that it does, in fact, work around the problem here?

@dvcrn
Copy link
Author

dvcrn commented Jan 22, 2025

Tested your PR and it fixes the issues, however there are a few build errors, I'll comment in the PR

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 a pull request may close this issue.

3 participants