-
Notifications
You must be signed in to change notification settings - Fork 16.2k
fix: keep shifted character in menu accelerator #29202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,9 @@ namespace electron { | |
namespace { | ||
|
||
// Return key code represented by |str|. | ||
ui::KeyboardCode KeyboardCodeFromKeyIdentifier(const std::string& s, | ||
bool* shifted) { | ||
ui::KeyboardCode KeyboardCodeFromKeyIdentifier( | ||
const std::string& s, | ||
base::Optional<char16_t>* shifted_char) { | ||
std::string str = base::ToLowerASCII(s); | ||
if (str == "ctrl" || str == "control") { | ||
return ui::VKEY_CONTROL; | ||
|
@@ -36,7 +37,7 @@ ui::KeyboardCode KeyboardCodeFromKeyIdentifier(const std::string& s, | |
} else if (str == "altgr") { | ||
return ui::VKEY_ALTGR; | ||
} else if (str == "plus") { | ||
*shifted = true; | ||
shifted_char->emplace('+'); | ||
return ui::VKEY_OEM_PLUS; | ||
} else if (str == "capslock") { | ||
return ui::VKEY_CAPITAL; | ||
|
@@ -319,11 +320,17 @@ ui::KeyboardCode KeyboardCodeFromCharCode(char16_t c, bool* shifted) { | |
} | ||
} | ||
|
||
ui::KeyboardCode KeyboardCodeFromStr(const std::string& str, bool* shifted) { | ||
if (str.size() == 1) | ||
return KeyboardCodeFromCharCode(str[0], shifted); | ||
else | ||
return KeyboardCodeFromKeyIdentifier(str, shifted); | ||
ui::KeyboardCode KeyboardCodeFromStr(const std::string& str, | ||
base::Optional<char16_t>* shifted_char) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm noticing a lot of code for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Electron apps, the accelerators are written in US keyboard layout, so we only consider the shifted state for the keys. For macOS, if the accelerator is But for Windows/Linux, the So when using |
||
if (str.size() == 1) { | ||
bool shifted = false; | ||
auto ret = KeyboardCodeFromCharCode(str[0], &shifted); | ||
if (shifted) | ||
shifted_char->emplace(str[0]); | ||
return ret; | ||
} else { | ||
return KeyboardCodeFromKeyIdentifier(str, shifted_char); | ||
} | ||
} | ||
|
||
} // namespace electron |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side note: This isn't strictly true,
+
isn't a shifted character for all keyboard layouts. This PR doesn't really aim to fix that functionality, I'm just noting it here so we don't close some linked issues that do talk about that as well.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The internal representation of accelerators is using US keyboard layout, and then the accelerator will be converted to actual keys according to the actual keyboard layout.
(below comment explains more.)