Merge pull request #8926 from dotCooCoo/fix/soft-mix-rate-same-value

Pathfinder: setting Soft Mix's Mixing Rate to the value it has records no undo step
This commit is contained in:
BFlat
2026-11-22 10:45:51 +07:00
committed by GitHub
2 changed files with 25 additions and 3 deletions
+8 -3
View File
@@ -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()))
+17
View File
@@ -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() {