Skip to content
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

Merged
merged 1 commit into from
Dec 14, 2018
Merged

Conversation

svenefftinge
Copy link
Contributor

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]

@svenefftinge
Copy link
Contributor Author

svenefftinge commented Dec 14, 2018

fixes #2200

@svenefftinge
Copy link
Contributor Author

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

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]>
Copy link
Contributor

@spoenemann spoenemann left a 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.

@spoenemann
Copy link
Contributor

spoenemann commented Dec 14, 2018

Ah, you updated the code in the meantime. The problem is, if the user presses cmd+alt+shift+7 on a German Mac keyboard, we cannot know whether he meant cmd+alt+/ or cmd+\ on a US keyboard layout.

@svenefftinge
Copy link
Contributor Author

Yes, I changed it now so that both 'shift+alt' are removed and also that at least one other modifier has to be pressed.

@spoenemann
Copy link
Contributor

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 alt+/ or alt+\ and log a warning (or even an error?) when a command is registered with such a binding.

@svenefftinge
Copy link
Contributor Author

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.

@spoenemann
Copy link
Contributor

Ok, but cmd+alt+/ and cmd+alt+\ are problematic, too.

@spoenemann
Copy link
Contributor

I'll create a separate issue for that.

Copy link
Contributor

@spoenemann spoenemann left a 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,

@svenefftinge
Copy link
Contributor Author

svenefftinge commented Dec 14, 2018

I can toggle line comments with ctrl+shift+7 due to #3834,
I cannot toggle line comments with cmd+shift+7, but the search box in the Help menu is activated instead.

thanks, both issues are addressed through #3835.

@svenefftinge
Copy link
Contributor Author

@kittaakos do you know if the appveyor failure is possibly related to my changes? I cannot tell from the output, unfortunately.

@kittaakos
Copy link
Contributor

kittaakos commented Dec 14, 2018

I cannot tell from the output, unfortunately.

I have seen the same error before.

Extracted from the AppVeyor log and formatted a bit:

An unknown server-side error occurred while processing the command.
    at elements(".theia-preload") - C:\\projects\\theia\node_modules\\webdriverio\\build\\lib\\commands\\isExisting.js:46:17
    at isExisting(".theia-preload") -     at C:\\projects\\theia\node_modules\\wdio-sync\\build\\index.js:293:3

root ERROR Uncaught Exception:  TypeError: Cannot set property 'state' of undefined
root ERROR TypeError: Cannot set property 'state' of undefined
    at ReporterStats.testFail (C:\\projects\\theia\node_modules\\webdriverio\\build\\lib\\utils\\ReporterStats.js:459:29)
    at BaseReporter.<anonymous> (C:\\projects\\theia\node_modules\\webdriverio\\build\\lib\\utils\\BaseReporter.js:159:25)
    at emitOne (events.js:116:13)
    at BaseReporter.emit (events.js:211:7)
    at BaseReporter.handleEvent 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants