From 7a1ba45d1891cf4e6ef7f23f1a11db2f26aa2943 Mon Sep 17 00:00:00 2001 From: midasmatterhorn <248507632+midasmatterhorn@users.noreply.github.com> Date: Wed, 14 Oct 2026 23:47:55 +0300 Subject: [PATCH] layout.section: keep the settings the command does not name The command removed the section at a nonzero start with retain() and only then looked it up to keep its properties, so the lookup always fell back to the defaults: editing one field (a marker, a start number) silently reset the style, prefix, include-prefix flag and start number. The existing section is now read before the list is rebuilt. Regression test: a Roman-numbered page-2 section with prefix A- and marker First, then marker Second keeps startNumber, style, prefix and includePrefix. --- crates/engine/src/cmd/layout.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/layout.rs b/crates/engine/src/cmd/layout.rs index 6d6e06ee1..79a555f3b 100644 --- a/crates/engine/src/cmd/layout.rs +++ b/crates/engine/src/cmd/layout.rs @@ -476,11 +476,14 @@ pub fn specs() -> Vec { let start = page - 1; let p = p.clone(); s.edit(|d, _| { + // The settings the command does not name stay as the section was: read it + // before the list is rebuilt (#717). + let existing = d.sections.iter().find(|x| x.start == start).cloned(); d.sections.retain(|x| x.start != start || start == 0); if p.get("remove").and_then(Value::as_bool).unwrap_or(false) && start != 0 { return ok(); } - let mut sec = d.sections.iter().find(|x| x.start == start).cloned().unwrap_or(designcraft_doc::Section { + let mut sec = existing.unwrap_or(designcraft_doc::Section { start, start_number: None, style: Default::default(), @@ -1034,6 +1037,28 @@ mod page_numbering_view_tests { assert_eq!(s.resolve_page("1"), Some(0)); assert_eq!(s.resolve_page("9"), None); } + + /// `layout.section` edits one named setting; the others stay as the section was (#717). + #[test] + fn updating_a_section_keeps_settings_the_command_does_not_name() { + let mut s = Session::new(); + s.execute("file.new", &json!({"pages": 4})).unwrap(); + s.execute( + "layout.section", + &json!({"page": 2, "startNumber": 1, "style": "lowerRoman", "prefix": "A-", "includePrefix": true, "marker": "First"}), + ) + .unwrap(); + assert_eq!(s.page_label(1), "A-i"); + s.execute("layout.section", &json!({"page": 2, "marker": "Second"})).unwrap(); + let d = s.doc().unwrap().doc.clone(); + let sec = d.sections.iter().find(|x| x.start == 1).expect("the page-2 section is still the only one there"); + assert_eq!(sec.marker, "Second"); + assert_eq!(sec.start_number, Some(1), "startNumber is kept"); + assert_eq!(sec.style, designcraft_doc::NumberStyle::LowerRoman, "style is kept"); + assert_eq!(sec.prefix, "A-", "prefix is kept"); + assert!(sec.include_prefix, "includePrefix is kept"); + assert_eq!(s.page_label(1), "A-i"); + } } #[cfg(test)]