From 0835537c3c3a8b7991b7a6e4a877a13f165a66e7 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Fri, 10 Feb 2023 16:49:38 +0100 Subject: [PATCH] macOS: map Qt::Key_Return to NSCarriageReturnCharacter in menus MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On macOS, key combinations with the Return key do not get delivered through NSView::keyDown, but they are seen by the QCocoaNSMenu::menuHasKeyEquivalent override. We already use that override to check whether any menu item uses a matching shortcut, and give Qt's focus object a chance to override the shortcut. The key mapper used the NSNewlineCharacter '\n' for Qt::Key_Return. However, the character we get from macOS for the return key is the NSCarriageReturnCharacter character, '\r'. This makes the lookup fail, and shortcut overrides are not delivered for shortcuts using Qt::Key_Return. To fix this, map Qt::Key_Return to NSCarriageReturnCharacter. The inverse mapping maps both NSCarriageReturnCharacter and NSNewlineCharacter to Qt::Key_Return, and there are no other users of this function in Qt. Pick-to: 6.5 6.4 Fixes: QTBUG-107526 Change-Id: I716190adf3cd94697e2b3ad1afc25b95d8ebde25 Reviewed-by: Tor Arne Vestbø Reviewed-by: Timur Pocheptsov --- src/gui/platform/darwin/qapplekeymapper.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/platform/darwin/qapplekeymapper.mm b/src/gui/platform/darwin/qapplekeymapper.mm index a0a2eb208d..f7dbc1990d 100644 --- a/src/gui/platform/darwin/qapplekeymapper.mm +++ b/src/gui/platform/darwin/qapplekeymapper.mm @@ -360,7 +360,7 @@ QChar QAppleKeyMapper::toCocoaKey(Qt::Key key) { // Prioritize overloaded keys if (key == Qt::Key_Return) - return QChar(NSNewlineCharacter); + return QChar(NSCarriageReturnCharacter); if (key == Qt::Key_Backspace) return QChar(NSBackspaceCharacter);