summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-08-25 15:30:51 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-08-27 00:29:02 +0200
commit294e4c7aa8cacd63c01d3836ce06c1f2d8c5ad5c (patch)
tree0fb6516738577355b360045b6ea38ffcf9064bfc /src/plugins/platforms
parent9004575f4b2aee7bf3c55522affd10555d134c51 (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')
-rw-r--r--src/plugins/platforms/cocoa/qnsview.mm4
-rw-r--r--src/plugins/platforms/cocoa/qnsview_complextext.mm22
-rw-r--r--src/plugins/platforms/cocoa/qnsview_keys.mm4
3 files changed, 17 insertions, 13 deletions
diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm
index c3884414e6..c1c11d5629 100644
--- a/src/plugins/platforms/cocoa/qnsview.mm
+++ b/src/plugins/platforms/cocoa/qnsview.mm
@@ -140,7 +140,6 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSViewMouseMoveHelper);
QSet<quint32> m_acceptedKeyDowns;
// Text
- NSString *m_inputSource;
QString m_composingText;
QPointer<QObject> m_composingFocusObject;
}
@@ -165,8 +164,6 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSViewMouseMoveHelper);
m_sendKeyEvent = false;
m_resendKeyEvent = false;
m_currentlyInterpretedKeyEvent = nil;
-
- m_inputSource = nil;
}
return self;
}
@@ -175,7 +172,6 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSViewMouseMoveHelper);
{
qCDebug(lcQpaWindow) << "Deallocating" << self;
- [m_inputSource release];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[m_mouseMoveHelper release];
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();
diff --git a/src/plugins/platforms/cocoa/qnsview_keys.mm b/src/plugins/platforms/cocoa/qnsview_keys.mm
index 762dc127cc..9fcd30d5d8 100644
--- a/src/plugins/platforms/cocoa/qnsview_keys.mm
+++ b/src/plugins/platforms/cocoa/qnsview_keys.mm
@@ -50,10 +50,6 @@
NSString *charactersIgnoringModifiers = nsevent.charactersIgnoringModifiers;
NSString *characters = nsevent.characters;
- if (m_inputSource != characters) {
- [m_inputSource release];
- m_inputSource = [characters retain];
- }
// Scan codes are hardware dependent codes for each key. There is no way to get these
// from Carbon or Cocoa, so leave it 0, as documented in QKeyEvent::nativeScanCode().