zed icon indicating copy to clipboard operation
zed copied to clipboard

Linux Shortcuts don't work with non-latin / international keyboard layouts

Open leonovk opened this issue 1 year ago • 50 comments

Description

If you switch the keyboard layout to another language, the hotkeys stop working.

For example ctrl + s or ctrl + c.

Environment

Zed on Linux

leonovk avatar Jul 10 '24 12:07 leonovk

Can you provide some additional details:

  1. Which desktop environment are you using?
  2. Which tool are you using to switch keyboard layouts (setxkbmap, loadkeys, localectl, /etc/default/keyboard, etc)?
  3. Which language(s) or keyboard layout(s) are causing you trouble?
  4. What's the language/locale of your keyboard (QWERTY, QWERTZ, AZERTY, ÄWERTY, etc)

notpeter avatar Jul 10 '24 13:07 notpeter

  1. GNOME 46 Wayland
  2. To switch the keyboard layout, I use the default hotkey in the Gnome environment "super + spacebar". The language switches, but the hotkeys inside zed stop working.
  3. Hotkeys do not work when the Russian keyboard is on
  4. My keyboard has 2 layouts: Russian and English (QWERTY/ЙЦУКЕН)

leonovk avatar Jul 10 '24 14:07 leonovk

KDE 6.1.2 Wayland Fedora 40, rpm from Terra The same issue, the same layouts

AndyDroid10X avatar Jul 11 '24 07:07 AndyDroid10X

same issue. ubuntu 24.04 gnome 46, qwerty/йцукен (eng/rus)

yournumberone avatar Jul 18 '24 06:07 yournumberone

GNOME 42.9, Wayland Ubuntu 22.04.4 2 layouts: Russian and English (QWERTY/ЙЦУКЕН) The same issue

ruskiiamov avatar Jul 18 '24 09:07 ruskiiamov

Not using the Russian layout but, using keycodes for stuff like the ` key instead of the actual character would help here as well i.e. if we can press the "key under esc" regardless of the layout. Because on mine the ` character is at AltGr + "," so doing Ctrl+AltGr+, is quite inconvenient :sweat_smile:

Beryesa avatar Jul 18 '24 23:07 Beryesa

MacOS has the same issue with shortcuts that use Opt key (for example Opt+T for a task run). Tested on MacBook Air M1, Sonoma 14.5

quendimax avatar Jul 30 '24 14:07 quendimax

MacOS has the same issue with shortcuts that use Opt key (for example Opt+T for a task run). Tested on MacBook Air M1, Sonoma 14.5

@quendimax Please do not hijack this thread one with off-topic comments, this is a linux specific keyboard layout issue. Please open a new issue if you're having trouble.

FYI your issue is likely because Opt+T is invalid. 1. Zed use lowercase alt on all platforms rather than the MacOS specific Option or Opt. 2. Zed use - not +.

Any of these should work: alt-t, alt-shift-t, alt-T -- if not open a new issue.

notpeter avatar Jul 30 '24 15:07 notpeter

