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:
Conrad Irwin 2024-11-08 13:05:10 -07:00 committed by GitHub
parent 07821083df
commit ff4f67993b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 435 additions and 10 deletions

View file

@ -546,7 +546,6 @@ impl InputExample {
impl Render for InputExample {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
let num_keystrokes = self.recent_keystrokes.len();
div()
.bg(rgb(0xaaaaaa))
.track_focus(&self.focus_handle(cx))
@ -561,7 +560,7 @@ impl Render for InputExample {
.flex()
.flex_row()
.justify_between()
.child(format!("Keystrokes: {}", num_keystrokes))
.child(format!("Keyboard {}", cx.keyboard_layout()))
.child(
div()
.border_1()
@ -607,6 +606,7 @@ fn main() {
KeyBinding::new("end", End, None),
KeyBinding::new("ctrl-cmd-space", ShowCharacterPalette, None),
]);
let window = cx
.open_window(
WindowOptions {
@ -642,6 +642,13 @@ fn main() {
.unwrap();
})
.detach();
cx.on_keyboard_layout_change({
move |cx| {
window.update(cx, |_, cx| cx.notify()).ok();
}
})
.detach();
window
.update(cx, |view, cx| {
cx.focus_view(&view.text_input);