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

macOS: improve IME state management #4087

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ksqsf
Copy link

@ksqsf ksqsf commented Jan 21, 2025

  • Tested on all platforms changed
  • Added an entry to the changelog module if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality

Fixes #3925
Fixes #3814

The basic idea of this change is: when IME is allowed, we always forward key events to the IME first, and use the result from the IME. Simpler keyboards, like the US keyboard, is also correctly supported by this.

Summary of changes:

  • Send Ime::Enabled when set_ime_allowed(true). Do not manage it elsewhere. This is a huge simplification, and it should be harmless to current conforming applications.
  • Do not prevent inserting text when there's no preedit.
  • Do not try to forward key to app even when no text is committed. This is safe because the IME now receive all keys and forwards back unhandled keys.
  • Some code becomes useless after the change and is thus removed.

What is improved:

  1. Any Chinese or Japanese input methods should now commit full-width punctuation just fine. Previously, this never worked.
  2. SKK Japanese IME should work now. Also, the toggle key q (toggles katakana) should work properly. Previously, SKK is not usable at all.
  3. The behavior of Korean IMEs doesn't change.

(Korean IMEs work mostly fine but #3095 is not fixed by this PR: the first key will generate a call to insertText: instead of setMarkedText:, which seems unrelated to the problems this PR tries to fix.)

fixes rust-windowing#3925

on macOS, when IME is allowed, always send text to IME and use that
result when possible.  Even if the keyboard is a simple one, like US
keyboard.

Committed text is now inserted regardless of the presence of a
preedit.
@ksqsf ksqsf requested a review from madsmtm as a code owner January 21, 2025 23:39
@fredizzimo
Copy link

I'm unable to test this myself, but it should probably mark #3814 as fixed too.

src/platform_impl/apple/appkit/view.rs Outdated Show resolved Hide resolved
src/changelog/unreleased.md Outdated Show resolved Hide resolved
Copy link
Member

@madsmtm madsmtm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hate our IME code with passion (another way of say I don't understand it at all ;) ), and will defer to Kirill's judgement as to whether this is a good idea or not. On the surface it looks fine.

@madsmtm madsmtm requested a review from kchibisov January 28, 2025 20:03
@kchibisov kchibisov added this to the Version 0.30.9 milestone Feb 2, 2025
Copy link
Member

@kchibisov kchibisov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All regular input now goes though IME, which is wrong. You can see that every character is going through Ime::Commit and not through regular keyboard input, thus nothing really works anymore when it comes to bindings and key combinations.

Regular input shouldn't go through IME.

@ksqsf
Copy link
Author

ksqsf commented Feb 2, 2025

Hmmm, then things are much more complicated. How about enable IME only when a text entry is focused?

Another way is perhaps to handle all shortcuts in performKeyEquivalent, supposing we know which shortcuts we are interested in.

@kchibisov
Copy link
Member

What text entry when we have none of that, so it won't really help as you can see? Like the issue is that normal input is not being sent at all. I'd suggest to figure out why punctuation is not sent in the first place, like there's clearly a case with the old code that makes it ignored, which should likely be changed to Commit, since no key input is also generated. It's just it seems like there should be a proper AND condition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

incorrectly handle insertText (macOS) Chinese IME punctuation behaviour is reveresed on macOS
4 participants