diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2023-01-03 14:13:53 +0100 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2023-01-04 17:05:19 +0100 |
commit | 7e7bae35f758acba45257d1cb4229d5bc43b07ca (patch) | |
tree | 5c9894a3d26b0c2c718d83175c0b521114849745 /src/plugins/platforms | |
parent | 96708cf16182a49dd8521c8c8a50d96e9658599c (diff) |
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
Pick-to: 6.4 6.5
Change-Id: I4a164bc809c3606b43f267514a66ff017efeb4af
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r-- | src/plugins/platforms/cocoa/qnsview_complextext.mm | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/plugins/platforms/cocoa/qnsview_complextext.mm b/src/plugins/platforms/cocoa/qnsview_complextext.mm index 7c50ec7ece..cdeb7154fe 100644 --- a/src/plugins/platforms/cocoa/qnsview_complextext.mm +++ b/src/plugins/platforms/cocoa/qnsview_complextext.mm @@ -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; + } } } |