From 82dd6df8b68e2f0c8a8d886a2636a873c1887c4b Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 5 Dec 2026 14:36:00 -0800 Subject: [PATCH] Width profiles: deleting a profile clears an order that is back to the default Deleting a saved profile kept only the stored ids, so a profile saved after the last move was missing from the order passed to set_profile_order and the default order stayed stored. Delete now builds the whole list as it shows and stores it only when it differs from the default. --- crates/engine/src/cmd/stroke.rs | 3 ++- crates/engine/src/tests/widthprofiles.rs | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/stroke.rs b/crates/engine/src/cmd/stroke.rs index bedfadd6c4..9978cfab91 100644 --- a/crates/engine/src/cmd/stroke.rs +++ b/crates/engine/src/cmd/stroke.rs @@ -824,7 +824,8 @@ fn profile_delete(s: &mut Session, p: &Value) -> Result { s.prefs.width_profiles.remove(i); // A profile saved later under the same name goes to the end of the list, not to this one's place. if !s.prefs.width_profile_order.is_empty() { - let order = s.prefs.width_profile_order.iter().filter(|id| **id != name).cloned().collect(); + // The whole list as it now shows, so an order that matches the default is no longer stored. + let order = s.profile_entries().skip(1).map(|e| e.id.to_string()).collect(); set_profile_order(s, order); } Ok(json!({ "deleted": name })) diff --git a/crates/engine/src/tests/widthprofiles.rs b/crates/engine/src/tests/widthprofiles.rs index 48fe1a6e78..3c39c96a64 100644 --- a/crates/engine/src/tests/widthprofiles.rs +++ b/crates/engine/src/tests/widthprofiles.rs @@ -233,6 +233,28 @@ fn a_deleted_profile_leaves_the_order_and_a_new_one_goes_last() { assert_eq!(listed(&mut s), ["uniform", "wave", "lens", "taperStart", "taperEnd", "pinch", "teardrop", "Mine"]); } +#[test] +fn deleting_the_only_moved_profile_clears_the_stored_order() { + let (mut s, id) = session_with_line(); + set_profile(&mut s, id, custom()); + s.execute("stroke.widthProfile.add", &json!({"name": "Alpha"})).unwrap(); + s.execute("stroke.widthProfile.move", &json!({"name": "Alpha", "to": 0})).unwrap(); + // Beta is saved after the move, so the stored order does not name it. + set_profile(&mut s, id, WidthProfile { points: vec![(0.0, 1.0, 0.0), (1.0, 0.0, 1.0)] }); + s.execute("stroke.widthProfile.add", &json!({"name": "Beta"})).unwrap(); + s.execute("stroke.widthProfile.delete", &json!({"name": "Alpha"})).unwrap(); + assert!(s.prefs.width_profile_order.is_empty(), "{:?}", s.prefs.width_profile_order); + assert_eq!(listed(&mut s).last().map(String::as_str), Some("Beta")); + + // A real custom order is kept after a delete. + s.execute("stroke.widthProfile.move", &json!({"name": "Beta", "to": 0})).unwrap(); + set_profile(&mut s, id, WidthProfile { points: vec![(0.0, 0.5, 0.5), (1.0, 1.0, 1.0)] }); + s.execute("stroke.widthProfile.add", &json!({"name": "Gamma"})).unwrap(); + s.execute("stroke.widthProfile.delete", &json!({"name": "Gamma"})).unwrap(); + assert_eq!(listed(&mut s)[1], "Beta"); + assert!(!s.prefs.width_profile_order.is_empty()); +} + #[test] fn every_built_in_applies_and_the_params_doc_names_them() { let (mut s, id) = session_with_line();