Subject: bug#29595: 26.0.90; menu items show incorrect shortcut keys

From: Alan Third <[email-masked]>
Date: Fri, 22 Dec 2017 12:34:33 +0000

On Fri, Dec 22, 2017 at 09:26:18AM +0200, Eli Zaretskii wrote:
> > From: Paul Rankin <[email-masked]>
> > Date: Fri, 22 Dec 2017 15:16:32 +1000
> > 
> > I’ve now tested this with Emacs versions 24.4, 25.4, 26.0.90 and HEAD
> > with the same results; this hasn’t happened for me with 24.x in the
> > past, so it appears that something has changed with macOS High Sierra
> > that screws up the display of shortcut keys in the menus.
> 
> You are probably right.

It seems that older macOS versions ignored keyboard shortcuts they
didn’t understand, but High Sierra appears to use a ‘best effort’
attempt which results in it just printing out the first character
(capital C for ctrl, so shift‐C).

I’ve attached a patch that I hope fixes it.

-- 
Alan Third
>From 3ca7f2e2113eeace6b75f5f4b86bbcc4be609807 Mon Sep 17 00:00:00 2001
From: Alan Third <[email-masked]>
Date: Fri, 22 Dec 2017 12:27:05 +0000
Subject: [PATCH] Fix menu keyboard shortcuts on macOS (Bug#29595)

* src/nsmenu.m (addItemWithWidgetValue)[NS_IMPL_COCOA]: It looks like
macOS 10.13 no longer ignores long modifier strings, so explicitly use
an empty string.
---
 src/nsmenu.m | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/src/nsmenu.m b/src/nsmenu.m
index 6ef7b60dc2..d2e102a2a9 100644
--- a/src/nsmenu.m
+++ b/src/nsmenu.m
@@ -643,14 +643,23 @@ - (NSMenuItem *)addItemWithWidgetValue: (void *)wvptr
 
       keyEq = [self parseKeyEquiv: wv->key];
 #ifdef NS_IMPL_COCOA
-      /* macOS just ignores modifier strings longer than one character */
+      /* macOS mangles modifier strings longer than one character.  */
       if (keyEquivModMask == 0)
-        title = [title stringByAppendingFormat: @" (%@)", keyEq];
+        {
+          title = [title stringByAppendingFormat: @" (%@)", keyEq];
+          item = [self addItemWithTitle: (NSString *)title
+                                 action: @selector (menuDown:)
+                          keyEquivalent: @""];
+        }
+      else
+        {
+#endif
+          item = [self addItemWithTitle: (NSString *)title
+                                 action: @selector (menuDown:)
+                          keyEquivalent: keyEq];
+#ifdef NS_IMPL_COCOA
+        }
 #endif
-
-      item = [self addItemWithTitle: (NSString *)title
-                             action: @selector (menuDown:)
-                      keyEquivalent: keyEq];
       [item setKeyEquivalentModifierMask: keyEquivModMask];
 
       [item setEnabled: wv->enabled];
-- 
2.14.3