Merge pull request #2488 from webdevtodayjason/fix/1968-transparency-grid

View: Show Transparency Grid is saved with the document
This commit is contained in:
BFlat
2026-10-17 15:07:24 +07:00
committed by GitHub
8 changed files with 61 additions and 11 deletions
+5
View File
@@ -695,6 +695,10 @@ pub struct Document {
/// save time only, so changing the view never marks the document modified.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub last_view: Option<SavedView>,
/// View → Show Transparency Grid when the document was saved. Written at save time only,
/// like [`Document::last_view`]; older files open with the grid hidden.
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub transparency_grid: bool,
/// The layers, sublayers and groups open in the Layers panel when the document was saved; they
/// reopen that way. `None`: the default, only the top-level layers open. Written at save time
/// only, like [`Document::last_view`].
@@ -813,6 +817,7 @@ impl Document {
metadata: DocMetadata::default(),
raster_effects: RasterEffectsSettings::default(),
last_view: None,
transparency_grid: false,
layers_open: None,
color_profiles: ColorProfiles::default(),
export_settings: Default::default(),
+3 -2
View File
@@ -296,17 +296,18 @@ fn is_svg(f: &Format) -> bool {
}
/// The document as written: native files carry the view to reopen at and the Layers panel's open
/// rows.
/// rows and transparency grid visibility.
fn doc_to_save(st: &DocState, f: &Format) -> Arc<Document> {
if !is_native(f) {
return st.doc.clone();
}
let open = st.layers_open.saved(&st.doc);
if st.doc.last_view == st.view && st.doc.layers_open == open {
if st.doc.last_view == st.view && st.doc.layers_open == open && st.doc.transparency_grid == st.transparency_grid {
return st.doc.clone();
}
let mut d = (*st.doc).clone();
d.last_view = st.view.clone();
d.transparency_grid = st.transparency_grid;
d.layers_open = open;
Arc::new(d)
}
+4 -4
View File
@@ -319,7 +319,7 @@ pub struct DocState {
/// View Opacity Mask (Alt-click the mask thumbnail): the masked object whose mask the canvas
/// shows alone, in greyscale, while that mask is edited (see [`DocState::shown_mask`]).
pub mask_view: Option<NodeId>,
/// View → Show Transparency Grid, per document (view state: not saved, not undoable).
/// View → Show Transparency Grid, per document (saved view state, not undoable).
pub transparency_grid: bool,
/// The format Save writes ([`cmd::fileio::SAVE_FORMATS`]): the one the document was opened
/// from or last saved as.
@@ -455,9 +455,9 @@ impl RecalledSelection {
impl DocState {
pub fn new(mut doc: Document, path: Option<String>) -> Self {
let active_layer = doc.default_layer();
// The saved view and open Layers rows live here while the document is open (saves write
// them back).
// Saved view state lives here while the document is open (saves write it back).
let view = doc.last_view.take();
let transparency_grid = std::mem::take(&mut doc.transparency_grid);
let saved_open = doc.layers_open.take();
let layers_open = OpenRows::new(&doc, saved_open);
let doc = Arc::new(doc);
@@ -479,7 +479,7 @@ impl DocState {
recalled_selection: RecalledSelection::default(),
uid: NEXT_DOC_UID.fetch_add(1, std::sync::atomic::Ordering::Relaxed),
mask_view: None,
transparency_grid: false,
transparency_grid,
format: "vectorcraft",
save_options: Default::default(),
converted: false,
+32
View File
@@ -373,3 +373,35 @@ fn a_template_places_like_a_native_file() {
let st = s.doc().unwrap();
assert!(st.doc.node_count() > empty && !st.selection.is_empty(), "the template's art is placed and selected");
}
#[test]
fn transparency_grid_round_trips_without_dirtying() {
let d = dir("transparency-grid");
let mut s = session();
let native = path(&d, "grid.vectorcraft");
for on in [true, false] {
s.execute("view.transparencyGrid", &json!({"on": on})).unwrap();
assert!(!s.doc().unwrap().is_dirty(), "the grid is view state, not an edit");
s.execute("document.save", &json!({"path": native})).unwrap();
s.execute("document.open", &json!({"path": native})).unwrap();
assert_eq!(s.doc().unwrap().transparency_grid, on);
assert!(s.doc().unwrap().history.undo.is_empty());
assert!(!s.doc().unwrap().is_dirty());
if on {
let svg = path(&d, "grid.svg");
s.execute("file.saveCopy", &json!({"path": svg})).unwrap();
s.execute("document.open", &json!({"path": svg})).unwrap();
assert!(!s.doc().unwrap().transparency_grid, "SVG does not store view state");
s.execute("document.open", &json!({"path": native})).unwrap();
assert!(s.doc().unwrap().transparency_grid);
}
}
// A native file written before this setting existed still opens with the grid hidden.
let old = path(&d, "old.vectorcraft");
let bytes = vectorcraft_format::save(&Document::new(5.0, 5.0), false);
assert!(!String::from_utf8_lossy(&bytes).contains("transparency_grid"));
std::fs::write(&old, bytes).unwrap();
s.execute("document.open", &json!({"path": old})).unwrap();
assert!(!s.doc().unwrap().transparency_grid);
let _ = std::fs::remove_dir_all(d);
}
+4 -1
View File
File diff suppressed because one or more lines are too long
+4 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+5 -1
View File
File diff suppressed because one or more lines are too long