diff --git a/crates/engine/src/cmd/layer.rs b/crates/engine/src/cmd/layer.rs index fb981dfc1..5bbf81230 100644 --- a/crates/engine/src/cmd/layer.rs +++ b/crates/engine/src/cmd/layer.rs @@ -413,7 +413,11 @@ fn run_state_save(s: &mut Session, p: &Value) -> Result { 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() } diff --git a/crates/engine/tests/it/layer_state_cmdline.rs b/crates/engine/tests/it/layer_state_cmdline.rs index 657a7b112..b766db443 100644 --- a/crates/engine/tests/it/layer_state_cmdline.rs +++ b/crates/engine/tests/it/layer_state_cmdline.rs @@ -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)]); }