-
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
Conversation
4d4a3b9
to
e5a12e4
Compare
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.
Pretty much looks good to me, just wrote down some questions that popped out at me while reading through the code. 👍
@@ -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('+'); |
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.
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.)
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 comment
The reason will be displayed to describe this comment to others. Learn more.
I'm noticing a lot of code for shifted_char
, but what about characters that require alt (aka option on macOS) to input? For example, in the french keyboard layout, typing @
requires pressing the option key (at least on macOS). Would this "alternate kind of shifted character" still work with these changes since they assume a US keyboard layout?
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.
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 @
, the character will be used as it is, and macOS will automatically use the correct keys of the actual keyboard layout.
But for Windows/Linux, the @
accelerator is internally translated as Shift + 2, and it will show as different keys depending on the actual keyboard layout.
So when using @
as accelerator, the actual key might be different on macOS and Windows/Linux depending on keyboard layout. This is because macOS accepts arbitrary characters as key shortcuts, while Windows/Linux only accept combinations of physical keys.
e5a12e4
to
7fb9204
Compare
Release Notes Persisted
|
I was unable to backport this PR to "13-x-y" cleanly; |
I was unable to backport this PR to "12-x-y" cleanly; |
I have automatically backported this PR to "14-x-y", please check out #29481 |
Description of Change
When a shifted character is used in accelerator, for example
Ctrl+Plus
andCtrl+?
, it should be kept as it is. And when Shift key and unshifted character are used, for exampleCtrl+Shift+=
andCtrl+Shift+/
, it should not be converted to shifted character.Close #21790.
Also as a side effect of this change, the
accelerator.patch
removes the hack hat usesDomCodeToUsLayoutCharacter
to get key character on Windows, which closes #26888.
(Germany keyboard layout)Checklist
npm test
passesRelease Notes
Notes: Fix shifted character getting changed in menu accelerator.