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.
This commit is contained in:
dotCooCoo committed 2026-11-28 12:03:06 -08:00
1 parent c4c672a855
commit e87a7f09d9
2 files changed
+3 -3

No files matched your search

+3 -1
View File
@@ -253,6 +253,8 @@ pub(crate) fn item_target(s: &Session, p: &Value, cmd: &str) -> Result<ItemTarge
/// [`item_target`] read from param `key` (e.g. `fromItem`).
pub(crate) fn item_target_at(s: &Session, p: &Value, key: &str, cmd: &str) -> Result<ItemTarget> {
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)
-2
View File
@@ -1474,8 +1474,6 @@ fn selected_part_target(s: &Session, p: &Value, cmd: &str) -> Result<Option<(Nod
}
let part = super::brushsym::selected_part(s)?;
if part.is_some() {
// Read `target` first: `item_target` stops at a null `id` or `ids` before it reads `target`.
super::appearance::targets_contents(p)?;
item_target(s, p, cmd)?;
}
Ok(part)