We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5071

Summary: macOS ApplePressAndHold IME
Product: SDL Reporter: Emir Marincic <learath2>
Component: videoAssignee: Alex Szpakowski <amaranth72>
Status: ASSIGNED --- QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: renesd
Version: HG 2.1   
Hardware: x86_64   
OS: macOS 10.15   

Description Emir Marincic 2020-04-03 12:44:05 UTC
We disable the press and hold IME to type accented characters for 2 reasons it seems, first because we enable the text input at startup (why? just SDL1 compatibility?) and second because [SDLTranslatorResponder insertText:] can't handle the replacementRange.

We can support the press and hold IME by first of all by instead enabling/disabling @"ApplePressAndHoldEnabled" at SDL_StartTextInput/SDL_StopTextInput (and maybe some internal state to only enable it after the first StartTextInput to keep backwards compatibility).

What's less obvious is how to fix [SDLTranslatorResponder insertText:] we need to keep the selected range at the end of the text for the press and hold IME to respond properly, but given SDL doesn't handle the backing storage for the text itself we don't know what that range should be. We could instead fake selectedRange to always be at a certain point and translate replacementRange accordingly. However given there is no indication that the "accent menu" has started/completed (barring actually hooking into AppKit at runtime) I can't see a way to translate this into a SDL_TEXTEDITING event.

This is where I'm stuck, we could introduce a new event like SDL_TEXTINPUTRELATIVE, or maybe introduce a new field into SDL_TEXTINPUT to indicate relative replacement. I thought I'd ask for opinion before implementing anything as I'm not completely sure about the fix that'd be appropriate.
Comment 1 Rene Dudfield 2020-11-14 11:28:55 UTC
I'd like this for pygame as well, and am interested in any solutions :) I'm tracking the issue pygame side here: https://github.com/pygame/pygame/issues/2328
Comment 2 Sam Lantinga 2020-11-24 05:27:41 UTC
Alex, what do you think?