diff --git a/crates/engine/src/tests/draw2.rs b/crates/engine/src/tests/draw2.rs
index 79dbd366f6..ea6e382b5f 100644
--- a/crates/engine/src/tests/draw2.rs
+++ b/crates/engine/src/tests/draw2.rs
@@ -5185,14 +5185,20 @@ fn pencil_at_the_lowest_fidelity_takes_degenerate_strokes() {
}
}
-/// The Pencil's Fidelity option takes 0.01, and the Smooth tool's stays at 0.05 or more.
+/// The Pencil's Fidelity option takes 0.01, and the Smooth tool's 0.05 or more: a lower Fidelity is
+/// an error that leaves the option as it was.
#[test]
fn pencil_option_takes_a_hundredth_and_smooth_keeps_its_floor() {
let mut s = session();
- for (tool, want) in [("pencil", 0.01), ("paintbrush", 0.01), ("smooth", 0.05)] {
- s.set_tool_option_cmd(&json!({"tool": tool, "values": {"fidelity": 0.001}})).unwrap();
- assert_eq!(s.tool_options_of(tool)["fidelity"].as_f64(), Some(want), "{tool}");
- s.set_tool_option_cmd(&json!({"tool": tool, "values": {"fidelity": 0.02}})).unwrap();
+ for (tool, floor) in [("pencil", 0.01), ("paintbrush", 0.01), ("smooth", 0.05)] {
+ let before = s.tool_options_of(tool)["fidelity"].clone();
+ let e = s.set_tool_option_cmd(&json!({"tool": tool, "values": {"fidelity": 0.001}})).unwrap_err();
+ assert_eq!(e, format!("tool `{tool}`: `fidelity` must be a number from {floor} to 100"));
+ assert_eq!(s.tool_options_of(tool)["fidelity"], before, "{tool}");
+ s.set_tool_option_cmd(&json!({"tool": tool, "values": {"fidelity": floor}})).unwrap();
+ assert_eq!(s.tool_options_of(tool)["fidelity"].as_f64(), Some(floor), "{tool}");
+ let hundredth = s.set_tool_option_cmd(&json!({"tool": tool, "values": {"fidelity": 0.02}}));
+ assert_eq!(hundredth.is_ok(), tool != "smooth", "{tool}");
assert_eq!(s.tool_options_of(tool)["fidelity"].as_f64(), Some(if tool == "smooth" { 0.05 } else { 0.02 }), "{tool}");
}
}
diff --git a/crates/engine/src/tests/toolsettings.rs b/crates/engine/src/tests/toolsettings.rs
index e896a0ab32..eae2a16aa4 100644
--- a/crates/engine/src/tests/toolsettings.rs
+++ b/crates/engine/src/tests/toolsettings.rs
@@ -324,3 +324,105 @@ fn alt_smoothing_takes_the_smooth_tools_fidelity() {
assert_eq!(s.tool_options()["fidelity"], json!(3.0), "{id}");
}
}
+
+/// `tool.setOption` with a value of the wrong type, a number out of range, an unknown value or an
+/// option the tool doesn't have is an error naming the tool and the option. Nothing is set, also
+/// when another option given with it is good, and nothing is saved or recorded for undo.
+#[test]
+fn bad_option_values_are_errors_that_set_nothing() {
+ let mut s = session();
+ select(&mut s, "smooth");
+ let (options, saved, undo) = (s.tool_options(), s.prefs.tool_settings.clone(), s.doc().unwrap().history.undo.len());
+ let fidelity = "tool `smooth`: `fidelity` must be a number from 0.05 to 100";
+ for bad in [json!("abc"), json!(true), json!(-3), json!(1e9), json!(null), json!([2])] {
+ assert_eq!(s.set_tool_option_cmd(&json!({"key": "fidelity", "value": bad})).unwrap_err(), fidelity, "{bad}");
+ }
+ let cases = [
+ (json!({"key": "bogus", "value": 1}), "tool `smooth`: unknown option `bogus`"),
+ (json!({"tool": "pencil", "values": {"closeWithin": 5, "fidelity": "x"}}), "tool `pencil`: `fidelity` must be a number from 0.01 to 100"),
+ (json!({"tool": "pencil", "key": "fill", "value": "yes"}), "tool `pencil`: `fill` must be true or false"),
+ (json!({"tool": "blobBrush", "key": "sizeMode", "value": "huge"}), "tool `blobBrush`: `sizeMode` must be one of `fixed`, `pressure`"),
+ (json!({"tool": "eraser", "key": "fidelity", "value": 4}), "tool `eraser`: unknown option `fidelity`"),
+ (json!({"tool": "polygon", "key": "sides", "value": 2}), "tool `polygon`: `sides` must be a whole number from 3 to 1000"),
+ (
+ json!({"tool": "mirrorCut", "key": "axis", "value": "diagonal"}),
+ "tool `mirrorCut`: `axis` must be one of `vertical`, `horizontal`, `free`",
+ ),
+ (json!({"tool": "selection", "key": "fidelity", "value": 4}), "tool `selection`: unknown option `fidelity`"),
+ (json!({"values": [1]}), "`values` must be an object"),
+ (json!({"tool": 3, "key": "fidelity", "value": 4}), "`tool` must be a tool id"),
+ (json!({"key": "fidelity"}), "`value` is missing for `fidelity`"),
+ ];
+ for (p, want) in cases {
+ assert_eq!(s.set_tool_option_cmd(&p).unwrap_err(), want, "{p}");
+ }
+ assert_eq!(s.tool_options_of("pencil")["closeWithin"], session().tool_options_of("pencil")["closeWithin"]);
+ assert_eq!((s.tool_options(), &s.prefs.tool_settings, s.doc().unwrap().history.undo.len()), (options, &saved, undo));
+ // A good value after the errors is set and read back.
+ assert_eq!(s.set_tool_option_cmd(&json!({"key": "fidelity", "value": 9})).unwrap()["fidelity"], json!(9.0));
+}
+
+/// `tool.setOption {}` reads the options, of the active tool or of the tool named, and saves nothing.
+#[test]
+fn an_empty_set_option_reads_and_saves_nothing() {
+ let mut s = session();
+ select(&mut s, "smooth");
+ let saved = s.prefs.tool_settings.clone();
+ assert_eq!(s.set_tool_option_cmd(&json!({})).unwrap(), s.tool_options());
+ assert_eq!(s.set_tool_option_cmd(&json!({"tool": "flare"})).unwrap(), s.tool_options_of("flare"));
+ assert_eq!(s.prefs.tool_settings, saved);
+}
+
+/// A Place queue with a malformed entry is an error, and the queue held stays as it was.
+#[test]
+fn a_malformed_place_queue_is_an_error() {
+ let mut s = session();
+ select(&mut s, "place");
+ let entry = json!({"params": {"svg": ""}, "name": "a", "width": 10, "height": 10});
+ s.set_tool_option_cmd(&json!({"key": "queue", "value": {"entries": [entry]}})).unwrap();
+ let bad = json!({"params": {}, "name": "b", "width": "wide", "height": 10});
+ let e = s.set_tool_option_cmd(&json!({"key": "queue", "value": {"entries": [entry, bad]}})).unwrap_err();
+ assert!(e.starts_with("tool `place`: `queue` must be"), "{e}");
+ assert_eq!(s.tool_options()["names"], json!(["a"]));
+ assert_eq!(
+ s.set_tool_option_cmd(&json!({"key": "current", "value": 1})).unwrap_err(),
+ "tool `place`: `current` must be the index of a queued file, from 0 to 0"
+ );
+}
+
+/// A `current` given with a new Place queue picks among the files of that queue.
+#[test]
+fn a_place_queue_and_its_current_file_set_together() {
+ let mut s = session();
+ select(&mut s, "place");
+ let entry = |name: &str| json!({"params": {"svg": ""}, "name": name, "width": 10, "height": 10});
+ let queue = json!({"entries": [entry("a"), entry("b"), entry("c")]});
+ let out = s.set_tool_option_cmd(&json!({"values": {"queue": queue, "current": 2}})).unwrap();
+ assert_eq!((out["names"].clone(), out["current"].clone()), (json!(["a", "b", "c"]), json!(2)));
+ let short = json!({"entries": [entry("d")]});
+ let e = s.set_tool_option_cmd(&json!({"values": {"queue": short, "current": 2}})).unwrap_err();
+ assert_eq!(e, "tool `place`: `current` must be the index of a queued file, from 0 to 0");
+ assert_eq!(s.tool_options()["names"], json!(["a", "b", "c"]), "a refused call keeps the queue held");
+}
+
+/// A value given with a parametric shape's new `kind` is checked against that kind's range and
+/// set on it, whether the tool is chosen or not.
+#[test]
+fn a_parametric_shape_kind_and_its_values_set_together() {
+ for active in [false, true] {
+ let mut s = session();
+ if active {
+ select(&mut s, "parametricShape");
+ }
+ let set = |s: &mut Session, values: serde_json::Value| s.set_tool_option_cmd(&json!({"tool": "parametricShape", "values": values}));
+ set(&mut s, json!({"kind": "polygon"})).unwrap();
+ let out = set(&mut s, json!({"kind": "star", "a": 0.8})).unwrap();
+ assert_eq!((out["kind"].clone(), out["a"].clone()), (json!("star"), json!(0.8)), "active {active}");
+ set(&mut s, json!({"kind": "ring"})).unwrap();
+ let out = set(&mut s, json!({"kind": "star", "a": 1.0})).unwrap();
+ assert_eq!((out["kind"].clone(), out["a"].clone()), (json!("star"), json!(1.0)), "active {active}");
+ let e = set(&mut s, json!({"kind": "ring", "a": 1.0})).unwrap_err();
+ assert!(e.contains("`a`"), "{e}");
+ assert_eq!(s.tool_options_of("parametricShape")["kind"], json!("star"), "a refused call sets nothing");
+ }
+}
diff --git a/crates/engine/src/tooling.rs b/crates/engine/src/tooling.rs
index 4dedfe7b28..df7ef4b1d8 100644
--- a/crates/engine/src/tooling.rs
+++ b/crates/engine/src/tooling.rs
@@ -1273,9 +1273,14 @@ impl Session {
}
let active = id.is_none_or(|id| id == self.tool.id());
self.tool_set_since_reset |= active;
+ // The Place queue and a parametric shape's kind are set first: setting the queue starts
+ // again at its first file, and a `current` given with it is an index into it; setting the
+ // kind puts the shape's other numbers back to that kind's, and those given with it are its.
+ let first = |k: &str| k == "queue" || k == "kind";
+ let ordered = || values.iter().filter(|(k, _)| first(k)).chain(values.iter().filter(|(k, _)| !first(k)));
let mut other = (!active).then(|| self.make_tool(id.unwrap_or_default()));
let t = other.as_deref_mut().unwrap_or(self.tool.as_mut());
- for (k, v) in values {
+ for (k, v) in ordered() {
t.set_option(k, v);
}
Self::store_tool_settings(&mut self.prefs, t);
@@ -1287,7 +1292,7 @@ impl Session {
// active tool.
if let Some(lender) = self.lender.as_deref_mut() {
if lender.id() == other.id() {
- for (k, v) in values {
+ for (k, v) in ordered() {
lender.set_option(k, v);
}
}
@@ -1303,17 +1308,20 @@ impl Session {
/// `tool.setOption {tool?, key?, value?, values?}` (a command of the desktop app and of the
/// headless host): set one option (`key`, `value`) or several (`values`) of `tool` (default:
- /// the active tool) → its options.
+ /// the active tool) → its options. With no option given, the options are read and nothing is
+ /// set. Every option given is checked first ([`vectorcraft_tools::Tool::check_option`]): an
+ /// unknown option, a value of the wrong type or a number out of range is an error that sets
+ /// none of them.
pub fn set_tool_option_cmd(&mut self, p: &Value) -> std::result::Result {
- let tool = p.get("tool").and_then(Value::as_str);
+ let (tool, values) = vectorcraft_tools::option_check::set_option_params(p)?;
if let Some(t) = tool
&& vectorcraft_tools::tool_info(t).is_none()
{
return Err(format!("unknown tool `{t}`"));
}
- let mut values = p.get("values").and_then(Value::as_object).cloned().unwrap_or_default();
- if let Some(k) = p.get("key").and_then(Value::as_str) {
- values.insert(k.to_string(), p.get("value").cloned().unwrap_or(Value::Null));
+ let active = tool.is_none_or(|t| t == self.tool.id());
+ if values.is_empty() {
+ return Ok(self.tool_options_of(tool.unwrap_or(self.tool.id())));
}
// Every value is checked before any is set, so an invalid one changes nothing.
vectorcraft_tools::builder::check_builder_options(tool.unwrap_or(self.tool.id()), &values)?;
@@ -1334,8 +1342,12 @@ impl Session {
return Err("Unknown dimension mode".into());
}
}
+ match tool.filter(|_| !active) {
+ Some(id) => vectorcraft_tools::option_check::check_values(self.make_tool(id).as_ref(), &values)?,
+ None => vectorcraft_tools::option_check::check_values(self.tool.as_ref(), &values)?,
+ }
// The active tool's merge being computed is applied with the options it was started with.
- if tool.is_none_or(|t| t == self.tool.id()) {
+ if active {
self.finish_tool_edit_later().map_err(|e| e.to_string())?;
}
Ok(self.set_tool_options(tool, &values))
diff --git a/crates/mcp/src/tests/liquify.rs b/crates/mcp/src/tests/liquify.rs
index 4760380bc2..c6d3862384 100644
--- a/crates/mcp/src/tests/liquify.rs
+++ b/crates/mcp/src/tests/liquify.rs
@@ -28,6 +28,21 @@ fn tool_options_are_set_headless_and_kept_across_tool_switches() {
assert_eq!(command(&mut h, "tool.setOption", json!({}))["detail"], json!(6.0));
}
+/// A value the tool refuses is an error result naming the tool and the option, and the options
+/// stay as they were, the good value given with it included.
+#[test]
+fn a_refused_option_value_is_an_error_result() {
+ let mut h = Headless::with_document();
+ command(&mut h, "tool.select", json!({"tool": "warp"}));
+ let before = command(&mut h, "tool.setOption", json!({}));
+ for values in [json!({"width": 64, "detail": 99}), json!({"width": 64, "detail": "fine"})] {
+ let r = call_tool(&mut h, "run_command", &json!({"command": "tool.setOption", "params": {"values": values}}));
+ assert!(r.is_error, "{r:?}");
+ assert!(format!("{:?}", r.content).contains("tool `warp`: `detail` must be a number from 1 to 10"), "{r:?}");
+ }
+ assert_eq!(command(&mut h, "tool.setOption", json!({})), before);
+}
+
#[test]
fn pointer_gestures_carry_pen_pressure() {
let bloat = |pressure: f64| {
diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs
index 037f8cd89b..7783f72f1f 100644
--- a/crates/mcp/src/ui_catalog.rs
+++ b/crates/mcp/src/ui_catalog.rs
@@ -775,7 +775,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
"tool.setOption",
"Tool Option",
"",
- "{key, value} | {values: {key: value…}}, tool?: id (default: the active tool) → the tool's options (`{}` reads them). The options a tool keeps (Liquify brush and tool options, Mirror & Cut, Puppet Warp, drawing tools…) last across tool switches and are saved with the preferences; another tool's are stored for when it is chosen",
+ "{key, value} | {values: {key: value…}}, tool?: id (default: the active tool) → the tool's options (`{}` reads them). The options a tool keeps (Liquify brush and tool options, Mirror & Cut, Puppet Warp, drawing tools…) last across tool switches and are saved with the preferences; another tool's are stored for when it is chosen. Every option is checked before any is set: an option the tool doesn't have, a value of the wrong type, a number out of the tool's range or an unknown choice is an error naming the tool and the option, and nothing changes. The Live Paint tools' width and the Shape Builder's gapLength are set to the nearest end of their range instead",
),
(
"tool.toggleTouchMode",
diff --git a/crates/tools/src/addons/anchor_eraser.rs b/crates/tools/src/addons/anchor_eraser.rs
index 1eae255bc2..114e2b8e7a 100644
--- a/crates/tools/src/addons/anchor_eraser.rs
+++ b/crates/tools/src/addons/anchor_eraser.rs
@@ -152,6 +152,16 @@ impl Tool for AnchorEraserTool {
_ => {}
}
}
+
+ fn check_option(&self, key: &str, v: &Value) -> Result<(), String> {
+ use crate::option_check as c;
+ match key {
+ "size" => c::number(key, v, SIZE_RANGE.0, SIZE_RANGE.1),
+ "tolerance" => c::number(key, v, TOLERANCE_RANGE.0, TOLERANCE_RANGE.1),
+ "pressure" => c::boolean(key, v),
+ _ => Err(c::unknown(key)),
+ }
+ }
}
#[cfg(test)]
diff --git a/crates/tools/src/addons/box3d.rs b/crates/tools/src/addons/box3d.rs
index b0ecdc350e..e4f4b272c5 100644
--- a/crates/tools/src/addons/box3d.rs
+++ b/crates/tools/src/addons/box3d.rs
@@ -729,4 +729,33 @@ impl Tool for Box3dTool {
_ => {}
}
}
+
+ /// The options within their ranges. Any finite arc angle is taken: it is kept from 0 to 360°.
+ fn check_option(&self, key: &str, v: &Value) -> Result<(), String> {
+ use crate::option_check as c;
+ let max_radius = crate::shape::MAX_CORNER_RADIUS;
+ match key {
+ "shape" => c::one_of(key, v, &["box3d", "rectangle", "ellipse", "polygon", "star", "spiral"]),
+ "cornerRadius" => c::number(key, v, 0.0, max_radius),
+ "cornerRadii" => {
+ let radii = v.as_array().filter(|a| a.len() == 4);
+ if radii.is_some_and(|a| a.iter().all(|r| r.as_f64().is_some_and(|r| r.is_finite() && (0.0..=max_radius).contains(&r)))) {
+ Ok(())
+ } else {
+ Err(format!("`cornerRadii` must be four numbers from 0 to {max_radius}"))
+ }
+ }
+ "arcStart" | "arcEnd" => c::finite(key, v),
+ "arcMode" => c::one_of(key, v, &["whole", "pie", "chord", "arc"]),
+ "sides" | "points" => c::whole(key, v, 3, 1000),
+ "starRatio" => c::number(key, v, 0.01, 1.0),
+ "rounded" | "randomized" => c::number(key, v, -10.0, 10.0),
+ "turns" => c::number(key, v, 0.01, 1024.0),
+ "divergence" => c::number(key, v, 0.0, 1000.0),
+ "innerRadius" => c::number(key, v, 0.0, 0.999),
+ "angleX" | "angleY" | "angleZ" => c::number(key, v, -180.0, 180.0),
+ "cornerSymmetry" | "polyIsStar" | "clockwise" | "parallelX" | "parallelY" | "parallelZ" => c::boolean(key, v),
+ _ => Err(c::unknown(key)),
+ }
+ }
}
diff --git a/crates/tools/src/addons/contour.rs b/crates/tools/src/addons/contour.rs
index e77bb29eed..3bac5a6649 100644
--- a/crates/tools/src/addons/contour.rs
+++ b/crates/tools/src/addons/contour.rs
@@ -248,6 +248,15 @@ impl Tool for ContourTool {
}
}
+ fn check_option(&self, key: &str, value: &Value) -> Result<(), String> {
+ match key {
+ "corners" if value.as_str().and_then(Corners::parse).is_some() => Ok(()),
+ "corners" => Err("`corners` must be one of `sharp`, `round`, `square`".into()),
+ "miterLimit" => crate::option_check::number(key, value, 1.0, 500.0),
+ _ => Err(crate::option_check::unknown(key)),
+ }
+ }
+
fn busy(&self) -> bool {
self.drag.is_some()
}
diff --git a/crates/tools/src/addons/corner_tool.rs b/crates/tools/src/addons/corner_tool.rs
index 177926837e..a92f327d93 100644
--- a/crates/tools/src/addons/corner_tool.rs
+++ b/crates/tools/src/addons/corner_tool.rs
@@ -381,6 +381,16 @@ impl Tool for CornerTool {
_ => {}
}
}
+
+ fn check_option(&self, key: &str, v: &Value) -> Result<(), String> {
+ use crate::option_check as c;
+ match key {
+ "radius" => c::number(key, v, 0.0, MAX_RADIUS),
+ "kind" if serde_json::from_value::(v.clone()).is_ok() => Ok(()),
+ "kind" => Err("`kind` must be one of `round`, `invertedRound`, `chamfer`".into()),
+ _ => Err(c::unknown(key)),
+ }
+ }
}
#[cfg(test)]
diff --git a/crates/tools/src/addons/extend_path.rs b/crates/tools/src/addons/extend_path.rs
index d1f54861ca..b53d52d3e8 100644
--- a/crates/tools/src/addons/extend_path.rs
+++ b/crates/tools/src/addons/extend_path.rs
@@ -203,6 +203,14 @@ impl Tool for ExtendPathTool {
self.mode = Mode(m);
}
}
+
+ fn check_option(&self, key: &str, v: &Value) -> Result<(), String> {
+ if key != "mode" {
+ return Err(crate::option_check::unknown(key));
+ }
+ let ids: Vec<&str> = ExtendMode::ALL.iter().map(|m| m.id()).collect();
+ crate::option_check::one_of(key, v, &ids)
+ }
}
#[cfg(test)]
diff --git a/crates/tools/src/addons/parametric_shape.rs b/crates/tools/src/addons/parametric_shape.rs
index d16cb63935..61ce83ecde 100644
--- a/crates/tools/src/addons/parametric_shape.rs
+++ b/crates/tools/src/addons/parametric_shape.rs
@@ -434,6 +434,32 @@ impl Tool for ParametricShapeTool {
self.next = s;
}
}
+
+ /// The numbers [`Self::options`] shows, each as [`apply`] checks it; null is not a value.
+ fn check_option(&self, key: &str, v: &Value) -> Result<(), String> {
+ if self.options().get(key).is_none() {
+ return Err(crate::option_check::unknown(key));
+ }
+ if v.is_null() {
+ return Err(format!("`{key}` must not be null"));
+ }
+ apply(self.next, &json!({ key: v })).map(|_| ())
+ }
+
+ /// The options together, as [`apply`] takes them: a `kind` given with them sets the kind
+ /// first, and the other values are checked against that kind's ranges.
+ fn check_options(&self, values: &serde_json::Map) -> Result<(), String> {
+ let options = self.options();
+ for (key, v) in values {
+ if options.get(key).is_none() {
+ return Err(crate::option_check::unknown(key));
+ }
+ if v.is_null() {
+ return Err(format!("`{key}` must not be null"));
+ }
+ }
+ apply(self.next, &Value::Object(values.clone())).map(|_| ())
+ }
}
#[cfg(test)]
diff --git a/crates/tools/src/addons/shared_edge.rs b/crates/tools/src/addons/shared_edge.rs
index d11261800a..703e8e6f3f 100644
--- a/crates/tools/src/addons/shared_edge.rs
+++ b/crates/tools/src/addons/shared_edge.rs
@@ -214,6 +214,16 @@ impl Tool for SharedEdgeTool {
_ => {}
}
}
+
+ fn check_option(&self, key: &str, v: &Value) -> Result<(), String> {
+ use crate::option_check as c;
+ match key {
+ "diameter" => c::number(key, v, DIAMETER_RANGE.0, DIAMETER_RANGE.1),
+ "tolerance" => c::number(key, v, 0.0, MAX_COINCIDENCE),
+ "together" => c::boolean(key, v),
+ _ => Err(c::unknown(key)),
+ }
+ }
}
#[cfg(test)]
diff --git a/crates/tools/src/addons/smart_pen.rs b/crates/tools/src/addons/smart_pen.rs
index cd72f1dd40..40ba482f8b 100644
--- a/crates/tools/src/addons/smart_pen.rs
+++ b/crates/tools/src/addons/smart_pen.rs
@@ -624,6 +624,10 @@ impl Tool for SmartPenTool {
}
}
}
+
+ fn check_option(&self, key: &str, v: &Value) -> Result<(), String> {
+ if key == "next" { crate::option_check::one_of(key, v, &["curved", "straight"]) } else { Err(crate::option_check::unknown(key)) }
+ }
}
#[cfg(test)]
diff --git a/crates/tools/src/builder.rs b/crates/tools/src/builder.rs
index 2190d34180..55214e8b7b 100644
--- a/crates/tools/src/builder.rs
+++ b/crates/tools/src/builder.rs
@@ -775,6 +775,9 @@ impl Tool for ShapeBuilderTool {
self.cache.clear();
self.cache.gap = self.gap();
}
+ fn check_option(&self, key: &str, v: &Value) -> Result<(), String> {
+ check_builder_options(self.id(), &serde_json::Map::from_iter([(key.to_string(), v.clone())]))
+ }
}
/// Why `tool.setOption` cannot give the builder-family tool `tool` the options `values`, checked
diff --git a/crates/tools/src/builder/live_paint.rs b/crates/tools/src/builder/live_paint.rs
index 6b744e4435..fc27bbde59 100644
--- a/crates/tools/src/builder/live_paint.rs
+++ b/crates/tools/src/builder/live_paint.rs
@@ -437,6 +437,10 @@ impl Tool for LivePaintBucketTool {
self.hover = LpHover::None;
}
+ fn check_option(&self, key: &str, v: &Value) -> Result<(), String> {
+ check_live_paint_options(self.id(), &serde_json::Map::from_iter([(key.to_string(), v.clone())]))
+ }
+
fn waiting(&self) -> bool {
self.cache.waiting()
}
@@ -737,4 +741,8 @@ impl Tool for LivePaintSelectionTool {
}
self.hover = LpHover::None;
}
+
+ fn check_option(&self, key: &str, v: &Value) -> Result<(), String> {
+ check_live_paint_options(self.id(), &serde_json::Map::from_iter([(key.to_string(), v.clone())]))
+ }
}
diff --git a/crates/tools/src/cropimage.rs b/crates/tools/src/cropimage.rs
index ff716bf171..e0fa322e3e 100644
--- a/crates/tools/src/cropimage.rs
+++ b/crates/tools/src/cropimage.rs
@@ -268,6 +268,19 @@ impl Tool for CropImageTool {
};
}
+ /// `rect` is `[x, y, width, height]`, or null to put the box back where it starts.
+ fn check_option(&self, key: &str, value: &Value) -> Result<(), String> {
+ if key != "rect" {
+ return Err(crate::option_check::unknown(key));
+ }
+ let numbers = value.as_array().filter(|a| a.len() == 4).and_then(|a| a.iter().map(Value::as_f64).collect::