Merge pull request #5869 from dotCooCoo/fix/transparency-grid-boolean-param

Reject invalid Transparency Grid parameters
This commit is contained in:
BFlat
2026-11-06 11:27:54 +08:00
committed by GitHub
3 changed files with 18 additions and 2 deletions
+2 -2
View File
@@ -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<CommandSpec> {
vec![
@@ -64,7 +64,7 @@ fn caps_lock(s: &mut Session, p: &Value) -> Result<Value> {
fn transparency_grid(s: &mut Session, p: &Value) -> Result<Value> {
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 }))
}
@@ -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", &params).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}));
}
+1
View File
@@ -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