SVG: a Preserve Editing SVG reopened from disk saves as the full document again (#3867)

This commit is contained in:
bflatastic
2026-10-24 03:52:24 +07:00
parent e372d00cb7
commit 8e8aaa8683
2 changed files with 23 additions and 0 deletions
+5
View File
@@ -454,6 +454,11 @@ fn open_loaded(s: &mut Session, loaded: Loaded, links: Resolved, path: Option<St
let 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;
+18
View File
@@ -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);