mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-05 21:42:59 -05:00
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.
This commit is contained in:
1 parent
a7a5bfff70
commit
82dd6df8b6
2 files changed
+24
-1
No files matched your search
@@ -824,7 +824,8 @@ fn profile_delete(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
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 }))
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user