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>
This commit is contained in:
parent
9004575f4b
commit
294e4c7aa8
@ -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];
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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().
|
||||
|
Loading…
Reference in New Issue
Block a user