summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2022-07-06 14:40:01 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-08-10 09:41:25 +0000
commit13118701255b5e6835c018e9a9f8741140f768bb (patch)
tree983b684eebf46c6edbe4b681741e5381d890e76d /src
parenta3c67555661233ec3d4dff5d1b93332403e80306 (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 Change-Id: I86d30b154867e8e2b6964967ede2bd0dadb83ef8 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 6767ac20c972f0f2654076c22826c392e698edfc) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-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());
}