-
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
New approach for handling keyboard layouts and keyboard events #4724
Conversation
hello, is it planned to be included in the upcoming release ? |
Detail, but the build on Linux now requires additional libraries, see: It is also not possible to build this branch on Gitpod because of this. |
Maybe we better to test it in next for a month before putting in latest? That's a cool change, but we have to verify that there are not surprises. cc @marcdumais-work @svenefftinge |
ff11c6d
to
28864ff
Compare
Yes, we need the additional package https://github.com/Microsoft/node-native-keymap#installing I added it to our
@svenefftinge should we add a Dockerfile to this repository, or would you rather add |
dfcf2fe
to
387d167
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.
I still need to try more things on Electron, great change!
387d167
to
84c7660
Compare
I restructured some of the code according to microsoft/node-native-keymap#10 (comment). Automatic update of all keybindings after a keyboard layout change works now in Electron. |
@spoenemann could you rebase please, i can start reviewing afterwards |
84c7660
to
08f2f7f
Compare
Done. |
08f2f7f
to
1840786
Compare
21f798e
to
a1f1deb
Compare
That's a great improvement! Shortcuts work way better now any existing web IDE i've tried! Testing Electron part... @spoenemann would be fine if I do one pass and fix naming of files/events to follow ours naming conventions? |
@marechal-p Do you have timeframe on it? I've finished testing Electron now and it looks great, but i'm always glad to more extensive testing :) I was looking at:
I will have a look at generation of ru layout for mac and playing with that around a bit. |
@akosyakov to be fair, I don't see much more else to comment about. When your review comments will be addressed I will be entirely good with these changes! Even if we happen to see something later, the code looks better now so I expect issues to be trivial. |
562586c
to
bfc4235
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.
I've resolved all outstanding issues and rebased.
@marechal-p If you are fine please approve and we can merge it.
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.
@akosyakov just noticed something: on Firefox layout doesn't seem to be automatically recognized.
IMO, we can get away just with a command to pick from the list of layouts:
> (quick pick)
- Linux: English (en)
- Linux: German (de)
- Linux: Français (fr)
- OSX: English (en)
...
This can either be done here, or on a following PR.
@marechal-p as far as I know @spoenemann is going to open 2 more issues and work on them:
But if the layout is not recognized then it works as on master for you. Not unexpected behaviour? |
Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
bfc4235
to
db5a826
Compare
@akosyakov I only noticed that using the German keyboard, it is not possible to do But it feels like expected behavior, as that will be fixed by being able to select the current layout. |
@marechal-p the same on master, so it's fine |
Everything is green on my side then :) Amazing work by the way, I really like these changes! |
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.
works nicely with international keyboard layout!
kudos to @spoenemann :) |
Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
What about my question:
|
@spoenemann yes, we need a CQ for all copied code |
Hi @spoenemann , The CQ looks good, thanks. |
Closes #4079, closes #1401, closes #3885, maybe also #2200 and #3518 (and possibly more).
I refactored a lot of the existing keybindings related code and introduced two new services:
layout-provider.ts
) tries to get the user's keyboard layout in the format defined by the native-keymap package.keyboard-layout-service.ts
) maps keybindings according to the provided keyboard layout and determines the characters to display in the UI (menus, quick open etc.)The KeyboardLayoutProvider behaves differently depending on the platform and browser:
native-keymap
package in the backend and transfer that information to the frontend via JSON-RPC.generate-layout.js
, which simply writes the output ofnative-keymap
to a file. I have already created layout files for German, French and US layouts.navigator.language
to guess the keyboard by the user's language setting (this is highly error-prone, of course).The KeyboardLayoutService behaves differently depending on the platform:
shift
andalt
modifiers. This reverse mapping is then used to transform keybindings. For example, the keybindingcmd+/
requires the/
character, which is reachable viashift+7
on German Mac keyboards. The reverse mapping transforms the keybinding tocmd+shift+7
.native-keymap
. Here the reverse mapping is computed based on the virtual keys. For example, the virtual key identifier for/
isVK_OEM_2
. On German Mac keyboards, this virtual key is mapped to the key labeled#
, so the keybindingctrl+/
is transformed toctrl+#
.The platform-specific behavior should be equivalent to what VS Code does. Please tell me if you find keybindings that are still different in VS Code.
There is still a lot of work to be done in order to improve keyboard detection for browsers that don't support the Keyboard API. For example, we could implement some heuristics that detect the keyboard after the user has pressed some keys, or implement a UI for selecting a keyboard. Furthermore, we should add more static layouts. Should we extract the script to a separate repository to make that easier also for external contributors? We don't need to build the whole of Theia just to run a simple NodeJS script.
The
native-keymap
package has a method to receive notifications when the keyboard layout has changed in the system. Unfortunately, this does not work yet (microsoft/node-native-keymap#10).I have created a CQ for the new dependency to
native-keymap
:https://dev.eclipse.org/ipzilla/show_bug.cgi?id=19423
I also had to copy the typings from VS Code (
native-keymap.d.ts
) because they are not included in the package. Do we need another CQ for this?