diff --git a/crates/engine/src/script/mod.rs b/crates/engine/src/script/mod.rs index 6292be8727..c2c70ae0f8 100644 --- a/crates/engine/src/script/mod.rs +++ b/crates/engine/src/script/mod.rs @@ -2251,8 +2251,9 @@ impl Session { }; // The perspective grid's view state changes without an undo step, as it does outside a // run, when no command in the run recorded an undo step of its own on the working copy. - let (now, was) = (&st.history.undo, &b.history.undo); - let recorded = now.len() != was.len() || !now.last().zip(was.last()).map_or(now.is_empty(), |(x, y)| Arc::ptr_eq(&x.doc, &y.doc)); + // The working copy starts with no undo steps (`World::working`), so any step it holds now + // was recorded in the run. + let recorded = !st.history.undo.is_empty(); let changed = !st.same_content(&b.doc) && (recorded || !cmd::distortcmds::only_grid_view_changed(&st.doc, &b.doc)); st.history = std::mem::take(&mut b.history); st.recovery.clone_from(&b.recovery); diff --git a/crates/engine/src/tests/script_dom_perspective.rs b/crates/engine/src/tests/script_dom_perspective.rs index c9398ffd4c..eebea33e7e 100644 --- a/crates/engine/src/tests/script_dom_perspective.rs +++ b/crates/engine/src/tests/script_dom_perspective.rs @@ -61,6 +61,19 @@ fn grid_view_commands_in_a_run_add_no_undo_step_but_an_edit_still_does() { assert_eq!(grid(&mut s)["visible"], true); } +#[test] +fn a_grid_view_run_after_an_edit_adds_no_undo_step() { + let mut s = doc(); + s.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 10, "height": 10})).unwrap(); + let before = undo_steps(&s); + let drawn = s.active().unwrap().doc.node_count(); + run(&mut s, "app.activeDocument.showPerspectiveGrid(); vc.run('perspective.plane.set', {plane: 'ground'});").unwrap(); + assert_eq!((grid(&mut s)["visible"].clone(), grid(&mut s)["plane"].clone()), (json!(true), json!("ground"))); + assert_eq!(undo_steps(&s), before); + s.execute("edit.undo", &json!({})).unwrap(); + assert_eq!(s.active().unwrap().doc.node_count(), drawn - 1); +} + #[test] fn a_grid_edit_that_changes_only_view_fields_keeps_its_undo_step_in_a_run() { let mut s = doc(); diff --git a/crates/engine/tests/it/script_host_vs_scriptcheck.rs b/crates/engine/tests/it/script_host_vs_scriptcheck.rs index 881cb64d04..95a8607329 100644 --- a/crates/engine/tests/it/script_host_vs_scriptcheck.rs +++ b/crates/engine/tests/it/script_host_vs_scriptcheck.rs @@ -42,7 +42,8 @@ const OUTSIDE: &[(&str, &str, &str)] = &[ /// The names the host adds that stay inside the document and the run, by the object that has them. /// Reading a file or a folder, a file dialog and a message to the person do not change anything /// outside it. The document model (`app`, its classes and the enumerations) acts on the open -/// documents; `Document.saveAs` and `close` throw "not available yet". +/// documents; `Document.saveAs`, `close` and the perspective grid preset files, and the workspace +/// methods, `loadColorSettings` and `showPresets` of `Application`, throw "not available yet". const INSIDE: &[(&str, &str)] = &[ ("", "$ File Folder alert confirm localize prompt toSource"), ("Object.prototype.", "toSource"), @@ -75,14 +76,16 @@ const INSIDE: &[(&str, &str)] = &[ "", "app Application Artboard Artboards CompoundPathItem CompoundPathItems CoordinateSystem Document \ DocumentArtboardLayout DocumentColorSpace DocumentPresetType DocumentPreviewMode DocumentRasterResolution \ - DocumentTransparencyGrid Documents ElementPlacement GroupItem GroupItems Layer Layers PageItem PageItems RulerUnits \ - ZOrderMethod", + DocumentTransparencyGrid Documents ElementPlacement GroupItem GroupItems Layer Layers PageItem PageItems \ + PerspectiveGridPlaneType PerspectiveGridType RulerUnits ZOrderMethod", ), ("Application.", "prototype"), ( "Application.prototype.", - "activeDocument activeDocument= beep beep= constructor coordinateSystem coordinateSystem= documents getIsFileOpen \ - selection typename", + "activeDocument activeDocument= beep beep= constructor coordinateSystem coordinateSystem= deleteWorkspace \ + deleteWorkspace= documents getIsFileOpen getPresetSettings loadColorSettings loadColorSettings= resetWorkspace \ + resetWorkspace= saveWorkspace saveWorkspace= selection showPresets showPresets= switchWorkspace switchWorkspace= \ + typename", ), ("Documents.", "prototype"), ("Documents.prototype.", "add addDocument constructor getByName index length parent typename"), @@ -90,8 +93,10 @@ const INSIDE: &[(&str, &str)] = &[ ( "Document.prototype.", "activeLayer activeLayer= artboards close close= compoundPathItems constructor convertCoordinate \ - documentColorSpace groupItems height layers name pageItems parent pathItems pathItems= rulerOrigin rulerOrigin= \ - rulerUnits saveAs saveAs= selection selection= swatches swatches= symbols symbols= textFrames textFrames= typename \ + documentColorSpace exportPerspectiveGridPreset exportPerspectiveGridPreset= getPerspectiveActivePlane groupItems \ + height hidePerspectiveGrid importPerspectiveGridPreset importPerspectiveGridPreset= layers name pageItems parent \ + pathItems pathItems= rulerOrigin rulerOrigin= rulerUnits saveAs saveAs= selectPerspectivePreset selection \ + selection= setActivePlane showPerspectiveGrid swatches swatches= symbols symbols= textFrames textFrames= typename \ views views= width", ), ("Layer.", "prototype"), @@ -153,6 +158,8 @@ const INSIDE: &[(&str, &str)] = &[ TransparencyGridNone TransparencyGridOrange TransparencyGridPurple TransparencyGridRed", ), ("ElementPlacement.", "INSIDE PLACEAFTER PLACEATBEGINNING PLACEATEND PLACEBEFORE"), + ("PerspectiveGridPlaneType.", "GRIDFLOORPLANETYPE GRIDLEFTPLANETYPE GRIDRIGHTPLANETYPE INVALIDGRIDPLANETYPE"), + ("PerspectiveGridType.", "InvalidPerspectiveGridType OnePointPerspectiveGridType ThreePointPerspectiveGridType TwoPointPerspectiveGridType"), ("RulerUnits.", "Centimeters Inches Millimeters Picas Pixels Points Qs Unknown"), ("ZOrderMethod.", "BRINGFORWARD BRINGTOFRONT SENDBACKWARD SENDTOBACK"), ];