Shortcut import keeps only a command's main default key first, so a set's own main key and default alternates round-trip

This commit is contained in:
aiongg
2026-11-16 23:36:04 +00:00
parent 79a5564061
commit 2b8741d72c
2 changed files with 5 additions and 7 deletions
+3 -5
View File
@@ -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() {
+2 -2
View File
@@ -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());