Skip to content

Visual Studio Code, rebuilt in Rust

Rust

fix(windows): read extension keybindings by the platform key

rokarturae78ba129c46
diff --git a/native/crates/app/src/workbench/extension_features.rs b/native/crates/app/src/workbench/extension_features.rs
index 3d1116d60e2..31f76ca59d9 100644
--- a/native/crates/app/src/workbench/extension_features.rs
+++ b/native/crates/app/src/workbench/extension_features.rs
@@ -275,8 +275,10 @@ fn commands_table(contributes: &Value) -> FeatureData {
rule => vec![rule],
};
for rule in keybindings {
- // `resolveUserBinding(mac ?? key)[0]`: a key that does not parse resolves to nothing.
- let key = rule.get("mac").and_then(Value::as_str).or_else(|| rule["key"].as_str()).unwrap_or_default();
+ // menusExtensionPoint.ts `resolveKeybinding`: `resolveUserBinding(win, linux or mac ?? key)[0]`; a key that
+ // does not parse resolves to nothing.
+ let platform_key = if cfg!(target_os = "macos") { "mac" } else if cfg!(windows) { "win" } else { "linux" };
+ let key = rule.get(platform_key).and_then(Value::as_str).or_else(|| rule["key"].as_str()).unwrap_or_default();
let chords = crate::keybindings::parse_keybinding(key);
if chords.is_empty() {
continue;
diff --git a/native/crates/app/src/workbench/extension_features/tests.rs b/native/crates/app/src/workbench/extension_features/tests.rs
index c94b57598fd..8e1b3f2b493 100644
--- a/native/crates/app/src/workbench/extension_features/tests.rs
+++ b/native/crates/app/src/workbench/extension_features/tests.rs
@@ -86,7 +86,8 @@ fn commands_list_their_keybindings_and_menus_with_the_implicit_command_palette()
assert_eq!(rows[1][3], markdown("`commandPalette` `editor/title`"));
let Cell::Keybindings(keybindings) = &rows[1][2] else { panic!("the keybindings cell") };
assert_eq!(keybindings.len(), 1);
- assert!(keybindings[0][0].contains(&"⌘".to_owned()), "the mac key wins: {keybindings:?}");
+ let platform_key = if cfg!(target_os = "macos") { "⌘" } else { "Ctrl" };
+ assert!(keybindings[0][0].contains(&platform_key.to_owned()), "the platform's key wins: {keybindings:?}");
assert_eq!(rows[2][1], text(""));
}