PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Address CodeRabbit review: shortcut sets leave action alternate keys to the action
David Mann8097063c469a
diff --git a/crates/engine/src/shortcut_sets.rs b/crates/engine/src/shortcut_sets.rsindex c91c3fefc..4b36de1b8 100644--- a/crates/engine/src/shortcut_sets.rs+++ b/crates/engine/src/shortcut_sets.rs@@ -39,7 +39,8 @@ impl ShortcutSet {/// actions, as in an `.atn` file, not to a set).pub fn from_bindings(shortcuts: &BTreeMap<String, String>, alternates: &BTreeMap<String, Vec<String>>) -> Self {let shortcuts = shortcuts.iter().filter(|(id, _)| !is_action_key(id)).map(|(id, k)| (id.clone(), k.clone())).collect();- Self { shortcuts, alternate_shortcuts: alternates.clone() }+ let alternate_shortcuts = alternates.iter().filter(|(id, _)| !is_action_key(id)).map(|(id, k)| (id.clone(), k.clone())).collect();+ Self { shortcuts, alternate_shortcuts }}/// The bindings `p` uses now, without the actions' function keys.@@ -52,7 +53,8 @@ impl ShortcutSet {pub fn apply(&self, shortcuts: &mut BTreeMap<String, String>, alternates: &mut BTreeMap<String, Vec<String>>) {shortcuts.retain(|id, _| is_action_key(id));shortcuts.extend(self.shortcuts.iter().filter(|(id, _)| !is_action_key(id)).map(|(id, k)| (id.clone(), k.clone())));- *alternates = self.alternate_shortcuts.clone();+ alternates.retain(|id, _| is_action_key(id));+ alternates.extend(self.alternate_shortcuts.iter().filter(|(id, _)| !is_action_key(id)).map(|(id, k)| (id.clone(), k.clone())));}/// Use this set's bindings in `p`, keeping the actions' function keys.@@ -349,6 +351,27 @@ mod tests {assert!(p.shortcut_sets.values().all(|s| s.shortcuts.is_empty()), "a saved set holds no action keys");}+ #[test]+ fn switching_sets_keeps_action_alternate_keys() {+ // An action key set as an alternate (`alternateShortcuts.actions.play:<name>`) is the+ // action's too: a saved set leaves it out and switching sets keeps it.+ let mut p = prefs();+ p.alternate_shortcuts.insert("edit.copy".into(), vec!["F9".into()]);+ p.alternate_shortcuts.insert("actions.play:Sepia".into(), vec!["F7".into()]);+ store(&mut p, &json!({"saveSet": "Mine"})).unwrap();+ assert_eq!(p.shortcut_sets["Mine"].alternate_shortcuts, BTreeMap::from([("edit.copy".to_string(), vec!["F9".to_string()])]));+ load(&mut p, &json!({"useSet": ""})).unwrap();+ assert_eq!(p.alternate_shortcuts, BTreeMap::from([("actions.play:Sepia".to_string(), vec!["F7".to_string()])]), "kept switching to the defaults");+ let sets = json!({"Other": {"alternateShortcuts": {"edit.cut": ["F8"], "actions.play:Old": ["F6"]}}});+ store(&mut p, &json!({"sets": sets})).unwrap();+ load(&mut p, &json!({"useSet": "Other"})).unwrap();+ assert_eq!(+ p.alternate_shortcuts,+ BTreeMap::from([("actions.play:Sepia".to_string(), vec!["F7".to_string()]), ("edit.cut".to_string(), vec!["F8".to_string()])]),+ "a set from the dialog brings no action key and keeps the one in use"+ );+ }+#[test]fn bad_names_sets_and_params_are_errors() {let mut p = prefs();