From e87a7f09d9431bb5f2f0b247a2532acc14a1ca64 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 10:52:42 -0800 Subject: [PATCH] Paint: a bad target is refused when ids or id names the objects item_target_at read `target` only when no `ids` or `id` was given, so paint.setFill and paint.setStroke with an `id` and a target such as "content" painted the object instead of refusing it, and tests::paintopacity::a_bad_target_is_refused_with_an_id_or_selected_characters (added in #8099) failed. item_target_at now reads `target` first, for every command that names its item through it, and the selected-part path no longer needs its own early read. --- crates/engine/src/cmd/appearance.rs | 4 +++- crates/engine/src/cmd/paint.rs | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/cmd/appearance.rs b/crates/engine/src/cmd/appearance.rs index 4fb4537ee4..d319e0d2a4 100644 --- a/crates/engine/src/cmd/appearance.rs +++ b/crates/engine/src/cmd/appearance.rs @@ -253,6 +253,8 @@ pub(crate) fn item_target(s: &Session, p: &Value, cmd: &str) -> Result Result { let aligned = aligned(p, cmd)?; + // Read `target` whatever names the objects, so that a bad one is refused with `ids` or `id` too. + let contents = targets_contents(p)?; match p.get(key) { Some(Value::Null) => Ok(ItemTarget::Top), Some(v) => v @@ -260,7 +262,7 @@ pub(crate) fn item_target_at(s: &Session, p: &Value, key: &str, cmd: &str) -> Re .map(|i| ItemTarget::Item { index: index(i), explicit: true, aligned }) .ok_or_else(|| bad(cmd, format!("`{key}` must be an appearance item index (paint order) or null"))), // The active item is a row of the first selected object's own stack. - None if p.get("ids").is_some() || p.get("id").is_some() || targets_contents(p)? => Ok(ItemTarget::Top), + None if p.get("ids").is_some() || p.get("id").is_some() || contents => Ok(ItemTarget::Top), // A row of a graph design's art in a series stands for nothing: the commands leave that art out. None if s.active().and_then(|st| st.selection.subjects().first().map(|id| super::graph::is_design_art(&st.doc, *id))) == Some(true) => { Ok(ItemTarget::Top) diff --git a/crates/engine/src/cmd/paint.rs b/crates/engine/src/cmd/paint.rs index 1ac467789c..c3e64db4d0 100644 --- a/crates/engine/src/cmd/paint.rs +++ b/crates/engine/src/cmd/paint.rs @@ -1474,8 +1474,6 @@ fn selected_part_target(s: &Session, p: &Value, cmd: &str) -> Result