From 2b8741d72c4c66ee71ff3a785bfbb0335c679578 Mon Sep 17 00:00:00 2001 From: aiongg Date: Mon, 16 Nov 2026 23:36:04 +0000 Subject: [PATCH] Shortcut import keeps only a command's main default key first, so a set's own main key and default alternates round-trip --- crates/keymap/src/import.rs | 8 +++----- crates/keymap/tests/import.rs | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/crates/keymap/src/import.rs b/crates/keymap/src/import.rs index 13f031e57..66bb172d0 100644 --- a/crates/keymap/src/import.rs +++ b/crates/keymap/src/import.rs @@ -639,14 +639,12 @@ pub fn plan(set: &ForeignSet, keymap: &Keymap, options: &ImportOptions) -> Impor } } - // A key the command already has by default stays its main key: the keys of the set follow the defaults in their order. + // The command's own main default key, when the set lists it, stays the main key; the set's other keys (default alternates included) keep their order. for p in &mut commands { let Some(home) = keymap.bindable(&p.command).map(|b| b.scope.clone()) else { continue }; let defaults = keymap.default_bindings(&p.command); - let rank = |b: &PlannedBinding| { - defaults.iter().position(|d| d.trigger == b.binding.trigger && d.scope_or(&home) == b.binding.scope_or(&home)).unwrap_or(usize::MAX) - }; - p.bindings.sort_by_key(rank); + let Some(main) = defaults.first() else { continue }; + p.bindings.sort_by_key(|b| !(main.trigger == b.binding.trigger && main.scope_or(&home) == b.binding.scope_or(&home))); } if !to_suggest.is_empty() { diff --git a/crates/keymap/tests/import.rs b/crates/keymap/tests/import.rs index 93e1383ed..6aaa67047 100644 --- a/crates/keymap/tests/import.rs +++ b/crates/keymap/tests/import.rs @@ -284,9 +284,9 @@ fn tool_keys_match_by_name_or_id_and_take_one_letter() { assert_eq!(unmatched, [("Copy", UnmatchedReason::NoMatch), ("Imaginary Tool", UnmatchedReason::NoMatch)]); } -/// A key the command has by default stays its main key, whichever order the set lists its keys in. +/// A command's main default key stays its main key, whichever order the set lists its keys in. #[test] -fn a_default_key_among_the_sets_keys_stays_first() { +fn the_main_default_key_among_the_sets_keys_stays_first() { let km = keymap(Platform::Mac); let set = ForeignSet::new(vec![win("File", &["Save"], &[("Default", "Ctrl+Alt+S"), ("Default", "Ctrl+S")])]); let planned = plan(&set, &km, &windows_options());