diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2021-08-25 15:30:51 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2021-08-27 00:29:02 +0200 |
commit | 294e4c7aa8cacd63c01d3836ce06c1f2d8c5ad5c (patch) | |
tree | 0fb6516738577355b360045b6ea38ffcf9064bfc /src/plugins/platforms/cocoa/qnsview_complextext.mm | |
parent | 9004575f4b2aee7bf3c55522affd10555d134c51 (diff) |
macOS: Use current NSEvent to determine if IM text matches key event
Gives us one less state member to worry about in the IM machinery.
Task-number: QTBUG-35700
Pick-to: 6.2
Change-Id: Iaa06b29015f9b9594b8107b74a8931f076a26e12
Reviewed-by: Liang Qi <liang.qi@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa/qnsview_complextext.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qnsview_complextext.mm | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/plugins/platforms/cocoa/qnsview_complextext.mm b/src/plugins/platforms/cocoa/qnsview_complextext.mm index b6f082c515..d9df96e0cd 100644 --- a/src/plugins/platforms/cocoa/qnsview_complextext.mm +++ b/src/plugins/platforms/cocoa/qnsview_complextext.mm @@ -68,11 +68,23 @@ qCDebug(lcQpaKeys).nospace() << "Inserting \"" << text << "\"" << ", replacing range " << replacementRange; - if (m_sendKeyEvent && m_composingText.isEmpty() && [text isEqualToString:m_inputSource]) { - // We do not send input method events for simple text input, - // and instead let handleKeyEvent send the key event. - qCDebug(lcQpaKeys) << "Not sending simple text as input method event"; - return; + if (m_sendKeyEvent && m_composingText.isEmpty()) { + // The input method may have transformed the incoming key event + // to text that doesn't match what the original key event would + // have produced, for example when 'Pinyin - Simplified' does smart + // replacement of quotes. If that's the case we can't rely on + // handleKeyEvent for sending the text. + auto *currentEvent = NSApp.currentEvent; + NSString *eventText = currentEvent.type == NSEventTypeKeyDown + || currentEvent.type == NSEventTypeKeyUp + ? currentEvent.characters : nil; + + if ([text isEqualToString:eventText]) { + // We do not send input method events for simple text input, + // and instead let handleKeyEvent send the key event. + qCDebug(lcQpaKeys) << "Ignoring text insertion for simple text"; + return; + } } QObject *focusObject = m_platformWindow->window()->focusObject(); |