Actions: an inserted Pathfinder effect step holds its Pathfinder Options

Clicking an Effect › Pathfinder item applies the effect with the
Pathfinder Options in force, and effect.apply journals them. Insert
Menu Item now stores the same params in the item's step, so playback
applies the effect as the click did and a later Pathfinder Options
change does not change the step. The effect dialog takes the options
in force from the same helper.
This commit is contained in:
dotCooCoo committed 2026-11-15 09:07:39 -08:00
1 parent 41aa34692b
commit 17bbb52b5b
4 files changed
+66 -12

No files matched your search

+2 -9
View File
@@ -180,15 +180,8 @@ fn fill_pathfinder_options(app: &VectorcraftApp, id: &str, fields: &mut Map<Stri
if !vectorcraft_effects::takes_pathfinder_options(id) {
return;
}
let options = if fresh {
let mut current = app.session.prefs.pathfinder;
if !vectorcraft_effects::PATHFINDER_EFFECT_PRECISION.contains(&current.precision) {
current.precision = vectorcraft_engine::PathfinderOptions::default().precision;
}
json!(current)
} else {
vectorcraft_effects::PathfinderEffectOptions::default().to_params()
};
let options =
if fresh { super::pathfinder_options::options_in_force(app) } else { vectorcraft_effects::PathfinderEffectOptions::default().to_params() };
for (key, v) in options.as_object().into_iter().flatten() {
fields.entry(key.clone()).or_insert_with(|| v.clone());
}
@@ -21,6 +21,36 @@ pub fn open(app: &mut VectorcraftApp) {
app.ui.dialog = Some(Dialog::new(KIND, json!(app.session.prefs.pathfinder)));
}
/// The Pathfinder Options that `effect.apply` gives a new Pathfinder effect: the Pathfinder panel's,
/// with the default precision in place of one out of range.
pub fn options_in_force(app: &VectorcraftApp) -> Value {
let mut current = app.session.prefs.pathfinder;
if !vectorcraft_engine::cmd::PATHFINDER_PRECISION_RANGE.contains(&current.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) {
+31 -2
View File
@@ -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<Value, St
if !items.iter().any(|item| item.command == command && item.params == params) {
return Err("no menu item that can be inserted runs this command".into());
}
let params = if command == "object.align" { super::align::menu_align_params(app, params) } else { params };
let params = match command {
"object.align" => 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]
+3 -1
View File
@@ -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