Skip to content

Commit e3159b4

Browse files
Cong Liurogerwang
authored andcommitted
fixed bugs of modifiers of nw.MenuItem
* modifiers should be case insensitive * command and super should be supported same as cmd on macOS fixed nwjs#5451
1 parent e603924 commit e3159b4

File tree

3 files changed

+8
-32
lines changed

3 files changed

+8
-32
lines changed

src/api/menuitem/menuitem.cc

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ namespace nw {
3333
namespace {
3434

3535
typedef std::map<std::string,std::string> KeyMap;
36-
/*
37-
{
36+
37+
static KeyMap keymap = {
3838
{"`" , "Backquote"},
3939
{"\\" , "Backslash"},
4040
{"[" , "BracketLeft"},
@@ -56,34 +56,6 @@ typedef std::map<std::string,std::string> KeyMap;
5656
{"MEDIANEXTTRACK", "MediaTrackNext"},
5757
{"MEDIAPREVTRACK", "MediaTrackPrevious"}
5858
};
59-
*/
60-
61-
static KeyMap InitKeyMap() {
62-
KeyMap result;
63-
result["`"] = "Backquote";
64-
result["\\"] = "Backslash";
65-
result["["] = "BracketLeft";
66-
result["]"] = "BracketRight";
67-
result[","] = "Comma";
68-
result["="] = "Equal";
69-
result["-"] = "Minus";
70-
result["."] = "Period";
71-
result["'"] = "Quote";
72-
result[";"] = "Semicolon";
73-
result["/"] = "Slash";
74-
result["\n"] = "Enter";
75-
result["\t"] = "Tab";
76-
result["UP"] = "ArrowUp";
77-
result["DOWN"] = "ArrowDown";
78-
result["LEFT"] = "ArrowLeft";
79-
result["RIGHT"] = "ArrowRight";
80-
result["ESC"] = "Escape";
81-
result["MEDIANEXTTRACK"] = "MediaTrackNext";
82-
result["MEDIAPREVTRACK"] = "MediaTrackPrevious";
83-
return result;
84-
}
85-
86-
static KeyMap keymap = InitKeyMap();
8759

8860
}
8961

src/api/menuitem/menuitem_mac.mm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,12 @@
208208

209209
void MenuItem::SetModifiers(const std::string& modifiers) {
210210
NSUInteger mask = 0;
211-
NSString* nsmodifiers = [NSString stringWithUTF8String:modifiers.c_str()];
211+
NSString* nsmodifiers = [NSString stringWithUTF8String:modifiers.c_str()].lowercaseString;
212212
if([nsmodifiers rangeOfString:@"shift"].location != NSNotFound)
213213
mask = mask|NSShiftKeyMask;
214-
if([nsmodifiers rangeOfString:@"cmd"].location != NSNotFound)
214+
if([nsmodifiers rangeOfString:@"cmd"].location != NSNotFound
215+
|| [nsmodifiers rangeOfString:@"command"].location != NSNotFound
216+
|| [nsmodifiers rangeOfString:@"super"].location != NSNotFound)
215217
mask = mask|NSCommandKeyMask;
216218
if([nsmodifiers rangeOfString:@"alt"].location != NSNotFound)
217219
mask = mask|NSAlternateKeyMask;

src/api/menuitem/menuitem_views.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "content/nw/src/api/menuitem/menuitem.h"
2222

2323
#include "base/files/file_path.h"
24+
#include "base/strings/string_util.h"
2425
#include "base/strings/utf_string_conversions.h"
2526
#include "base/threading/thread_restrictions.h"
2627
#include "base/values.h"
@@ -74,6 +75,7 @@ void MenuItem::Create(const base::DictionaryValue& option) {
7475
enable_shortcut_ = true;
7576
//only code for ctrl, shift, alt, super and meta modifiers
7677
int modifiers_value = ui::EF_NONE;
78+
modifiers = base::ToLowerASCII(modifiers);
7779
if (modifiers.find("ctrl")!=std::string::npos){
7880
modifiers_value |= ui::EF_CONTROL_DOWN;
7981
}

0 commit comments

Comments
 (0)