From 12fd6872cc8e469b71e28aee2e0d6b1b37137b25 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 20 Nov 2026 20:22:14 -0800 Subject: [PATCH] Pathfinder: setting Soft Mix's Mixing Rate to the value it has records no undo step effect.setParams compared a Pathfinder effect's values other than its Pathfinder Options exactly, so a mixingRate of 50 over a stored 50.0 counted as an edit and recorded an undo step. A float now compares with any number by value, and two integers still compare exactly. --- crates/engine/src/cmd/effectcmd.rs | 11 ++++++++--- crates/engine/src/tests/pathops.rs | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/cmd/effectcmd.rs b/crates/engine/src/cmd/effectcmd.rs index edb5561796..5638f76749 100644 --- a/crates/engine/src/cmd/effectcmd.rs +++ b/crates/engine/src/cmd/effectcmd.rs @@ -927,7 +927,8 @@ fn bevel_effect(id: &str) -> bool { /// Options ([`effects::PathfinderEffectOptions`], so an effect saved without them and given their /// defaults is unchanged), each option given equal to the one it stores (a precision that Scale /// Strokes & Effects took past its range evaluates at the bound but is still edited), and every -/// other value given equal to the one it has? +/// other value given equal to the one it has (a number by its value, so a Soft Mix `mixingRate` of 50 +/// over a stored 50.0 is unchanged)? fn pathfinder_edit_changes_nothing(e: &Effect, params: &Value) -> bool { if !effects::takes_pathfinder_options(&e.id) { return false; @@ -938,8 +939,12 @@ fn pathfinder_edit_changes_nothing(e: &Effect, params: &Value) -> bool { if let Value::Object(m) = &mut after { m.extend(given.clone()); } - let others_same = given.iter().filter(|(k, _)| !effects::PATHFINDER_OPTION_KEYS.contains(&k.as_str())).all(|(k, v)| current.get(k) == Some(v)); - let same_value = |a: &Value, b: &Value| a == b || a.as_f64().is_some_and(|x| b.as_f64() == Some(x)); + // Two integers compare exactly, and a float compares with any number by value. + let same_value = |a: &Value, b: &Value| a == b || ((a.is_f64() || b.is_f64()) && a.as_f64().is_some_and(|x| b.as_f64() == Some(x))); + let others_same = given + .iter() + .filter(|(k, _)| !effects::PATHFINDER_OPTION_KEYS.contains(&k.as_str())) + .all(|(k, v)| current.get(k).is_some_and(|c| same_value(c, v))); let stored_same = given .iter() .filter(|(k, _)| effects::PATHFINDER_OPTION_KEYS.contains(&k.as_str())) diff --git a/crates/engine/src/tests/pathops.rs b/crates/engine/src/tests/pathops.rs index feb71e40ad..4ebc8206f5 100644 --- a/crates/engine/src/tests/pathops.rs +++ b/crates/engine/src/tests/pathops.rs @@ -2067,6 +2067,23 @@ fn a_precision_set_after_a_scale_past_its_range_is_kept() { assert_eq!(s.doc().unwrap().history.undo.len(), steps); } +/// Soft Mix's Mixing Rate is compared by value: 50 over a stored 50.0 records no undo step, and 51 +/// is an edit. +#[test] +fn a_soft_mix_rate_set_to_its_value_records_no_step() { + let mut s = session(); + let (a, b) = (rect(&mut s, 0.0, 0.0, 100.0, 100.0), rect(&mut s, 50.0, 50.0, 100.0, 100.0)); + s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap(); + s.execute("effect.apply", &json!({"effect": "pathfinder.softMix", "params": {"mixingRate": 50.0}})).unwrap(); + assert_eq!(first_effect_params(&s)["mixingRate"], json!(50.0)); + let steps = |s: &Session| s.doc().unwrap().history.undo.len(); + let before = steps(&s); + assert_eq!(s.execute("effect.setParams", &json!({"index": 0, "params": {"mixingRate": 50}})).unwrap(), json!({"ids": []})); + assert_eq!((first_effect_params(&s)["mixingRate"].clone(), steps(&s)), (json!(50.0), before), "50 over 50.0: no step"); + assert_ne!(s.execute("effect.setParams", &json!({"index": 0, "params": {"mixingRate": 51}})).unwrap(), json!({"ids": []})); + assert_eq!((first_effect_params(&s)["mixingRate"].clone(), steps(&s)), (json!(51), before + 1), "51 is an edit"); +} + /// A single group containing multiple overlapping paths is accepted by Crop. #[test] fn crop_operates_on_a_single_selected_group_of_paths() {