VectorCraft: An open-source, vector art tool written by scratch in pure Rust
SVG: a Preserve Editing SVG reopened from disk saves as the full document again (#3867)
bflatastic8e8aaa868312
diff --git a/crates/engine/src/cmd/fileio/load.rs b/crates/engine/src/cmd/fileio/load.rsindex 72574e5e0..000712d7b 100644--- a/crates/engine/src/cmd/fileio/load.rs+++ b/crates/engine/src/cmd/fileio/load.rs@@ -454,6 +454,11 @@ fn open_loaded(s: &mut Session, loaded: Loaded, links: Resolved, path: Option<Stlet st = s.doc_mut()?;if saves_back {st.format = format.id;+ // An SVG that reopened as the full document saves as one again: Save keeps Preserve+ // Editing, as it would after a save of this session (#3867).+ if restored && matches!(format.id, "svg" | "svgz") {+ st.save_options.insert("preserveEditing".into(), json!(true));+ }}st.converted = converted;st.imported_from = source_path;diff --git a/crates/engine/src/cmd/fileio/tests_svg.rs b/crates/engine/src/cmd/fileio/tests_svg.rsindex 05cafeb6a..b9b90cc00 100644--- a/crates/engine/src/cmd/fileio/tests_svg.rs+++ b/crates/engine/src/cmd/fileio/tests_svg.rs@@ -162,6 +162,24 @@ fn saving_several_artboards_as_plain_svg_warns_they_are_lost() {assert_eq!(artboards(&session(1).execute("document.save", &json!({"format": "svg"})).unwrap()), 0);}+/// #3867: a Preserve Editing SVG opened from disk and saved with plain Save keeps the full+/// document (every artboard), not just the artwork of the first.+#[test]+fn reopened_preserve_editing_svg_saves_as_the_full_document() {+ let dir = tmp_dir("reopen");+ let path = dir.join("keep.svg").to_string_lossy().to_string();+ session(3).execute("document.save", &json!({"path": path, "svg": {"preserveEditing": true}})).unwrap();+ let mut s = Session::new();+ s.execute("document.open", &json!({"path": path})).unwrap();+ assert_eq!(s.doc().unwrap().doc.artboards.len(), 3);+ s.execute("document.save", &json!({})).unwrap();+ let mut t = Session::new();+ let r = t.execute("document.open", &json!({"path": path})).unwrap();+ assert_eq!(r["restored"], json!(true), "{r}");+ assert_eq!(t.doc().unwrap().doc.artboards.len(), 3, "every artboard survives open and Save");+ let _ = std::fs::remove_dir_all(dir);+}+#[test]fn save_writes_svg_and_remembers_its_options() {let mut s = session(1);