Layer states: layerstate.save replaces a state named in another case

This PR makes layerstate.restore, rename and delete find a state's name
without regard to case, as AutoCAD 2024 does, but layerstate.save still
replaced only a state of the same spelling, so saving s1 next to S1 made
a second state that the lookups then had to choose between. AutoCAD
keeps one state per name in any case: its -LAYER stAte Save and
layerstate-save refuse s1 after S1 and keep S1 (measured; layerstate-has
"s1" is T). -LAYER stAte Save here already refuses; the JSON command now
replaces a state whose name differs only in case, as it replaces one of
the same spelling.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2ez4gcx
2026-11-09 22:47:03 +07:00
co-authored by Claude Opus 5.5
parent 60fc6e7b40
commit f8be7d8339
2 changed files with 11 additions and 2 deletions
+5 -1
View File
@@ -413,7 +413,11 @@ fn run_state_save(s: &mut Session, p: &Value) -> Result<Value> {
let d = s.doc_mut()?;
let layers = d.layers.clone();
let current = d.header.str("CLAYER", "0");
d.layer_states.retain(|st| st.name != name);
// A state of this name in any case is replaced, so a drawing keeps one state per name, as in
// AutoCAD 2024, which finds states without regard to case. AutoCAD's -LAYER stAte Save and
// layerstate-save refuse `s1` after `S1` and keep `S1` (measured), as the command line here
// does; this command replaces instead, as it does a state of the same spelling.
d.layer_states.retain(|st| !st.name.eq_ignore_ascii_case(&name));
d.layer_states.push(S { mask, ..S::new(name, layers, current) });
ok()
}
@@ -221,8 +221,13 @@ fn json_layer_states_take_a_mask_and_find_names_in_any_case() {
s.execute("layerstate.rename", &json!({ "from": "m", "to": "M2" })).unwrap();
s.execute("layerstate.delete", &json!({ "name": "on" })).unwrap();
assert_eq!(states(&s), [state("M2", LayerState::ALL)]);
// Names that differ only in case (CADCraft's own record can hold both): the one spelled so.
// Save onto a name another state has in another case replaces that state, as one spelled the
// same: AutoCAD 2024 keeps one state per name in any case.
s.execute("layerstate.save", &json!({ "name": "m2", "mask": LayerState::ON })).unwrap();
assert_eq!(states(&s), [state("m2", 513)]);
// Names that differ only in case (a file can hold both, and AutoCAD 2024 opens it): the one
// spelled so, though the other comes first.
s.doc_mut().unwrap().layer_states.insert(0, LayerState::new("M2", Vec::new(), ""));
s.execute("layerstate.delete", &json!({ "name": "m2" })).unwrap();
assert_eq!(states(&s), [state("M2", LayerState::ALL)]);
}