macOS: Resend event if the first input method event changes focus

QAbstractItemView opens the editor and changes focus in response to the
first QEvent::InputMethod event. Changing focus however cancels the
current composition, so the key press is lost and needs to be repeated by
the user. What QAbstractItemView does is probably not that unique, so
fixing this there - if possible at all - is not a general solution.

In the platform specific input method handling code, we can generally
discover that the focus object changed in response to the InputMethod
event that gets sent to the focus object. On macOS, we can then pass the
key event to the input method once more, which works fine.

On Windows and X11, the situation is more complicated. That the focus
changed is easily discovered, but re-sending the key press in such a way
that the input method responds doesn't seem possible. On Windows, using
SendInput simply delivers the exact key to the focus object, without
starting the expected composition.

On X11 with IBus, it should be possible to call ProcessKeyEvent again on
the IBus input context when we discover in filterEventFinished that the
focus object changed while delivering the event. However, any attempt to
do so has no effect.

So, for now only fixing this for macOS.

Task-number: QTBUG-54848
Change-Id: I0f7b786cfa57430e6a1e7d605415265cf53eb675
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Volker Hilsheimer 2021-06-16 15:37:05 +02:00
parent b6c5e06676
commit 0c2ca26cd9

View File

@ -117,6 +117,11 @@
// pass the key event to the input method. note that m_sendKeyEvent may be set to false during this call
m_currentlyInterpretedKeyEvent = nsevent;
[self interpretKeyEvents:@[nsevent]];
// If the receiver opens an editor in response to a key press, then the focus will change, the input
// method will be reset, and the first key press will be gone. If the focus object changes, then we
// need to pass the key event to the input method once more.
if (qApp->focusObject() != fo)
[self interpretKeyEvents:@[nsevent]];
m_currentlyInterpretedKeyEvent = 0;
// if the last key we sent was dead, then pass the next key to the IM as well to complete composition
m_lastKeyDead = text.isEmpty();