microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
160.15k stars 28.05k forks source link

Wrong keybind is used with colemak & russian layout #141365

Open aliksend opened 2 years ago

aliksend commented 2 years ago

Issue Type: Bug

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

Steps to reproduce:

  1. Install colemak and russian keyboard (guess it is related to any non-querty layout along with non-english layout)
  2. Press Ctrl+D on colemak layout (actually - Ctrl and G key on keyboard) and take "editor.action.addSelectionToNextFindMatch" action. Perfect!
  3. Switch to russian and press the same keybinding. Take "workbench.action.gotoLine" action. Not what I expected.

Expected behavior is to have same actions for same keys, ignoring layout.

Just checked. In version

1.61.0
ee8c7def80afc00dd6e593ef12f37756d8f504ea
x64

keybindings works as expected, but in

1.62.0
b3318bc0524af3d74034b8bb8a64df0ccf35549a
x64

issue occurs (i'm using versions from archive, so not all versions are present)

Turning keyboard.dispatch to keyCode didn't help.

My logs with keyboard.dispatch = code

== russian
[2022-01-25 11:19:25.708] [renderer1] [info] [KeybindingService]: / Received  keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 17, key: Control
[2022-01-25 11:19:25.708] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 5 ('Ctrl')
[2022-01-25 11:19:25.708] [renderer1] [info] [KeybindingService]: \ Keyboard event cannot be dispatched in keydown phase.
[2022-01-25 11:19:25.865] [renderer1] [info] [KeybindingService]: / Received  keydown event - modifiers: [ctrl], code: KeyG, keyCode: 71, key: п
[2022-01-25 11:19:25.866] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: KeyG, keyCode: 37 ('G')
[2022-01-25 11:19:25.867] [renderer1] [info] [KeybindingService]: | Resolving ctrl+[KeyG]
[2022-01-25 11:19:25.868] [renderer1] [info] [KeybindingService]: \ From 1 keybinding entries, matched workbench.action.gotoLine, when: no when condition, source: built-in.
[2022-01-25 11:19:26.036] [renderer1] [info] [KeybindingService]: / Received  keydown event - modifiers: [ctrl], code: KeyG, keyCode: 71, key: п
[2022-01-25 11:19:26.037] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: KeyG, keyCode: 37 ('G')
[2022-01-25 11:19:26.038] [renderer1] [info] [KeybindingService]: | Resolving ctrl+[KeyG]
[2022-01-25 11:19:26.038] [renderer1] [info] [KeybindingService]: \ From 1 keybinding entries, matched workbench.action.gotoLine, when: no when condition, source: built-in.

== colemak
[2022-01-25 11:19:40.340] [renderer1] [info] [KeybindingService]: / Received  keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 17, key: Control
[2022-01-25 11:19:40.341] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 5 ('Ctrl')
[2022-01-25 11:19:40.342] [renderer1] [info] [KeybindingService]: \ Keyboard event cannot be dispatched in keydown phase.
[2022-01-25 11:19:40.433] [renderer1] [info] [KeybindingService]: / Received  keydown event - modifiers: [ctrl], code: KeyG, keyCode: 68, key: d
[2022-01-25 11:19:40.440] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: KeyG, keyCode: 34 ('D')
[2022-01-25 11:19:40.440] [renderer1] [info] [KeybindingService]: | Resolving ctrl+[KeyG]
[2022-01-25 11:19:40.441] [renderer1] [info] [KeybindingService]: \ From 1 keybinding entries, matched editor.action.addSelectionToNextFindMatch, when: editorFocus, source: built-in.
[2022-01-25 11:19:40.574] [renderer1] [info] [KeybindingService]: / Received  keydown event - modifiers: [ctrl], code: KeyG, keyCode: 68, key: d
[2022-01-25 11:19:40.575] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: KeyG, keyCode: 34 ('D')
[2022-01-25 11:19:40.575] [renderer1] [info] [KeybindingService]: | Resolving ctrl+[KeyG]
[2022-01-25 11:19:40.576] [renderer1] [info] [KeybindingService]: \ From 1 keybinding entries, matched editor.action.addSelectionToNextFindMatch, when: editorFocus, source: built-in.

My logs with keyboard.dispatch = keyCode

== russian
[2022-01-25 11:27:19.126] [renderer1] [info] [KeybindingService]: / Received  keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 17, key: Control
[2022-01-25 11:27:19.127] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 5 ('Ctrl')
[2022-01-25 11:27:19.127] [renderer1] [info] [KeybindingService]: \ Keyboard event cannot be dispatched in keydown phase.
[2022-01-25 11:27:19.279] [renderer1] [info] [KeybindingService]: / Received  keydown event - modifiers: [ctrl], code: KeyG, keyCode: 71, key: п
[2022-01-25 11:27:19.279] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: KeyG, keyCode: 37 ('G')
[2022-01-25 11:27:19.280] [renderer1] [info] [KeybindingService]: | Resolving ctrl+G
[2022-01-25 11:27:19.280] [renderer1] [info] [KeybindingService]: \ From 1 keybinding entries, matched workbench.action.gotoLine, when: no when condition, source: built-in.
[2022-01-25 11:27:19.506] [renderer1] [info] [KeybindingService]: / Received  keydown event - modifiers: [ctrl], code: KeyG, keyCode: 71, key: п
[2022-01-25 11:27:19.507] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: KeyG, keyCode: 37 ('G')
[2022-01-25 11:27:19.507] [renderer1] [info] [KeybindingService]: | Resolving ctrl+G
[2022-01-25 11:27:19.508] [renderer1] [info] [KeybindingService]: \ From 1 keybinding entries, matched workbench.action.gotoLine, when: no when condition, source: built-in.

== colemak
[2022-01-25 11:26:51.893] [renderer1] [info] [KeybindingService]: / Received  keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 17, key: Control
[2022-01-25 11:26:51.893] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 5 ('Ctrl')
[2022-01-25 11:26:51.893] [renderer1] [info] [KeybindingService]: \ Keyboard event cannot be dispatched in keydown phase.
[2022-01-25 11:26:52.176] [renderer1] [info] [KeybindingService]: / Received  keydown event - modifiers: [ctrl], code: KeyG, keyCode: 68, key: d
[2022-01-25 11:26:52.177] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: KeyG, keyCode: 34 ('D')
[2022-01-25 11:26:52.177] [renderer1] [info] [KeybindingService]: | Resolving ctrl+D
[2022-01-25 11:26:52.178] [renderer1] [info] [KeybindingService]: \ From 1 keybinding entries, matched editor.action.addSelectionToNextFindMatch, when: editorFocus, source: built-in.
[2022-01-25 11:26:52.478] [renderer1] [info] [KeybindingService]: / Received  keydown event - modifiers: [ctrl], code: KeyG, keyCode: 68, key: d
[2022-01-25 11:26:52.479] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: KeyG, keyCode: 34 ('D')
[2022-01-25 11:26:52.479] [renderer1] [info] [KeybindingService]: | Resolving ctrl+D
[2022-01-25 11:26:52.480] [renderer1] [info] [KeybindingService]: \ From 1 keybinding entries, matched editor.action.addSelectionToNextFindMatch, when: editorFocus, source: built-in.

VS Code version: Code - OSS 1.62.0 (b3318bc0524af3d74034b8bb8a64df0ccf35549a, 2021-11-07T19:37:13.664Z) OS version: Linux x64 5.10.89-1-MANJARO Restricted Mode: No

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz (12 x 4000)| |GPU Status|2d_canvas: unavailable_software
gpu_compositing: disabled_software
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
opengl: disabled_off
rasterization: disabled_software
skia_renderer: enabled_on
video_decode: disabled_software
vulkan: disabled_off
webgl: unavailable_software
webgl2: unavailable_software| |Load (avg)|2, 2, 2| |Memory (System)|31.21GB (1.65GB free)| |Process Argv|--unity-launch| |Screen Reader|no| |VM|0%| |DESKTOP_SESSION|i3| |XDG_CURRENT_DESKTOP|i3| |XDG_SESSION_DESKTOP|i3| |XDG_SESSION_TYPE|x11|
aliksend commented 2 years ago

Russian letter п is in the button with label g that prints character g in qwerty and d in colemak. This is why action "workbench.action.gotoLine" is used and why you can see key: п ... ('G') in logs

alexdima commented 2 years ago

@aliksend Could you please try our latest insiders? We've made a bunch of recent changes on Linux, like to detect the real selected keyboard layout, to detect keyboard layout changes, or to fix some crashes. You can grab a zip that will execute side-by-side with vscode stable from https://code.visualstudio.com/insiders/ .

Once you have the latest insiders, it would be helpful to figure out if VS Code detects the switching between keyboard layouts correctly. You can find this out by opening an editor and using F1 > Developer: Inspect Key Mappings, then switching the keyboard layout and then running the command again.

aliksend commented 2 years ago

Problem still present in insiders build. Key mappings attached russian.txt colemak.txt

aliksend commented 2 years ago

As I understand, when I use non-english keyboard like russian system tries to "translate" keys from russian to english. When it receives russian keybinding like "Ctrl+П" it tries to translate it to english and uses QWERTY-layout, so "Ctrl+П" goes "Ctrl+G". But on colemak I expect "Ctrl+D".

It is not problem with vscode only, I've had this problem with other linux apps as well (google chrome for example) and on many applications on windows.

aliksend commented 2 years ago

@alexdima this issue still exists. We know when it appears (between 1.61 and 1.62 builds). We know what is wrong: code: KeyG is correct, but keyCode differs depends on keyboard layout. So issue is in converting from code to keyCode. It is all how I can help in it

VSCodeTriageBot commented 1 year ago

Hey @alexdima, this issue might need further attention.

@aliksend, you can help us out by closing this issue if the problem no longer exists, or adding more information.

VSCodeTriageBot commented 1 year ago

This issue has been closed automatically because it needs more information and has not had recent activity. See also our issue reporting guidelines.

Happy Coding!

Akhristenko commented 1 year ago

Problem still exists, is there any news about this issue?

suwermave commented 12 months ago

Please fix this. The bug still exists and can lead to dangerous shortcuts being called on accident.

suwermave commented 11 months ago

I did some testing that may help identify the roots of the problem! The issue does nothing to do with being Cyrillic - Ukrainian and Serbian layouts work just fine. However, Russian, Chinese and Japanese layouts - fail by retreating to QWERTY. Interestingly enough, Russian m17n layouts work, but they are alien to dominating Russian layout ЙЦУКЕН. And it doesn't help other languages.

Other tested languages: Arabic(Colemak keybindings worked), QWERTY Latin layouts(French, Spanish - Colemak keybindings didn't work, is this intended?)

It is reproducible, and affects multiple languages

suwermave commented 11 months ago

‼️ I have found a workaround ‼️ On Fedora 38:

  1. Add layout "Русский (kbd (m17n))" изображение
  2. Choose it, click "setup" изображение
  3. Turn on the option "Use US keyboard layout" and close the window. изображение

This also tells what is exactly wrong with VS Code - it should follow any chosen US layout when specified (like all other apps already do)!

unional commented 8 months ago

I use a colemak-dh layout created by using Keyboard Layout Creator 1.4.

I am facing the same problem in both Windows and in WSL.

I have set locale to Japan, don't know if that has anything to do with it.

Akhristenko commented 3 months ago

I think i found root of the problem.

When we change keyboard layout, vscode make map, containing the correspondence between scanCode to charCode(which uses in hotkey) And when we work with non english layout and for scanCode returned non-english letter, vscode add to map charCode corresponding for scanCode. For expample for ScanCode.KeyK will be added CharCode.K) The code, that do this placed at https://github.com/microsoft/vscode/blob/main/src/vs/workbench/services/keybinding/common/macLinuxKeyboardMapper.ts#L467

As a solution can be setting, that tell vscode to use concrete KeyboardMapping when he work with concrete keyboard layout. And we could set is settings 'ru' => 'en,dvp', for example, and when he create map for russian layout he will use KeyboardMapping for english dvorak.

Akhristenko commented 3 months ago

Or, as more easily solution, add flag useStartupLayout, and if this flag enabled disable event listener on https://github.com/microsoft/vscode/blob/main/src/vs/workbench/services/keybinding/electron-sandbox/nativeKeyboardLayoutService.ts#L45, so vscode will work as in version 1.61, right before this bug appear.