summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2022-07-06 14:40:01 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2022-07-14 14:09:34 +0200
commit6767ac20c972f0f2654076c22826c392e698edfc (patch)
tree506a5b2d3c96f068b5d7b7f89b21ce1230741e27 /src/plugins/platforms/cocoa
parent3ad0f755f56eae4e8d94459f7cc17671e51e95da (diff)
macOS: Distinguish between return and enter when inserting newlines
In most situations the originating key event contains the information we need, but during confirmation of input method composition the text of the event might be "~\r", in which case the logic we have on macOS for generating key events will interpret the key press as a tilde, and we end up inserting "~~" and fail to deliver the return key. We should probably treat NSEvents with characters > 1 as a special case and go via the virtual key map in QAppleKeyMapper, but for now we manually distinguish enter and return by looking at the modifiers. This works for enter key presses both via the key itself, and via Fn+Return. Fixes: QTBUG-104774 Fixes: QTBUG-103473 Pick-to: 6.2 6.3 6.4 Change-Id: I86d30b154867e8e2b6964967ede2bd0dadb83ef8 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa')
-rw-r--r--src/plugins/platforms/cocoa/qnsview_complextext.mm11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/plugins/platforms/cocoa/qnsview_complextext.mm b/src/plugins/platforms/cocoa/qnsview_complextext.mm
index 4be8126299..ad5f5a0827 100644
--- a/src/plugins/platforms/cocoa/qnsview_complextext.mm
+++ b/src/plugins/platforms/cocoa/qnsview_complextext.mm
@@ -112,9 +112,14 @@
KeyEvent newlineEvent(m_currentlyInterpretedKeyEvent ?
m_currentlyInterpretedKeyEvent : NSApp.currentEvent);
newlineEvent.type = QEvent::KeyPress;
- newlineEvent.key = Qt::Key_Return;
- newlineEvent.text = QLatin1Char(kReturnCharCode);
- newlineEvent.nativeVirtualKey = kVK_Return;
+
+ const bool isEnter = newlineEvent.modifiers & Qt::KeypadModifier;
+ newlineEvent.key = isEnter ? Qt::Key_Enter : Qt::Key_Return;
+ newlineEvent.text = isEnter ? QLatin1Char(kEnterCharCode)
+ : QLatin1Char(kReturnCharCode);
+ newlineEvent.nativeVirtualKey = isEnter ? kVK_ANSI_KeypadEnter
+ : kVK_Return;
+
qCDebug(lcQpaKeys) << "Inserting newline via" << newlineEvent;
newlineEvent.sendWindowSystemEvent(m_platformWindow->window());
}