diff --git a/crates/ui-egui/src/dialogs/effect.rs b/crates/ui-egui/src/dialogs/effect.rs index 3bc24b0d9d..d5d2260ee1 100644 --- a/crates/ui-egui/src/dialogs/effect.rs +++ b/crates/ui-egui/src/dialogs/effect.rs @@ -180,15 +180,8 @@ fn fill_pathfinder_options(app: &VectorcraftApp, id: &str, fields: &mut Map Value { + let mut current = app.session.prefs.pathfinder; + if !vectorcraft_engine::cmd::PATHFINDER_PRECISION_RANGE.contains(¤t.precision) { + current.precision = vectorcraft_engine::PathfinderOptions::default().precision; + } + json!(current) +} + +/// The params that an Effect › Pathfinder menu item with params `p` (`effect.apply`) runs with: its +/// `params` with the Pathfinder Options in force ([`options_in_force`]) added where they are +/// missing, as `effect.apply` journals them. Insert Menu Item stores the same params as the item's +/// step. Params of any other effect are returned unchanged. +pub fn menu_effect_params(app: &VectorcraftApp, mut p: Value) -> Value { + if !p.get("effect").and_then(Value::as_str).is_some_and(vectorcraft_effects::takes_pathfinder_options) { + return p; + } + let options = options_in_force(app); + if let Some(o) = p.as_object_mut() { + let params = o.entry("params").or_insert_with(|| json!({})); + if let (Some(params), Some(options)) = (params.as_object_mut(), options.as_object()) { + for (key, v) in options { + params.entry(key.clone()).or_insert_with(|| v.clone()); + } + } + } + p +} + fn check(ui: &mut egui::Ui, d: &mut Dialog, key: &str, text: &str) { let v = d.bool(key); if widgets::check(ui, text, v, true) { diff --git a/crates/ui-egui/src/panels/actions.rs b/crates/ui-egui/src/panels/actions.rs index a7f32611cc..76aec85630 100644 --- a/crates/ui-egui/src/panels/actions.rs +++ b/crates/ui-egui/src/panels/actions.rs @@ -1159,7 +1159,10 @@ pub const INSERT_MENU_ITEM: &str = "ui.action.insertMenuItem"; /// runs. An Object › Align item's step holds the params that clicking the item sends now /// ([`crate::panels::align::menu_align_params`]): with whole objects selected, the `to` of the key /// object, the artboard or the selection, so a later Align To choice does not change the step, and a -/// step that aligns to the key object fails in playback when there is none then. A View menu item that the app runs itself +/// step that aligns to the key object fails in playback when there is none then. An Effect › +/// Pathfinder item's step holds the Pathfinder Options in force now +/// ([`crate::dialogs::pathfinder_options::menu_effect_params`]), as clicking the item applies the +/// effect with them, so a later Pathfinder Options change does not change the step. A View menu item that the app runs itself /// ([`crate::menus::plays_in_app`]) plays on its own, with no undo step ([`play`]). The place is as /// [`insert_stop`] takes it, and the step is selected as a stop is. A command and params that no such /// item has, a param of another type, params that are not an object, or a place [`insert_stop`] @@ -1179,7 +1182,11 @@ pub fn insert_menu_item(app: &mut VectorcraftApp, p: &Value) -> Result super::align::menu_align_params(app, params), + "effect.apply" => crate::dialogs::pathfinder_options::menu_effect_params(app, params), + _ => params, + }; insert(app, p, (command.to_string(), params)) } @@ -5652,6 +5659,28 @@ mod tests { assert_eq!(steps[4], ("object.align".to_string(), json!({"horizontal": "left", "to": "selection"}))); } + /// An Effect › Pathfinder item's step holds the Pathfinder Options in force at insertion, as the + /// click applies the effect with them: a later Pathfinder Options change does not change the step, + /// and playback applies the effect with the step's options. + #[test] + fn an_inserted_pathfinder_effect_item_keeps_the_pathfinder_options_of_its_insertion() { + let (mut app, _, ids) = app_with_two_rectangles(); + app.run("select.set", json!({ "ids": ids })).unwrap(); + app.run("object.pathfinder.options", json!({"precision": 0.5, "removeRedundantPoints": true})).unwrap(); + app.ui.action_sets[0].actions[0].steps.clear(); + app.run(INSERT_MENU_ITEM, json!({"set": 0, "action": 0, "command": "effect.apply", "params": {"effect": "pathfinder.add"}})).unwrap(); + app.run("object.pathfinder.options", json!({"precision": 0.01, "removeRedundantPoints": false})).unwrap(); + let options = json!({"precision": 0.5, "removeRedundantPoints": true, "removeUnpainted": false}); + let held = json!({"effect": "pathfinder.add", "params": options}); + assert_eq!(app.ui.action_sets[0].actions[0].steps, [("effect.apply".to_string(), held)]); + app.run("select.set", json!({ "ids": ids })).unwrap(); + app.run("object.group", json!({})).unwrap(); + play(&mut app, 0, 0).unwrap(); + let group = app.session.doc().unwrap().selection.objects[0]; + let effects = &app.session.doc().unwrap().doc.node(group).unwrap().appearance.effects; + assert_eq!((effects.len(), effects[0].id.as_str(), &effects[0].params), (1, "pathfinder.add", &options)); + } + /// With anchor points selected, an Object › Align item sends its params unchanged, and the points /// align to their own bounds: its step holds the same params, without the Align To choice. #[test] diff --git a/docs/mcp.md b/docs/mcp.md index 6840acd1c4..8703a01d05 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -3590,7 +3590,9 @@ already walks Image Trace. Short agent entry points: keeps the `to` its click sends at insertion (`key` while the selection has a key object or key guide, `artboard` for one selected object or with Align to Artboard, else `selection`), so a later Align To choice does not change it, and a step that aligns to the key object fails in playback when the selection has no key then. With anchor points selected the click - sends no `to`, and neither does the step. These are VectorCraft's own rules. A + sends no `to`, and neither does the step. An Effect › Pathfinder item's step holds the Pathfinder Options in force at + insertion (`precision`, `removeRedundantPoints` and `removeUnpainted` in its `params`), as its click applies the + effect with them, so a later Pathfinder Options change does not change it. These are VectorCraft's own rules. A View menu step plays as `ui.action.play` describes. With `set` and `action`, the step goes into that action, after step `step`, else after its last step, becomes the panel's selected step, and the command returns `{set, action, step}`. Without them it goes into the recording in progress and returns