flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
165.45k stars 27.31k forks source link

[macOS] Provide a way to close the accent panel programmatically #132272

Open angelosilvestre opened 1 year ago

angelosilvestre commented 1 year ago

Is there an existing issue for this?

Use case

In super_editor, we handle text input by using both TextInputClient (with delta model enabled) and FocusNode's onKey.

We need to handle key events because some operations generates text editing deltas and others don't. For example, typing a character generates a TextEditingDeltaInsertion, but pressing BACKSPACE don't. Because of that, we handle the BACKSPACE key event to delete a character upstream.

By handling the BACKSPACE key event we have the following issue:

After pressing and holding a letter, macOS shows the accent panel:

Sem Título

By pressing BACKSPACE, the panel should close. However, as we handled the BACKSPACE key event, the panel stays open.

Proposal

Provide a method in TextInputConnection so we can close the accent panel after handling the key event.

justinmc commented 1 year ago

@cbracken Do you know if Flutter is calling some native Mac API to show this accent menu in the engine? If so then it shouldn't be too hard to expose this programmatically to the framework.

flutter-triage-bot[bot] commented 1 year ago

The triaged-design label is irrelevant if there is no team-design label or fyi-design label.

cbracken commented 1 year ago

This is handled entirely by macOS (other than all the work that @LongCatIsLooong did to ensure we're not stealing input for arrow keys/numbers). I suspect that dismissing this should be identical to dismissing the IME composing candidates list. I suspect if there's a means to do that, we'll find it in InputMethodKit. Maybe [InputMethodController hidePalettes]?

justinmc commented 1 year ago

@cbracken Thank you for the insight here!

LongCatIsLooong commented 1 year ago

Does it work if you handle DeleteCharacterIntent instead of intercepting key events? As @cbracken mentioned the IME should be the one handling the accent menu, and if the backspace key event is intercepted by FocusNode.onKey, then the IME won't be able to close it.

angelosilvestre commented 1 year ago

@LongCatIsLooong Using DeleteCharacterIntent doesn't work because the Shortcuts widget also intercepts key events on FocusNode.onKey.

LongCatIsLooong commented 1 year ago

On macOS if I remember correctly it's not using a Shortcuts widget. Shortcuts uses / depends on Intent/Actions stuff, not the other way around.

flutter-triage-bot[bot] commented 4 months ago

The triaged-desktop label is irrelevant if there is no team-desktop label or fyi-desktop label.