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

Add preference to fall back to using keyCode for keybindings #8609

Merged

Conversation

foltik
Copy link
Contributor

@foltik foltik commented Oct 9, 2020

What it does

By default, Theia interprets all KeyboardEvents by the code, property instead of key or keyCode. On Mac (#7919) and Linux (#7654), due to not handling specific user keymap customizations, this interpretation can sometimes be incorrect.

I added the preference keyboard.dispatch to CorePreferences, which can be either code to use the default handling, or keyCode to fall back to using the keyCode property of KeyboardEvents. This is the same workaround that is used in VSCode, due to an underlying issue with native-keymap as discussed in microsoft/vscode/issues/23991.

The main logic where the keyboard event is interpreted resides in KeyCode.createKeyCode and KeyCode.toKey(event), which are static methods. Because of this I wasn't able to inject the CorePreferences, so I added a parameter with a default value to the methods instead. I then injected CorePreferences into KeybindingRegistry, and used the keyboard.dispatch preference to pass into the callsite of KeyCode.createKeyCode when responding to KeyboardEvents.

There is additional code in other packages in this repo that would need to be updated to use this new parameter, however I figured I'd just do the basics to start before I get feedback on the approach I took. Maybe it would also make sense to have the key decoding handled by a service in some non static context, such as how VSCode does it? I would also be willing to give that a shot if it seems like the right direction to go.

I am new to both this codebase and TypeScript/Inversify.js, so please let me know if I'm not doing something right or if I should make any changes!

How to test

With keyboard.dispatch set to keyCode, #7654 and #7919 should no longer be reproducible. I was only able to test #7654 on my machine.

Review checklist

Reminder for reviewers

@vince-fugnitto vince-fugnitto added the keybindings issues related to keybindings label Oct 9, 2020
Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@foltik thank you for the contribution, do you mind squashing your commits (into a single one) so we may proceed with the review, logically they should be grouped together.

packages/core/src/browser/keyboard/keys.ts Outdated Show resolved Hide resolved
@foltik foltik force-pushed the keyboard-dispatch-preference branch from 0f67097 to 5e9518b Compare October 9, 2020 13:40
Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@foltik please be sure to perform the following updates:

@foltik foltik force-pushed the keyboard-dispatch-preference branch from 5e9518b to a1463b2 Compare October 9, 2020 19:44
Signed-off-by: Jack Foltz <jack@foltz.io>
@foltik foltik force-pushed the keyboard-dispatch-preference branch from a1463b2 to db714ab Compare October 9, 2020 19:47
@foltik
Copy link
Contributor Author

foltik commented Oct 9, 2020

@vince-fugnitto I signed off the commit, added the binding to the test, and added an additional test for the new functionality in keys.spec.ts.

Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@foltik sorry for the late review, I must have missed the ping and it was in my backlog of reviews. Code-wise the changes look very good, thank you for taking care of it! 👍

My colleague will now verify the functionality.

Copy link
Contributor

@DucNgn DucNgn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested both issues (#7654 and #7919) on my machines:

  • On Linux, tested remapping capslock to esc.
  • On MacOS, tested with Dvorak Qwerty CMD layout.

I confirm the functionality works very well on my side for both cases. The code also looks good to me 👍

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

Successfully merging this pull request may close these issues.

3 participants