From 98692d9d4828da2e430863e989a716166b8a8bb0 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 19 Nov 2026 05:32:34 -0800 Subject: [PATCH] Color Wheel: a null id keeps the paint on the selected characters paint.setFill and paint.setStroke read a null `ids` or `id` as naming no object, as the other paint commands do, so while the Type tool has characters selected the paint goes to those characters and the rest of the type keeps its paint. Before, a null `id` or `ids` recolored the whole type object. While the Live Paint Bucket is the active tool, paint.proxies answers null for fillOpacity and strokeOpacity, so the Color Wheel's opacity row is gray: a fill or stroke chosen then goes to the bucket, and an opacity has nothing to go to. The doc comment of proxy_opacity names paint.setStroke for the stroke opacity. --- crates/engine/src/cmd/paint.rs | 27 ++++++++++-------- crates/engine/src/tests/paintopacity.rs | 37 +++++++++++++++++++++++++ docs/mcp.md | 4 +-- 3 files changed, 54 insertions(+), 14 deletions(-) diff --git a/crates/engine/src/cmd/paint.rs b/crates/engine/src/cmd/paint.rs index f9f1bd5eb9..ab0bb5f57b 100644 --- a/crates/engine/src/cmd/paint.rs +++ b/crates/engine/src/cmd/paint.rs @@ -160,7 +160,7 @@ pub fn proxy_specs() -> Vec { "Fill and Stroke", [], None, - "{} → {fill, stroke: the paints the Fill/Stroke proxies show (the Appearance panel's active item for the proxy of its kind, else the first selected object's, a group's first painted object's, a Live Paint group's first face's fill and first edge's stroke, type: its first run's; else the defaults for new art; when that object is a gradient mesh with points picked by the Mesh tool, Direct Selection or the Lasso and no fill item is active, the fill is its first picked point's color), fillActive, fillMixed, strokeMixed: the selected objects' (or a selected group's contents') fills (strokes) differ, a Live Paint group counting with its faces' fills and its edges' strokes, shown as a \"?\" proxy (a gradient mesh with points picked counts with their colors), fillOpacity, strokeOpacity: 0..100, the opacity of the fill item that paint.setFill {opacity} sets (the stroke item that paint.setStroke {opacity} sets), from the first selected object (or painted object in a selected group; a selected path of a compound path stands for its compound) that has one (a gradient mesh's first picked point's), or null with nothing selected (the defaults for new art), for an object selected in a symbol instance, while the Type tool has characters selected, and when only type characters or objects without that item are selected}", + "{} → {fill, stroke: the paints the Fill/Stroke proxies show (the Appearance panel's active item for the proxy of its kind, else the first selected object's, a group's first painted object's, a Live Paint group's first face's fill and first edge's stroke, type: its first run's; else the defaults for new art; when that object is a gradient mesh with points picked by the Mesh tool, Direct Selection or the Lasso and no fill item is active, the fill is its first picked point's color), fillActive, fillMixed, strokeMixed: the selected objects' (or a selected group's contents') fills (strokes) differ, a Live Paint group counting with its faces' fills and its edges' strokes, shown as a \"?\" proxy (a gradient mesh with points picked counts with their colors), fillOpacity, strokeOpacity: 0..100, the opacity of the fill item that paint.setFill {opacity} sets (the stroke item that paint.setStroke {opacity} sets), from the first selected object (or painted object in a selected group; a selected path of a compound path stands for its compound) that has one (a gradient mesh's first picked point's), or null with nothing selected (the defaults for new art), for an object selected in a symbol instance, while the Live Paint Bucket is the active tool, while the Type tool has characters selected, and when only type characters or objects without that item are selected}", always, proxies ), @@ -234,16 +234,19 @@ impl Session { None } - /// The opacity (0..1) of the fill (or stroke) that `paint.setFill {opacity}` sets: the item's, - /// or for a gradient mesh with points picked the first picked point's. The rows the command - /// would edit are read in order (a group without an active Appearance row stands for its - /// contents), and the first that exists answers. `None` with nothing selected, for an object - /// selected in a symbol instance, while the Type tool has characters selected, and when only - /// type characters, objects without that item or the art of graph designs in a graph series - /// are selected. + /// The opacity (0..1) of the fill that `paint.setFill {opacity}` sets (or of the stroke that + /// `paint.setStroke {opacity}` sets): the item's, or for a gradient mesh with points picked the + /// first picked point's. The rows the command would edit are read in order (a group without an + /// active Appearance row stands for its contents), and the first that exists answers. `None` + /// with nothing selected, for an object selected in a symbol instance, while the Live Paint + /// Bucket is the active tool, while the Type tool has characters selected, and when only type + /// characters, objects without that item or the art of graph designs in a graph series are + /// selected. pub fn proxy_opacity(&self, stroke: bool) -> Option { let st = self.active()?; - if st.selection.symbol_part.is_some() { + // The Live Paint Bucket takes a fill or stroke chosen as the color it paints with, and the + // selection keeps its own (for_bucket). + if st.selection.symbol_part.is_some() || self.tool_id() == LIVE_PAINT_BUCKET { return None; } // The command would give the opacity to the characters, which have none of their own. @@ -638,9 +641,9 @@ fn apply_paint_opacity(s: &mut Session, p: &Value, paint: Option, opacity let focus = switch_or(p, "focus", true, cmd)?; // An opacity alone places no gradient, so `span` may only be "object" with it. let span = spans_targets(p, paint.as_ref().unwrap_or(&Paint::None)).map_err(|e| bad(cmd, e))?; - // Characters selected with the Type tool take the paint, not the whole type object (#1063). - if p.get("ids").is_none() - && p.get("id").is_none() + // Characters selected with the Type tool take the paint, not the whole type object (#1063). A + // null `ids` or `id` names no object, as `given_nodes` reads it. + if ["ids", "id"].iter().all(|k| p.get(k).is_none_or(Value::is_null)) && p.get("item").is_none() && let Some((id, a, b)) = super::textedit::editing_range(s)? && a != b diff --git a/crates/engine/src/tests/paintopacity.rs b/crates/engine/src/tests/paintopacity.rs index 2a8b753366..f9bfb00e3e 100644 --- a/crates/engine/src/tests/paintopacity.rs +++ b/crates/engine/src/tests/paintopacity.rs @@ -396,3 +396,40 @@ fn a_picked_mesh_point_takes_the_fill_opacity() { assert!(o.iter().enumerate().all(|(i, a)| i == 4 || *a == 1.0), "{o:?}"); assert_eq!(proxies(&mut s)["fillOpacity"], 30.0); } + +/// A null `id` or `ids` names no object, so while the Type tool has characters selected the paint +/// goes to those characters only, and the rest of the type keeps its paint. +#[test] +fn a_null_id_leaves_the_paint_to_the_selected_characters() { + for key in ["id", "ids"] { + let mut s = session(); + let t = text(&mut s); + select(&mut s, &[t]); + s.select_tool("type", ViewInfo::default()).unwrap(); + s.set_tool_option("textSelection", &json!({"editing": t.0, "anchor": 0, "caret": 1})); + s.execute("paint.setFill", &json!({"color": "#ff0000", key: null})).unwrap(); + let NodeKind::Text(tx) = &node(&s, t).kind else { panic!("not type") }; + let fills: Vec = tx.runs.iter().map(|r| r.style.fill.clone()).collect(); + assert_eq!(fills.first(), Some(&Paint::solid(Color::rgb8(255, 0, 0))), "{key}: {fills:?}"); + assert!(fills.len() > 1 && fills[1..].iter().all(|f| *f != Paint::solid(Color::rgb8(255, 0, 0))), "{key}: {fills:?}"); + let e = s.execute("paint.setFill", &json!({"opacity": 40, key: null})).unwrap_err(); + assert!(e.to_string().contains("type characters have no opacity of their own"), "{key}: {e}"); + } +} + +/// While the Live Paint Bucket is the active tool, a fill or stroke chosen goes to the bucket, so +/// `paint.proxies` answers no opacity for the selection and an opacity is an error that leaves the +/// document as it was. +#[test] +fn the_live_paint_bucket_answers_no_opacity() { + let mut s = session(); + let id = rect(&mut s, 10.0); + select(&mut s, &[id]); + assert_eq!(proxies(&mut s)["fillOpacity"], 100.0); + s.select_tool("livePaintBucket", ViewInfo::default()).unwrap(); + assert_eq!(proxies(&mut s)["fillOpacity"], Value::Null); + assert_eq!(proxies(&mut s)["strokeOpacity"], Value::Null); + let doc = s.doc().unwrap().doc.clone(); + assert!(s.execute("paint.setFill", &json!({"opacity": 40})).is_err()); + assert_eq!(*s.doc().unwrap().doc, *doc); +} diff --git a/docs/mcp.md b/docs/mcp.md index d5be9fe47c..ec50aba777 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -862,8 +862,8 @@ its kind (`paint.proxies`) and the Gradient tool's annotator then show that row. (0 to 100, a percentage as in `transparency.set`), which sets the opacity of the fill or stroke row they paint, with or without a new paint, as one undo step. An opacity that no target takes is an error and also leaves the paint undone. Without a new paint, `objects` counts only the targets that took the opacity. `paint.proxies` answers it as `fillOpacity` and `strokeOpacity`, from the first selected object that has -that row (a selected path of a compound path answers with its compound path's row, which the commands edit). It answers null with nothing selected, for an object selected in a symbol instance, while the Type tool -has characters selected, and when only type characters (which have no opacity of their own) or objects without that +that row (a selected path of a compound path answers with its compound path's row, which the commands edit). It answers null with nothing selected, for an object selected in a symbol instance, while the Live Paint Bucket is the +active tool, while the Type tool has characters selected, and when only type characters (which have no opacity of their own) or objects without that row are selected. Live effects take the same `item` to apply to one fill or stroke instead of the whole object: `run_command effect.apply {"effect": "path.offsetPath", "item": 0}`, and `effect.remove`, `effect.setParams` (`visible` toggles one) and `effect.duplicate` address that item's effects;