I have the same/similar issue, but on macOS, using Zed v0.149.0. Let me know if this goes into this existing issue or if I should file a new one.

  • For me, it's switching window focus stopped working in Zed (it works elsewhere in macOS). It's cmd+`.
  • I can still use cmd+s, cmd+c etc, however. So it's not as severe as OP's issue.
  • I'm using Swedish as input language.
  • If I switch back to English (US) input language, I cannot repro.

macOS keyboard settings Screenshot 2024-08-15 at 08 34 03

  1. Which desktop environment are you using? macOS
  2. Which tool are you using to switch keyboard layouts (setxkbmap, loadkeys, localectl, /etc/default/keyboard, etc)? None.
  3. Which language(s) or keyboard layout(s) are causing you trouble? Swedish.
  4. What's the language/locale of your keyboard (QWERTY, QWERTZ, AZERTY, ÄWERTY, etc). QWERTY.

Zed specs Zed: v0.149.0 (Zed Preview) OS: macOS 14.4.0 Memory: 32 GiB Architecture: aarch64

brookback avatar Aug 15 '24 06:08 brookback

@brookback Please file a new issue as your issue on MacOS is likely distinct. Please include full reproduction steps if possible. Thanks.

notpeter avatar Aug 15 '24 12:08 notpeter

same issue. nixos-unstable hyprland 0.42.0, qwerty/йцукен (eng/rus)

D3st0ny avatar Aug 24 '24 09:08 D3st0ny

Same issue on Ubuntu 24.04 LTS, Wayland session, Canadian Multilingual layout. Mapping on the Quote ' key does not work (it's "è"), nor does the \ key (it's "à").

In VS Code, it maps ctrl+' (ctrl+è on the Canadian Multilingual layout) as ctrl-[Quote].

SylChamber avatar Aug 28 '24 01:08 SylChamber

There is an active discussion going on here:

  • https://github.com/zed-industries/zed/discussions/17031

We'd love to gather input from folks who are using international keyboards with Zed.

notpeter avatar Sep 03 '24 16:09 notpeter

v0.162.x fixes most problems for macOS, so now Linux...

The goal here is to make the gpui platform implementation consistent with the macOS one, so:

  • For layouts which generate a different key when the platform modifier is down, we should use that as the basis of the keybindings. (so, ctrl-я becomes ctrl-q)
  • For layouts with dead-keys, we should generate a shortcut press for the dead key (so that ctrl-^ works, and even ^ to go to start of line in vim mode); we also need to generate shortcuts before IME if an IME is not in progress (so vim mode works on Japanese keyboards).
  • We also want to copy the changes for Extended Latin keyboards. For macOS, we copy the key equivalents from the OS; for Linux I'm not sure we can copy equivalents from anywhere (is there already a convention about what to do about ctrl-[ when [ requires alt to type?). We could possibly copy VSCode's logic if we want to avoid creating our own.

I took a bit of a look, and found that the first problem is that for non-Latin layouts that should have a different character when the platform modifier is pressed, we don't correctly read that even though xev does.

If anyone has done key handling on Linux before, I'd love to pair with you: https://calendly.com/conradirwin/pairing.

ConradIrwin avatar Nov 11 '24 23:11 ConradIrwin

yeaaaahhh i have the same issue qwerty/йцукен (eng(US)/rus)

VyacheslavKuchumov avatar Nov 14 '24 07:11 VyacheslavKuchumov

@VyacheslavKuchumov are you on macOS or Linux? If Linux, are you on Wayland or X11, and which IME system do you use?

ConradIrwin avatar Nov 18 '24 03:11 ConradIrwin

Same issue with Ukrainian (QWERTY/ЙЦУКЕН) on Linux (Fedora Workstation), Wayland, GNOME 47

Besides from mentioned above with extended keyboards and modifiers, I'm wondering is there anything blocking to use key/scan codes rather than key names? I.e. instead of mapping dozens of keys like й to q for ctrl + q, it could be something like ctrl + key:81?

ExposedCat avatar Nov 22 '24 12:11 ExposedCat

@ExposedCat I'd like this to work by default - so we don't need mappings in most cases. How other apps on Linux work; but it's not totally clear to me (and probably not as standardized as it is on macOS).

For example I know if I use a Cyrillic keyboard, then shortcuts like ctrl-shift-n for new window in Gnome terminal still work. Is that because they are bound to the key code, or is it because they are bound to a layer on your keyboard that generates ASCII still?

ConradIrwin avatar Nov 22 '24 16:11 ConradIrwin

@ConradIrwin can this be used?

However I'm not sure how to get these codes from rust without root access to /dev/input or device list

ExposedCat avatar Nov 23 '24 16:11 ExposedCat

Has this issue been resolved? I am using a Macbook Pro M4 with a Swedish layout. Shortcuts like toggling line comments do not work with swedish input.

RasmusHogslatt avatar Dec 06 '24 13:12 RasmusHogslatt

@RasmusHogslatt on a Swedish keyboard toggle comments is now cmd-´

Screenshot 2024-12-06 at 09 52 42

ConradIrwin avatar Dec 06 '24 16:12 ConradIrwin

@ConradIrwin I got back and tried this. Your comment was correct, and it reflects my setup, but for whatever reason, instead of toggling comments it opens the "Help" window for zed in the top menubar. Is that expected behaviour?

RasmusHogslatt avatar Dec 07 '24 13:12 RasmusHogslatt

@RasmusHogslatt that is not expected; part of the reason to move these shortcuts around is to avoid the builtin macOS shortcuts.

Are you also using the Swedish locale? What's the default help menu shortcut?

ConradIrwin avatar Dec 09 '24 17:12 ConradIrwin

I'm also using the Swedish layout, and can reproduce what @RasmusHogslatt is running into: when using the keyboard shortcut, the native macOS help menu is shown instead.

(It's been like this for a long time, so I just rebinded the shortcut to something else.)

Edit: I have a theory it's like this:

  1. If you read https://github.com/zed-industries/zed/blob/main/crates/settings/src/key_equivalents.rs#L1186, you'll see that / maps to ´.
  2. Toggle comments is bound to ´. image
  3. The Swedish layout for entering / is shift+7, so cmd+/ becomes cmd+shift+7.
  4. This keyboard shortcut is somehow triggering macOS's help menu.

brookback avatar Dec 09 '24 18:12 brookback

Should we adjust the macOS Swedish layout equivalents to be less intrusive by default?

        "com.apple.keylayout.Swedish" => &[
   // Copied from macOS
            // Move the window switching shortcuts to match the default Swedish locale
            ('`', '<'),
            ('~', '>'),
            ('<', ';'),
            ('>', ':'),
            (':', 'Å'),
            (';', 'å'),
            // Move these untypable "pairs" to typeable pairs (so indent/outdent feel similar)
            ('{', 'Ö'),
            ('}', 'Ä'),
            ('[', 'ö'),
            (']', 'ä'),
            // keep cmd-shift-{3,4,5} in the same place as it's used for macOS screenshots by default
            ('$', '€'),
  
   // Deviate from macOS (and current Zed)     
            // There are three remaining ASCII characters that require option to type on a Swedish keyboard, 
            // assign these to the three remaining characters that don't require option to type.
            ('@', '¨'),
            ('\\', '´'),
            ('|', '`'),

            // remove all these...
            // ('"', '^'),
            // ('&', '/'),
            // ('(', ')'),
            // (')', '='),
            // ('*', '('),
            // ('^', '&'),
            // ('/', '´'),
            // ('=', '`'),
            // ('\'', '¨'),
        ],

