windows: Fix keystroke & keymap (#36572)

Closes #36300

This PR follows Windows conventions by introducing
`KeybindingKeystroke`, so shortcuts now show up as `ctrl-shift-4`
instead of `ctrl-$`.

It also fixes issues with keyboard layouts: when `use_key_equivalents`
is set to true, keys are remapped based on their virtual key codes. For
example, `ctrl-\` on a standard English layout will be mapped to
`ctrl-ё` on a Russian layout.


Release Notes:

- N/A

---------

Co-authored-by: Kate <kate@zed.dev>
This commit is contained in:
张小白 2025-08-27 03:24:50 +08:00 committed by GitHub
parent b1b60bb7fe
commit fff0ecead1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 3515 additions and 1721 deletions

View file

@ -1308,11 +1308,11 @@ pub fn handle_keymap_file_changes(
})
.detach();
let mut current_mapping = settings::get_key_equivalents(cx.keyboard_layout().id());
let mut current_layout_id = cx.keyboard_layout().id().to_string();
cx.on_keyboard_layout_change(move |cx| {
let next_mapping = settings::get_key_equivalents(cx.keyboard_layout().id());
if next_mapping != current_mapping {
current_mapping = next_mapping;
let next_layout_id = cx.keyboard_layout().id();
if next_layout_id != current_layout_id {
current_layout_id = next_layout_id.to_string();
keyboard_layout_tx.unbounded_send(()).ok();
}
})
@ -4729,7 +4729,7 @@ mod tests {
// and key strokes contain the given key
bindings
.into_iter()
.any(|binding| binding.keystrokes().iter().any(|k| k.key == key)),
.any(|binding| binding.keystrokes().iter().any(|k| k.display_key == key)),
"On {} Failed to find {} with key binding {}",
line,
action.name(),

View file

@ -72,7 +72,10 @@ impl QuickActionBar {
Tooltip::with_meta(
tooltip_text,
Some(open_action_for_tooltip),
format!("{} to open in a split", text_for_keystroke(&alt_click, cx)),
format!(
"{} to open in a split",
text_for_keystroke(&alt_click.modifiers, &alt_click.key, cx)
),
window,
cx,
)