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](https://github.com/zed-industries/zed/blob/a890df1863ca939ee7f0ada6e629b6f83eb18bc5/crates/settings/src/key_equivalents.rs#L7). --------- Co-authored-by: Will <will@zed.dev>
This commit is contained in:
@@ -808,6 +808,7 @@ pub fn handle_keymap_file_changes(
|
||||
VimModeSetting::register(cx);
|
||||
|
||||
let (base_keymap_tx, mut base_keymap_rx) = mpsc::unbounded();
|
||||
let (keyboard_layout_tx, mut keyboard_layout_rx) = mpsc::unbounded();
|
||||
let mut old_base_keymap = *BaseKeymap::get_global(cx);
|
||||
let mut old_vim_enabled = VimModeSetting::get_global(cx).0;
|
||||
cx.observe_global::<SettingsStore>(move |cx| {
|
||||
@@ -822,6 +823,11 @@ pub fn handle_keymap_file_changes(
|
||||
})
|
||||
.detach();
|
||||
|
||||
cx.on_keyboard_layout_change(move |_| {
|
||||
keyboard_layout_tx.unbounded_send(()).ok();
|
||||
})
|
||||
.detach();
|
||||
|
||||
load_default_keymap(cx);
|
||||
|
||||
cx.spawn(move |cx| async move {
|
||||
@@ -829,6 +835,7 @@ pub fn handle_keymap_file_changes(
|
||||
loop {
|
||||
select_biased! {
|
||||
_ = base_keymap_rx.next() => {}
|
||||
_ = keyboard_layout_rx.next() => {}
|
||||
user_keymap_content = user_keymap_file_rx.next() => {
|
||||
if let Some(user_keymap_content) = user_keymap_content {
|
||||
match KeymapFile::parse(&user_keymap_content) {
|
||||
@@ -854,7 +861,7 @@ fn reload_keymaps(cx: &mut AppContext, keymap_content: &KeymapFile) {
|
||||
load_default_keymap(cx);
|
||||
keymap_content.clone().add_to_cx(cx).log_err();
|
||||
cx.set_menus(app_menus());
|
||||
cx.set_dock_menu(vec![MenuItem::action("New Window", workspace::NewWindow)])
|
||||
cx.set_dock_menu(vec![MenuItem::action("New Window", workspace::NewWindow)]);
|
||||
}
|
||||
|
||||
pub fn load_default_keymap(cx: &mut AppContext) {
|
||||
|
||||
Reference in New Issue
Block a user