What is the default help shortcut in the Swedish locale? I also want to make sure we're not going to crash into it.

See also https://github.com/zed-industries/zed/issues/20425#issuecomment-2533543683 for similar woes with German and a proposed new default.

ConradIrwin avatar Dec 11 '24 03:12 ConradIrwin

same issue with en/ru kb layout.

endeavouros arch distro, x11 desktop (awesome)

bnn1 avatar Dec 17 '24 09:12 bnn1

I have same issue, shortcuts like ctrl+c and ctrl+v etc. Works only when active system layout is QWERTY, any other non latin layout breaks shortcuts.
Zed version: 0.166.1
OS: Fedora Linux 41 (Wayland) 
This issue not reproduced in other editors, vscode for example. 
Would like have an option that switches all shortcuts to keycode bind instead of char

Akiyamka avatar Dec 28 '24 14:12 Akiyamka

There was a similar problem for Cyrillic keyboard on Ubuntu. I share the solution

  1. Ctrl+Shift+P --> (execute command) debug: open key context view

  2. Press all the necessary key combinations and save their designations For example, Last Keystroke: Typed: "ctrl-cyrillic_em" = CTRL+M(cyrillic) ..... and others

  3. Menu - Open Key BIndings - add combinations (For example for cyrillic keyboard) { "context": "Editor", "bindings": { "ctrl-cyrillic_es":"editor::Copy", "ctrl-cyrillic_em":"editor::Paste", "ctrl-cyrillic_che": "editor::Cut", "ctrl-cyrillic_ef":"editor::SelectAll", "ctrl-cyrillic_ya": "editor::Undo", "ctrl-cyrillic_en": "editor::Redo", "ctrl-cyrillic_a": "buffer_search::Deploy" } }

  4. worked

neodraw avatar Feb 13 '25 21:02 neodraw

@neodraw - amazing, thank you

Akiyamka avatar Feb 14 '25 11:02 Akiyamka

I wrote a script that translates shortcuts into Cyrillic, so you can use or copy the already translated file localized_keymap.json here is the link to the script https://github.com/Randommist/zed-cyrillic

Randommist avatar Apr 14 '25 17:04 Randommist