From 398131b9ccda7ed5be2516b9ea7436a9b56fea70 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 5 Nov 2026 19:04:43 -0800 Subject: [PATCH] Reject invalid Transparency Grid parameters --- crates/engine/src/cmd/views.rs | 4 ++-- crates/engine/src/tests/transparencygrid.rs | 15 +++++++++++++++ docs/mcp.md | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/views.rs b/crates/engine/src/cmd/views.rs index 8597a0963..fd9e11bcf 100644 --- a/crates/engine/src/cmd/views.rs +++ b/crates/engine/src/cmd/views.rs @@ -5,7 +5,7 @@ use serde_json::{Value, json}; use vectorcraft_doc::SavedView; use vectorcraft_geom::Point; -use super::{CommandSpec, Result, Session, always, bad, bool_or, cmd, f64_req, finite_numbers, has_doc, str_param}; +use super::{CommandSpec, Result, Session, always, bad, bool_or, cmd, f64_req, finite_numbers, has_doc, str_param, switch_or}; pub fn specs() -> Vec { vec![ @@ -64,7 +64,7 @@ fn caps_lock(s: &mut Session, p: &Value) -> Result { fn transparency_grid(s: &mut Session, p: &Value) -> Result { let st = s.doc_mut()?; - st.transparency_grid = p.get("on").and_then(Value::as_bool).unwrap_or(!st.transparency_grid); + st.transparency_grid = switch_or(p, "on", !st.transparency_grid, "view.transparencyGrid")?; Ok(json!({ "on": st.transparency_grid })) } diff --git a/crates/engine/src/tests/transparencygrid.rs b/crates/engine/src/tests/transparencygrid.rs index 974fb0343..06efa70fb 100644 --- a/crates/engine/src/tests/transparencygrid.rs +++ b/crates/engine/src/tests/transparencygrid.rs @@ -26,3 +26,18 @@ fn transparency_grid_is_per_document_view_state() { s.execute("document.activate", &json!({"index": 1})).unwrap(); assert!(!grid(&s)); } + +#[test] +fn invalid_transparency_grid_parameters_leave_the_view_unchanged() { + let mut s = Session::new(); + s.execute("file.new", &json!({})).unwrap(); + for params in [json!({"on": "false"}), json!({"on": 1})] { + assert!(s.execute("view.transparencyGrid", ¶ms).is_err(), "accepted {params}"); + let st = s.doc().unwrap(); + assert!(!st.transparency_grid, "changed the grid for {params}"); + assert!(st.history.undo.is_empty() && !st.is_dirty(), "recorded an edit for {params}"); + } + // Left out, or null as for every command, it toggles. + assert_eq!(s.execute("view.transparencyGrid", &json!(null)).unwrap(), json!({"on": true})); + assert_eq!(s.execute("view.transparencyGrid", &json!({"on": null})).unwrap(), json!({"on": false})); +} diff --git a/docs/mcp.md b/docs/mcp.md index 5c9c5cb45..4934da0c7 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -1359,6 +1359,7 @@ mask first". Pattern editing mode does not count as isolation mode here. `view.transparencyGrid {on?}` (View → Show Transparency Grid; default: toggle) is view state of each open document, like the mask view: the grid shows behind the artboards of the documents that turn it on, on the canvas and in `ui.screenshot`, never in exports. It returns `{on}`, isn't undoable and doesn't mark the document changed. +The command rejects an `on` value that is not a boolean. Omitting `on` toggles the current value. `view.globalRulers {global?}` (View → Rulers → Change to Global / Artboard Rulers, Cmd+Alt+R; default: toggle) is saved with the document and undoable. With artboard rulers (a new document's) the rulers count from the active