PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Merge remote-tracking branch 'upstream/main' into atn-duplicate-inplace
Kushagra Saxena8f2f4220db57
diff --cc contributors/people.tomlindex a61b8ff6b,bc3533777..33e6aa12f--- a/contributors/people.toml+++ b/contributors/people.toml@@@ -173,5 -179,5 +179,8 @@@ sync_github_name = fals[people.Byxis]sync_github_name = true+ [people.00xJS]+ sync_github_name = true+++[people.ksaxena149]+sync_github_name = truediff --cc crates/engine/src/atn_cmds/tests.rsindex 60fe381da,26865d406..19dd91ef4--- a/crates/engine/src/atn_cmds/tests.rs+++ b/crates/engine/src/atn_cmds/tests.rs@@@ -1090,20 -1343,47 +1343,65 @@@ fn add_noise_with_mask_target_is_not_ex}}+/// Photoshop's Duplicate Layer has no in-place flag: an in-place duplicate (the artboard copy+/// that stays on the original) must not be exported as a plain duplicate, which places the+/// copy beside the original on playback.+#[test]+fn duplicate_in_place_is_not_exported_as_plain_duplicate() {+ let in_place = Action { name: "Probe".into(), steps: vec![("layer.duplicate".into(), json!({"inPlace": true}))], ..Default::default() };+ assert!(export("Audit5", &[&in_place], &[], false).is_err());+ let (_, skipped) = export("Audit5", &[&in_place], &[], true).unwrap();+ assert_eq!(skipped, vec![Skipped { action: "Probe".into(), step: 0, id: "layer.duplicate".into() }]);+ for params in [json!({}), json!({"inPlace": false})] {+ let plain = Action { name: "Plain".into(), steps: vec![("layer.duplicate".into(), params)], ..Default::default() };+ let (bytes, skipped) = export("Audit5", &[&plain], &[], false).unwrap();+ assert!(skipped.is_empty());+ let imported = import(&bytes).unwrap();+ assert_eq!(imported.actions[0].steps, vec![("layer.duplicate".to_string(), json!({}))]);+ }+}+++ /// A Play Action that starts the called action at a later step must not export as a call of the+ /// whole action: that would replay the steps the recording deliberately skipped.+ #[test]+ fn partial_play_action_is_not_exported_as_whole_action_call() {+ let partial = Action { name: "Parent".into(), steps: vec![("actions.play".into(), json!({"action": "Child", "from": 1}))], ..Default::default() };+ assert!(export("Set", &[&partial], &[], false).is_err());+ let (_, skipped) = export("Set", &[&partial], &[], true).unwrap();+ assert_eq!(skipped, vec![Skipped { action: "Parent".into(), step: 0, id: "actions.play".into() }]);+ for params in [json!({"action": "Child"}), json!({"action": "Child", "from": 0})] {+ let whole = Action { name: "Parent".into(), steps: vec![("actions.play".into(), params)], ..Default::default() };+ let (bytes, skipped) = export("Set", &[&whole], &[], false).unwrap();+ assert!(skipped.is_empty());+ let imported = import(&bytes).unwrap();+ assert_eq!(imported.actions[0].steps, vec![("actions.play".to_string(), json!({"action": "Child"}))]);+ }+ }++ /// #7646: an action's function key keeps Photoshop's Shift and Command options through+ /// `.atn` load and save, as `Shift+F5`, `Cmd+F5` and `Cmd+Shift+F5` shortcuts.+ #[test]+ fn function_keys_keep_shift_and_command() {+ let mut file = sample();+ file.actions[1].function_key = 5;+ file.actions[1].shift = true;+ file.actions[1].command = true;+ file.actions[0].shift = true;+ let mut s = Session::new();+ let r = s.execute("actions.load", json!({"data": b64(&atn::write(&file).unwrap())})).unwrap();+ assert_eq!(r["functionKeys"], json!([{"action": "Soften", "key": "Shift+F3"}, {"action": "Finish", "key": "Cmd+Shift+F5"}]));+ let shortcuts = &s.prefs().shortcuts;+ assert_eq!(shortcuts.get("actions.play:Soften").map(String::as_str), Some("Shift+F3"));+ assert_eq!(shortcuts.get("actions.play:Finish").map(String::as_str), Some("Cmd+Shift+F5"));+ let r = s.execute("actions.save", json!({"set": "Test Set"})).unwrap();+ let saved = atn::parse(&photocraft_paint::tile::b64_decode(r["data"].as_str().unwrap()).unwrap()).unwrap();+ let keys: Vec<_> = saved.actions.iter().map(|a| (a.function_key, a.shift, a.command)).collect();+ assert_eq!(keys, [(3, true, false), (5, true, true)]);++ assert_eq!(super::parse_function_key("Cmd+F12"), Some((12, false, true)));+ assert_eq!(super::parse_function_key("Shift+Cmd+F2"), Some((2, true, true)));+ for bad in ["F16", "F0", "Alt+F2", "Cmd+Cmd+F2", "Shift+", "Cmd+K", ""] {+ assert_eq!(super::parse_function_key(bad), None, "{bad}");+ }+ assert_eq!(super::function_key_name(7, false, false), "F7");+ }diff --cc crates/engine/src/jobs.rsindex 504fe3a01,0ee057317..86443ca50--- a/crates/engine/src/jobs.rs+++ b/crates/engine/src/jobs.rs@@@ -800,8 -842,9 +842,10 @@@ impl Session}if !crate::brush_cmds::coalesce_journal(self, id, ¶ms) {let params = match id {- "layer.select" if self.actions.recording.is_some() => crate::layer_multi_cmds::recorded_selection(self, params),- "layer.duplicate" if self.actions.recording.is_some() => crate::artboard_cmds::recorded_duplicate(self, params),+ _ if self.actions.recording.is_none() => params,+ "layer.select" => crate::layer_multi_cmds::recorded_selection(self, params),++ "layer.duplicate" => crate::artboard_cmds::recorded_duplicate(self, params),+ "layerComp.apply" => crate::comps_cmds::recorded_apply(self, params),_ => params,};self.journal.push((id.to_string(), params));