diff --git a/crates/engine/src/cmd/paint.rs b/crates/engine/src/cmd/paint.rs index b8136e8cf5..4ec75a202e 100644 --- a/crates/engine/src/cmd/paint.rs +++ b/crates/engine/src/cmd/paint.rs @@ -1986,6 +1986,8 @@ fn proxy_recolor(s: &mut Session, p: &Value, cmd: &str, label: &str, f: &dyn Fn( Some(ids) => ids, None => super::edit::selected_roots(s)?, }; + // Read before the default is recolored, so that a bad `target` or `aligned` is refused with nothing selected too. + let item = item_target(s, p, cmd)?; if ids.is_empty() { let def = if stroke { &mut s.paint.stroke } else { &mut s.paint.fill }; let changed = super::colorcmds::map_paint(def, f); @@ -1993,7 +1995,7 @@ fn proxy_recolor(s: &mut Session, p: &Value, cmd: &str, label: &str, f: &dyn Fn( s.remember_paint(&shown); return Ok(json!({ "changed": changed as usize })); } - let item = item_target(s, p, cmd)?.of_kind(s, !stroke); + let item = item.of_kind(s, !stroke); // Read before the check below, so that a bad param (such as `target` or `aligned`, or an explicit `item` the art has // no row for) is still an error. let targets = super::appearance::drop_design_art_rows(s, item.targets_for(s, p, !stroke)?, item, !stroke, cmd)?; diff --git a/crates/engine/src/tests/build.rs b/crates/engine/src/tests/build.rs index 320d6ba70f..6ccdfad0a5 100644 --- a/crates/engine/src/tests/build.rs +++ b/crates/engine/src/tests/build.rs @@ -4046,6 +4046,26 @@ fn live_paint_bucket_refuses_a_bad_target_or_aligned() { } } +/// With nothing selected, Invert and Complement refuse a bad `target` or `aligned` and leave the +/// default fill and stroke as they are. +#[test] +fn invert_and_complement_refuse_a_bad_target_or_aligned_with_nothing_selected() { + let mut s = session(); + s.execute("paint.setFill", &json!({"color": "#336699", "defaultsOnly": true})).unwrap(); + s.execute("select.none", &json!({})).unwrap(); + let before = (s.paint.fill.clone(), s.paint.stroke.clone()); + for cmd in ["paint.invert", "paint.complement"] { + for p in + [json!({"stroke": false, "target": "content"}), json!({"stroke": false, "aligned": "yes"}), json!({"stroke": true, "target": "bogus"})] + { + assert!(s.execute(cmd, &p).is_err(), "{cmd} {p}"); + assert_eq!((s.paint.fill.clone(), s.paint.stroke.clone()), before, "{cmd} {p}"); + } + } + s.execute("paint.invert", &json!({"stroke": false})).unwrap(); + assert_ne!(s.paint.fill, before.0, "a good call still inverts the default"); +} + /// While the Live Paint Bucket is active, each preview of a paint command in one interaction starts /// from the colors the interaction began with, so previewing a swap twice and committing swaps once. #[test]