PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Merge PR #7015: Actions: deleting an action removes its function key (#7014)
aiongg1d567a115f02
diff --cc crates/engine/src/actions_cmds.rsindex be0ad7ab1,955539415..2cc9c1f29--- a/crates/engine/src/actions_cmds.rs+++ b/crates/engine/src/actions_cmds.rs@@@ -792,29 -776,22 +799,45 @@@ mod testsassert_eq!(s.actions.list[0].name, "Sepia");}+ #[test]+ fn rename_follows_conditional_branches() {+ let mut s = Session::new();+ s.execute("file.new", json!({"width": 8, "height": 8})).unwrap();+ for name in ["B", "Other"] {+ s.actions.list.push(Action { name: name.into(), steps: vec![("layer.new.layer".into(), json!({}))], ..Default::default() });+ }+ s.actions.list.push(Action {+ name: "Main".into(),+ steps: vec![+ ("actions.conditional".into(), json!({"if": "always", "then": "B", "else": "Other"})),+ ("actions.conditional".into(), json!({"if": "never", "then": "Other", "else": "B"})),+ ],+ ..Default::default()+ });+ s.execute("actions.rename", json!({"action": "B", "name": "C"})).unwrap();+ let steps = &s.actions.list[2].steps;+ assert_eq!(steps[0].1, json!({"if": "always", "then": "C", "else": "Other"}));+ assert_eq!(steps[1].1, json!({"if": "never", "then": "Other", "else": "C"}));+ let r = s.execute("actions.play", json!({"action": "Main"})).unwrap();+ assert!(r.get("failed").is_none(), "{r}");+ }++ #[test]+ fn delete_action_drops_its_function_key_but_deleting_a_step_keeps_it() {+ let mut s = Session::new();+ let key = format!("{PLAY_SHORTCUT_PREFIX}Action 1");+ s.actions.list.push(Action::new("Action 1", vec![("layer.new.layer".into(), json!({})), ("layer.new.layer".into(), json!({}))]));+ s.edit_prefs(|p| p.shortcuts.insert(key.clone(), "F2".into()));+ s.execute("actions.delete", json!({"action": 0, "step": 0})).unwrap();+ assert_eq!(s.prefs().shortcuts.get(&key).map(String::as_str), Some("F2"), "deleting a step keeps the key");+ assert_eq!(s.execute("actions.delete", json!({"action": 0})).unwrap()["deleted"], "Action 1");+ assert!(!s.prefs().shortcuts.contains_key(&key), "the deleted action's function key is gone");+ s.execute("actions.record", json!({})).unwrap();+ s.execute("actions.stop", json!({})).unwrap();+ assert_eq!(s.actions.list[0].name, "Action 1");+ assert!(!s.prefs().shortcuts.contains_key(&key), "a new action with the same name starts unbound");+ }+fn record_red(s: &mut Session, depth: u32) {s.execute("file.new", json!({"width": 40, "height": 40, "depth": depth})).unwrap();s.execute("actions.record", json!({"name": "Red"})).unwrap();