-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[Keybinding] Normalize key sequences to US layout #3833
Conversation
fixes #2200 |
The underlying issue is that we have no way to find out what the keyboard layout of a user looks like, when running in the browser. VS Code does this through a native node library, but obviously this is not available in the case of browser-only. See microsoft/monaco-editor#1233 |
ac9c215
to
5ab0e77
Compare
Some bindings, i.e. 'Toggle Line Comment' or 'Open Terminal' are bound to a sequence that are not directly reachable on many non-US keyboard layouts. For instance 'ctrlcmd+/' to toggle line comments doesn't work on german kb layouts, because the slash is above the `7` and therefore the shortcut is seen as `cmdctrl+shift+7` This change translates the given chord to a normalized US keysequence if the character is one of the US layout keys. I.e. for `cmdctrl+shift+7` we also know the typed character is `/` so if there is no direct keybinding we test against a US-keyboard layouted version. Fixes #1244 Signed-off-by: Sven Efftinge <[email protected]>
5ab0e77
to
261993e
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.
This is a pragmatic solution for cases where the shift key is involved, but it does not work when additionally the alt key is involved. For example, if a keybinding is defined as alt+/
, I would have to press alt+shift+7
to get that on my keyboard. The resulting character
is \
, so the normalizeToUsLayout()
function would translate that to alt+\
, which is wrong.
I propose to add the guard !this.alt
in normalizeToUsLayout()
so at least it works for the shift-only case.
Ah, you updated the code in the meantime. The problem is, if the user presses |
Yes, I changed it now so that both 'shift+alt' are removed and also that at least one other modifier has to be pressed. |
But I'm fine with keeping this solution until we run into actual problems. The only alternative I can think of at the moment is to change the problematic keybindings. One additional thing we could do is to hard-code a list of problematic keybindings such as |
I think that would be an unrelated check, because even without this change those bindings are problematic as they are used to type a character. |
Ok, but |
I'll create a separate issue for that. |
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.
Looks good to me. However,
- I can toggle line comments with
ctrl+shift+7
due to [osx][keybinding][monaco] Modifier keys are incorrectly mapped on macOS #3834, - I cannot toggle line comments with
cmd+shift+7
, but the search box in the Help menu is activated instead.
@kittaakos do you know if the appveyor failure is possibly related to my changes? I cannot tell from the output, unfortunately. |
I have seen the same error before. Extracted from the AppVeyor log and formatted a bit:
|
Some bindings, i.e. 'Toggle Line Comment' or 'Open Terminal' are
bound to a sequence that are not directly reachable on many
non-US keyboard layouts. For instance 'ctrlcmd+/' to toggle line
comments doesn't work on german kb layouts, because the slash
is above the
7
and therefore the shortcut is seen ascmdctrl+shift+7
This change translates the given chord to
a normalized US keysequence if the character is one of the US layout
keys. I.e. for
cmdctrl+shift+7
we also know the typed character is/
so if there is no direct keybinding we test against a US-keyboard
layouted version.
Fixes #1244
Signed-off-by: Sven Efftinge [email protected]