mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-30 02:07:10 +01:00
Merge pull request #9992 from dotCooCoo/fix/invert-empty-selection-target
Paint: Invert and Complement refuse a bad target with nothing selected
This commit is contained in:
2 files changed
+23
-1
No files matched your search
@@ -2000,6 +2000,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);
|
||||
@@ -2007,7 +2009,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)?;
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in new issue
Block a user