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

Keyboard shortcuts not matching layout locale #143442

Closed
akirataguchi115 opened this issue Feb 19, 2022 · 5 comments
Closed

Keyboard shortcuts not matching layout locale #143442

akirataguchi115 opened this issue Feb 19, 2022 · 5 comments
Assignees
Labels
*duplicate Issue identified as a duplicate of another issue(s) keyboard-layout Keyboard layout issues linux Issues with VS Code on Linux

Comments

@akirataguchi115
Copy link

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.64.2
  • OS Version: Ubuntu 20.04.3 LTS x86_64

Steps to Reproduce:

  1. Change the OS keyboard layout to Finnish/Swedish
  2. Shortcut for Fold should be something like ctrl + shift+ `
  3. It is however not bound to anything yet when switching to US keyboard the Shortcut is there
@alexdima
Copy link
Member

alexdima commented Feb 22, 2022

Our default keybindings are optimized for the US keyboard layout. In this particular case, Fold is bound by default to Ctrl+Shift+[.

  • on the US keyboard layout, [ is produced by the [BracketLeft] key, so the keybinding is Ctrl+Shift+[BracketLeft].
  • on the Swedish keyboard layout, Ctrl+Shift+[ cannot be mapped to a key combination because [ can only be produced via AltGr+[Digit8], which is indistinguishable from Ctrl+Alt+[Digit8]. So the default keybinding would need to be Ctrl+Shift+Ctrl+Alt+[Digit8], which is not possible. So by default, Fold is not bound on the Swedish keyboard layout.

You can rebind this command to a different key combination and you can use keyboard layout independent keys in your keybindings.json if you want that they are constant across keyboard layouts. See https://code.visualstudio.com/docs/getstarted/keybindings#_keyboard-layoutindependent-bindings

Having better default keybindings for more keyboard layouts is something you can upvote at #1240

@alexdima alexdima added *duplicate Issue identified as a duplicate of another issue(s) keyboard-layout Keyboard layout issues linux Issues with VS Code on Linux labels Feb 22, 2022
@akirataguchi115
Copy link
Author

@alexdima Thanks for the answer! Is this a situation with just Linux or what am I missing here? 🤔 :

Windows version of vscode properly maps f.ex. opening a terminal to ctrl + shift + ö on my swedish Finnish keyboard layout. Fold is also bound to some combination doable in Finnish layout.

@alexdima
Copy link
Member

alexdima commented Feb 23, 2022

This way of mapping that I described above is the way of doing it on Linux and macOS, where we dispatch by default on keydown.code and not keydown.keyCode. On Windows, we dispatch on keydown.keyCode. The concept of a keyCode exists natively at the OS level on Windows. On Linux and macOS, keydown events have a keyCode property, but it is all "fabricated" by each browser to compensate for the lack of OS support.

On Windows, we interpret things differently, by default "Fold" is mapped to Ctrl+Shift+[ which is interpreted as Ctrl+Shift+VK_OEM_4 (See here). Sometimes virtual keys will be missing on Windows keyboard layouts, but most of the times they will be assigned to a physical key. You can read more about it here -- https://github.com/microsoft/vscode/wiki/Keybinding-Issues#ecode-ekeycode-and-ekey

@akirataguchi115
Copy link
Author

@alexdima Thanks for the answer, again! It's good to know that there are issues OSwise that are not strictly trivial.

Just to be clear: Can't I just make a pull request to create a file like this but for Linux instead of Windows: https://github.com/microsoft/vscode/blob/main/src/vs/workbench/services/keybinding/browser/keyboardLayouts/sv.win.ts ?

@alexdima
Copy link
Member

Good search skills! :). In regular VS Code (desktop version) we've written a C++ node module -- https://github.com/microsoft/node-native-keymap -- which we use to listen to OS keyboard layout changes and to read the entire current keyboard layout. You can see this in action in VS Code when you switch keyboard layouts and the default keybindings update. You can see even more info from this module by opening a file and using F1 > Developer: Inspect Key Mappings. When configuring the Swedish keyboad layout, this native node module allows us to use X11 APIs and find out that AltGr+[Digit8] produces [ on the current keyboard.

However, VS Code can run entirely in a browser e.g. https://vscode.dev and we wanted VS Code on the web to feel familiar and work similarly to VS Code on desktop. However, browsers API are not 100% complete and we can't read the keyboard layout like we do in C++ and for obvious reasons we cannot load native C++ code... So on the web, we've made a compromise, where we ship a few of the most popular keyboard layouts (by usage numbers) and then try to guess at runtime which one is currently used. This is quite problematic by itself and is a short-term solution until browsers APIs improve. The file you have linked to is a file which gets shipped on VS Code for the web and which does not impact the desktop in any way.

I think your question is more "what would be necessary to implement #1240". Basically, we would either have to enrich the way keybindings are registered in source code (e.g.

kbOpts: {
kbExpr: EditorContextKeys.editorTextFocus,
primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.BracketLeft,
mac: {
primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.BracketLeft
},
weight: KeybindingWeight.EditorContrib
},
) with keyboard layout specific variants or we could attempt to maintain separate keymaps with only the deltas necessary for each keyboard layout.

Extensions can remove or add default keybindings. So in the short term, our proposed solution for this situation is that someone passionate creates an extension, let's say "Swedish layout keymap" and publishes it to the marketplace. The principle is very similar to other keymap extensions e.g. https://github.com/Microsoft/vscode-notepadplusplus-keybindings and such an extension can redefine some of the builtin keybindings which are not bound well, etc. Such an extension can then be shared via the marketplace.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*duplicate Issue identified as a duplicate of another issue(s) keyboard-layout Keyboard layout issues linux Issues with VS Code on Linux
Projects
None yet
Development

No branches or pull requests

2 participants