Paint: Invert and Complement refuse a bad target with nothing selected

With nothing selected, `paint.invert` and `paint.complement` recolored the
default fill or stroke before reading `target` and `aligned`, so a bad value
was accepted and changed the default. They now read both before the default
branch, as #8099 does for `paint.setFill` and `paint.setStroke`.
This commit is contained in:
dotCooCoo committed 2026-11-28 14:18:20 -08:00
1 parent 170d491cb9
commit 1ce80e6d48
2 files changed
+23 -1

No files matched your search

+3 -1
View File
@@ -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)?;
+20
View File
@@ -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]