macOS: Add key equivalents for non-Latin layouts (#20401)
Closes #16343
Closes #10972
Release Notes:
- (breaking change) On macOS when using a keyboard that supports an
extended Latin character set (e.g. French, German, ...) keyboard
shortcuts are automatically updated so that they can be typed without
`option`. This fixes several long-standing problems where some keyboards
could not type some shortcuts.
- This mapping works the same way as
[macOS](https://developer.apple.com/documentation/swiftui/view/keyboardshortcut(_:modifiers:localization:)).
For example on a German keyboard shortcuts like `cmd->` become `cmd-:`,
`cmd-[` and `cmd-]` become `cmd-ö` and `cmd-ä`. This mapping happens at
the time keyboard layout files are read so the keybindings are visible
in the command palette. To opt out of this behavior for your custom
keyboard shortcuts, set `"use_layout_keys": true` in your binding
section. For the mappings used for each layout [see
here](a890df1863/crates/settings/src/key_equivalents.rs (L7)
).
---------
Co-authored-by: Will <will@zed.dev>
This commit is contained in:
parent
07821083df
commit
ff4f67993b
16 changed files with 435 additions and 10 deletions
|
@ -23,6 +23,8 @@ The file contains a JSON array of objects with `"bindings"`. If no `"context"` i
|
|||
|
||||
Within each binding section a [key sequence](#keybinding-syntax) is mapped to an [action](#actions). If conflicts are detected they are resolved as [described below](#precedence).
|
||||
|
||||
If you are using a non-QWERTY, Latin-character keyboard, you may want to set `use_layout_keys` to `true`. See [Non-QWERTY keyboards](#non-qwerty-keyboards) for more information.
|
||||
|
||||
For example:
|
||||
|
||||
```json
|
||||
|
@ -58,7 +60,7 @@ Each key press is a sequence of modifiers followed by a key. The modifiers are:
|
|||
- `shift-` The shift key
|
||||
- `fn-` The function key
|
||||
|
||||
The keys can be any single unicode codepoint that your keyboard generates (for example `a`, `0`, `£` or `ç`), or any named key (`tab`, `f1`, `shift`, or `cmd`).
|
||||
The keys can be any single unicode codepoint that your keyboard generates (for example `a`, `0`, `£` or `ç`), or any named key (`tab`, `f1`, `shift`, or `cmd`). If you are using a non-Latin layout (e.g. Cyrillic), you can bind either to the cyrillic character, or the latin character that that key generates with `cmd` pressed.
|
||||
|
||||
A few examples:
|
||||
|
||||
|
@ -89,7 +91,7 @@ For example:
|
|||
|
||||
```
|
||||
# in an editor, it might look like this:
|
||||
Workspace os=macos
|
||||
Workspace os=macos keyboard_layout=com.apple.keylayout.QWERTY
|
||||
Pane
|
||||
Editor mode=full extension=md inline_completion vim_mode=insert
|
||||
|
||||
|
@ -130,6 +132,38 @@ The other kind of conflict that arises is when you have two bindings, one of whi
|
|||
|
||||
When this happens, and both bindings are active in the current context, Zed will wait for 1 second after you tupe `ctrl-w` to se if you're about to type `left`. If you don't type anything, or if you type a different key, then `DeleteToNextWordEnd` will be triggered. If you do, then `DeleteToEndOfLine` will be triggered.
|
||||
|
||||
### Non-QWERTY keyboards
|
||||
|
||||
As of Zed 0.162.0, Zed has some support for non-QWERTY keyboards on macOS. Better support for non-QWERTY keyboards on Linux is planned.
|
||||
|
||||
There are roughly three categories of keyboard to consider:
|
||||
|
||||
Keyboards that support full ASCII (QWERTY, DVORAK, COLEMAK, etc.). On these keyboards bindings are resolved based on the character that would be generated by the key. So to type `cmd-[`, find the key labelled `[` and press it with command.
|
||||
|
||||
Keyboards that are mostly non-ASCII, but support full ASCII when the command key is pressed. For example Cyrillic keyboards, Armenian, Hebrew, etc. On these keyboards bindings are resolved based on the character that would be generated by typing the key with command pressed. So to type `ctrl-a`, find the key that generates `cmd-a`. For these keyboards, keyboard shortcuts are displayed in the app using their ASCII equivalents. If the ASCII-equivalents are not printed on your keyboard, you can use the macOS keyboard viewer and holding down the `cmd` key to find things (though often the ASCII equivalents are in a QWERTY layout).
|
||||
|
||||
Finally keyboards that support extended Latin alphabets (usually ISO keyboards) require the most support. For example French AZERTY, German QWERTZ, etc. On these keyboards it is often not possible to type the entire ASCII range without option. To ensure that shortcuts _can_ be typed without option, keyboard shortcuts are mapped to "key equivalents" in the same way as [macOS](). This mapping is defined per layout, and is a compromise between leaving keyboard shortcuts triggered by the same character they are defined with, keeping shortcuts in the same place as a QWERTY layout, and moving shortcuts out of the way of system shortcuts.
|
||||
|
||||
For example on a German QWERTZ keyboard, the `cmd->` shortcut is moved to `cmd-:` because `cmd->` is the system window switcher and this is where that shortcut is typed on a QWERTY keyboard. `cmd-+` stays the same because + is still typable without option, and as a result, `cmd-[` and `cmd-]` become `cmd-ö` and `cmd-ä`, moving out of the way of the `+` key.
|
||||
|
||||
If you are defining shortcuts in your personal keymap, you can opt-out of the key equivalent mapping by setting `use_layout_keys` to `true` in your keymap:
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"bindings": {
|
||||
"ctrl->": "editor::Indent" // parsed as ctrl-: when a German QWERTZ keyboard is active
|
||||
}
|
||||
},
|
||||
{
|
||||
"use_layout_keys": true,
|
||||
"bindings": {
|
||||
"ctrl->": "editor::Indent" // remains ctrl-> when a German QWERTZ keyboard is active
|
||||
}
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
## Tips and tricks
|
||||
|
||||
### Disabling a binding
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue