mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 01:44:25 +00:00
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:
@@ -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() {
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user