summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/plugins/platforms/cocoa/qnsview.mm2
-rw-r--r--src/plugins/platforms/cocoa/qnsview_complextext.mm34
-rw-r--r--src/plugins/platforms/cocoa/qnsview_keys.mm4
3 files changed, 32 insertions, 8 deletions
diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm
index c1c11d5629..7de8da2da6 100644
--- a/src/plugins/platforms/cocoa/qnsview.mm
+++ b/src/plugins/platforms/cocoa/qnsview.mm
@@ -135,7 +135,6 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSViewMouseMoveHelper);
// Keys
bool m_lastKeyDead;
bool m_sendKeyEvent;
- bool m_resendKeyEvent;
NSEvent *m_currentlyInterpretedKeyEvent;
QSet<quint32> m_acceptedKeyDowns;
@@ -162,7 +161,6 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSViewMouseMoveHelper);
m_lastKeyDead = false;
m_sendKeyEvent = false;
- m_resendKeyEvent = false;
m_currentlyInterpretedKeyEvent = nil;
}
return self;
diff --git a/src/plugins/platforms/cocoa/qnsview_complextext.mm b/src/plugins/platforms/cocoa/qnsview_complextext.mm
index d9df96e0cd..3edbbae479 100644
--- a/src/plugins/platforms/cocoa/qnsview_complextext.mm
+++ b/src/plugins/platforms/cocoa/qnsview_complextext.mm
@@ -123,8 +123,38 @@
- (void)insertNewline:(id)sender
{
Q_UNUSED(sender);
- qCDebug(lcQpaKeys) << "Inserting newline";
- m_resendKeyEvent = true;
+
+ // Depending on the input method, pressing enter may
+ // result in simply dismissing the input method editor,
+ // without confirming the composition. In other cases
+ // it may confirm the composition as well. And in some
+ // cases the IME will produce an explicit new line, which
+ // brings us here.
+
+ // Semantically, the input method has asked us to insert
+ // a newline, and we should do so via an QInputMethodEvent,
+ // either directly or via [self insertText:@"\r"]. This is
+ // also how NSTextView handles the command. But, if we did,
+ // we would bypass all the code in Qt (and clients) that
+ // assume that pressing the return key results in a key
+ // event, for example the QLineEdit::returnPressed logic.
+ // To ensure that clients will still see the Qt::Key_Return
+ // key event, we send it as a normal key event.
+
+ // But, we can not fall back to handleKeyEvent for this,
+ // as the original key event may have text that reflects
+ // the combination of the inserted text and the newline,
+ // e.g. "~\r". We have already inserted the composition,
+ // so we need to follow up with a single newline event.
+
+ KeyEvent newlineEvent(NSApp.currentEvent);
+ newlineEvent.key = Qt::Key_Return;
+ newlineEvent.text = QLatin1Char(kReturnCharCode);
+ newlineEvent.nativeVirtualKey = kVK_Return;
+ qCDebug(lcQpaKeys) << "Inserting newline via" << newlineEvent;
+ newlineEvent.sendWindowSystemEvent(m_platformWindow->window());
+
+ m_sendKeyEvent = false;
}
// ------------- Text composition -------------
diff --git a/src/plugins/platforms/cocoa/qnsview_keys.mm b/src/plugins/platforms/cocoa/qnsview_keys.mm
index 9628b770ad..fb55612212 100644
--- a/src/plugins/platforms/cocoa/qnsview_keys.mm
+++ b/src/plugins/platforms/cocoa/qnsview_keys.mm
@@ -55,7 +55,6 @@
window = popup->window();
}
- QBoolBlocker resendKeyEventGuard(m_resendKeyEvent, false);
// We will send a key event unless the input method sets m_sendKeyEvent to false
QBoolBlocker sendKeyEventGuard(m_sendKeyEvent, true);
@@ -108,9 +107,6 @@
}
}
-
- if (m_resendKeyEvent)
- m_sendKeyEvent = true;
}
bool accepted = true;