macOS: Include text in key events triggered by insertion key-bindings

In 705665957baf16f9ec4d256dd4d2fad98788314b we started relying on the
input method to decide whether a key event should include the resulting
text or not, based on the assumption that text insertion would happen
via the insertText:replacementRange: selector.

But the NSStandardKeyBindingResponding protocol includes several other
commands for inserting content, including insertTab:, insertBacktab:,
and insertNewline:.

  https://developer.apple.com/documentation/appkit/nsstandardkeybindingresponding

We explicitly handle the latter, but for any command we didn't handle,
we concluded that the input method didn't want us to insert text, and
sent the key event without text, which broke tab character insertion
in text edits.

As long as we're not handling these commands explicitly, we adjust
the logic to treat any command starting with "insert" as an unhandled
request to insert text, and forward it as a key event with the text
included, as before 705665957baf16f9ec4d256dd4d2fad98788314b.

Fixes: QTBUG-109754
Task-number: QTBUG-106393
Change-Id: I4a164bc809c3606b43f267514a66ff017efeb4af
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 7e7bae35f758acba45257d1cb4229d5bc43b07ca)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Tor Arne Vestbø 2023-01-03 14:13:53 +01:00 committed by Qt Cherry-pick Bot
parent 969ba5e368
commit ee1e0d256b

View File

@ -370,14 +370,16 @@
if (![self tryToPerform:selector with:self]) {
m_sendKeyEvent = true;
// The text input system determined that the key event was not
// meant for text insertion, and instead asked us to treat it
// as a (possibly noop) command. This typically happens for key
// events with either ⌘ or ⌃, function keys such as F1-F35,
// arrow keys, etc. We reflect that when sending the key event
// later on, by removing the text from the event, so that the
// event does not result in text insertion on the client side.
m_sendKeyEventWithoutText = true;
if (![NSStringFromSelector(selector) hasPrefix:@"insert"]) {
// The text input system determined that the key event was not
// meant for text insertion, and instead asked us to treat it
// as a (possibly noop) command. This typically happens for key
// events with either ⌘ or ⌃, function keys such as F1-F35,
// arrow keys, etc. We reflect that when sending the key event
// later on, by removing the text from the event, so that the
// event does not result in text insertion on the client side.
m_sendKeyEventWithoutText = true;
}
}
}