diff --git a/crates/engine/src/cmd/gradient.rs b/crates/engine/src/cmd/gradient.rs index e6086b670d..7c843ef8b7 100644 --- a/crates/engine/src/cmd/gradient.rs +++ b/crates/engine/src/cmd/gradient.rs @@ -61,7 +61,9 @@ pub(crate) fn active_gradient(s: &Session) -> Option { fn select_stop(s: &mut Session, p: &Value) -> Result { const C: &str = "gradient.selectStop"; // No document is needed for the default paint's gradient, so this does not use `refuse_symbol_part`. - if s.active().is_some_and(|st| st.selection.symbol_part.is_some()) { + // While the Live Paint Bucket is active the proxies show the default paint, whose stops can be + // selected with a part picked. + if s.tool_id() != super::paint::LIVE_PAINT_BUCKET && s.active().is_some_and(|st| st.selection.symbol_part.is_some()) { return Err(super::brushsym::part_only()); } let index = match p.get("index") { @@ -82,8 +84,10 @@ fn select_stop(s: &mut Session, p: &Value) -> Result { /// Whose gradient a selected stop belongs to: the active document, its first selected object /// (None: the default paint), whether a part of a symbol instance's art is picked, the proxy in -/// front and the Appearance panel's active item. Selecting other art, picking a part of the -/// instance, toggling the proxy or picking another item leaves no stop selected. +/// front, the Appearance panel's active item and whether the Live Paint Bucket is the active tool +/// (its proxies show the default paint). Selecting other art, picking a part of the instance, +/// toggling the proxy, picking another item or choosing the bucket or leaving it leaves no stop +/// selected. #[derive(Clone, Copy, Debug, PartialEq)] pub(crate) struct StopOwner { doc: Option, @@ -91,6 +95,7 @@ pub(crate) struct StopOwner { part: bool, fill: bool, item: Option, + bucket: bool, } impl StopOwner { @@ -102,6 +107,7 @@ impl StopOwner { part: st.is_some_and(|d| d.selection.symbol_part.is_some()), fill: s.fill_active, item: s.appearance_item(), + bucket: s.tool_id() == super::paint::LIVE_PAINT_BUCKET, } } } diff --git a/crates/engine/src/cmd/gradpresets.rs b/crates/engine/src/cmd/gradpresets.rs index 037033ea8a..f308010ad5 100644 --- a/crates/engine/src/cmd/gradpresets.rs +++ b/crates/engine/src/cmd/gradpresets.rs @@ -33,7 +33,7 @@ pub fn specs() -> Vec { "Apply Gradient Preset", [], None, - "{name: a preset's name (gradient.presets.list), stroke?, item?, ids?|id?, target? (as paint.editGradient)} give the gradient behind the active proxy (or the targeted fill or stroke) the preset's type, stops, method, spread and repeats (a freeform preset's: the first three), and a fill its dither, keeping its placement; a solid or no paint becomes the gradient. One undo step, as paint.editGradient → {name, ids: the objects painted (none: only the default changed)}", + "{name: a preset's name (gradient.presets.list), stroke?, item?, ids?|id?, target? (as paint.editGradient)} give the gradient behind the active proxy (or the targeted fill or stroke) the preset's type, stops, method, spread and repeats (a freeform preset's: the first three), and a fill its dither, keeping its placement; a solid or no paint becomes the gradient. One undo step, as paint.editGradient (while the Live Paint Bucket is the active tool and no ids, id or item are given, only the default changes, by the active proxy) → {name, ids: the objects painted (none: only the default changed)}", has_doc, apply ), @@ -207,6 +207,10 @@ fn apply(s: &mut Session, p: &Value) -> Result { const C: &str = "gradient.presets.apply"; let name = name_param(p, C)?; let preset = s.gradient_preset(name).ok_or_else(|| bad(C, format!("no gradient preset `{name}` (see gradient.presets.list)")))?; + // While the Live Paint Bucket is active, the gradient it paints with changes, chosen by the + // active proxy rather than the selection's Appearance row (as paint.editGradient chooses). + let bucket = super::paint::bucket_color_params(s, p); + let p = bucket.as_ref().unwrap_or(p); let stroke = edits_stroke(s, p, item_target(s, p, C)?, !s.fill_active, C)?; let g = &preset.gradient; let mut edit = p.clone(); diff --git a/crates/engine/src/cmd/stroke.rs b/crates/engine/src/cmd/stroke.rs index b826256f2f..4f10bf0ac0 100644 --- a/crates/engine/src/cmd/stroke.rs +++ b/crates/engine/src/cmd/stroke.rs @@ -22,7 +22,7 @@ pub fn specs() -> Vec { "Stroke Options", ["Window", "Stroke"], None, - "{weight?: pt, cap?: butt|round|square, join?: miter|round|bevel, miterLimit?, align?: center|inside|outside, dash?: [d,g,…]|null (a 0 dash with a round or projecting cap draws dots or squares; a new pattern keeps the current offset and alignment), dashOffset? (exact dashes only), alignDashes?: bool (true: dashes fitted to corners and path ends, every run between them holding whole periods with a dash centred on each corner and end; false, the default for a new pattern: exact lengths), startArrow?, endArrow?: Arrow|ArrowOpen|LineArrow|Barbed|Concave|DoubleArrow|HalfArrowLeft|HalfArrowRight|Chevron|Feather|Swallowtail|Triangle|TriangleOpen|TriangleReverse|TriangleBar|Kite|Leaf|Drop|Circle|CircleOpen|HalfCircle|Oval|Target|Square|SquareOpen|Tag|TagOpen|Diamond|DiamondOpen|Hexagon|HexagonOpen|Star|Cross|Plus|Bar|DoubleBar|DotOnBar|Slash|DoubleSlash|Bracket|Fork|null|{custom: name} (a custom arrowhead of the arrowheads file, stroke.arrowheads.list)|{Custom: {name, path}} (a custom head with its art, as document.inspect reports one; refused when the path fills no area, parts thinner than a millionth of a head unit counting as none, or has more than 4096 anchors, more than 4096 subpaths or a point more than 64 head units from the tip) (HalfArrowLeft/Right: one barb, left or right of the direction the head points), arrowAlign?: \"extend\" (tip past the end point, default)|\"tip\" (tip on the end point; the stroke is shortened), profile?: \"uniform\"|\"lens\"|\"taperStart\"|\"taperEnd\"|\"pinch\"|\"teardrop\"|\"wave\"|a saved profile's name (stroke.widthProfile.list), widthPoints?, gradientMode? (as document.inspect reports them in strokeOptions, so those read back unchanged; ignored here: a custom profile is set with the Width tool, gradientMode with paint.editGradient), item?: stroke item index|null (omitted: the Appearance panel's active item if it is a stroke, else the top stroke, created when missing), ids?|id?, target?: \"object\"|\"contents\", aligned?: bool (index and item are rows of the first target's stack: each other target edits its equal one, as the Appearance panel does for a mixed selection; with the art of a graph design in a series given first, rows of the art's stack: docs/mcp.md)} Without a stroke item, type takes weight, cap, join, miterLimit, align (around its glyph outlines; the type stays live) and the dash options as its characters' stroke (every run; text.setRangeStyle `strokeOptions` styles a range), and images and symbol instances (also in groups) are left alone. With nothing selected (and no ids) they set up the next object drawn (appearance.newArt; weight always does). On a path directly in a graph series, the graph also stores a weight it changes on the topmost visible stroke (docs/mcp.md); on a graph label's stroke row, the graph stores the label's topmost visible fill and stroke rows for every label of its kind, and on its characters the stroke options they take; on a graph's axis line, tick mark or radar ring, the graph stores the paint, weight, opacity and blend mode of its topmost visible fill and stroke rows that the edit changes, and the weight it writes to the topmost visible stroke, for every line of its kind, and not its caps, joins, dashes, alignment or arrowheads. While the Live Paint Bucket is the active tool and no ids, id or item are given, only the stroke for new art changes (the one the bucket paints with) → {objects: how many objects took the stroke options}", + "{weight?: pt, cap?: butt|round|square, join?: miter|round|bevel, miterLimit?, align?: center|inside|outside, dash?: [d,g,…]|null (a 0 dash with a round or projecting cap draws dots or squares; a new pattern keeps the current offset and alignment), dashOffset? (exact dashes only), alignDashes?: bool (true: dashes fitted to corners and path ends, every run between them holding whole periods with a dash centred on each corner and end; false, the default for a new pattern: exact lengths), startArrow?, endArrow?: Arrow|ArrowOpen|LineArrow|Barbed|Concave|DoubleArrow|HalfArrowLeft|HalfArrowRight|Chevron|Feather|Swallowtail|Triangle|TriangleOpen|TriangleReverse|TriangleBar|Kite|Leaf|Drop|Circle|CircleOpen|HalfCircle|Oval|Target|Square|SquareOpen|Tag|TagOpen|Diamond|DiamondOpen|Hexagon|HexagonOpen|Star|Cross|Plus|Bar|DoubleBar|DotOnBar|Slash|DoubleSlash|Bracket|Fork|null|{custom: name} (a custom arrowhead of the arrowheads file, stroke.arrowheads.list)|{Custom: {name, path}} (a custom head with its art, as document.inspect reports one; refused when the path fills no area, parts thinner than a millionth of a head unit counting as none, or has more than 4096 anchors, more than 4096 subpaths or a point more than 64 head units from the tip) (HalfArrowLeft/Right: one barb, left or right of the direction the head points), arrowAlign?: \"extend\" (tip past the end point, default)|\"tip\" (tip on the end point; the stroke is shortened), profile?: \"uniform\"|\"lens\"|\"taperStart\"|\"taperEnd\"|\"pinch\"|\"teardrop\"|\"wave\"|a saved profile's name (stroke.widthProfile.list), widthPoints?, gradientMode? (as document.inspect reports them in strokeOptions, so those read back unchanged; ignored here: a custom profile is set with the Width tool, gradientMode with paint.editGradient), item?: stroke item index|null (omitted: the Appearance panel's active item if it is a stroke, else the top stroke, created when missing), ids?|id?, target?: \"object\"|\"contents\", aligned?: bool (index and item are rows of the first target's stack: each other target edits its equal one, as the Appearance panel does for a mixed selection; with the art of a graph design in a series given first, rows of the art's stack: docs/mcp.md)} Without a stroke item, type takes weight, cap, join, miterLimit, align (around its glyph outlines; the type stays live) and the dash options as its characters' stroke (every run; text.setRangeStyle `strokeOptions` styles a range), and images and symbol instances (also in groups) are left alone. With nothing selected (and no ids) they set up the next object drawn (appearance.newArt; weight always does). On a path directly in a graph series, the graph also stores a weight it changes on the topmost visible stroke (docs/mcp.md); on a graph label's stroke row, the graph stores the label's topmost visible fill and stroke rows for every label of its kind, and on its characters the stroke options they take; on a graph's axis line, tick mark or radar ring, the graph stores the paint, weight, opacity and blend mode of its topmost visible fill and stroke rows that the edit changes, and the weight it writes to the topmost visible stroke, for every line of its kind, and not its caps, joins, dashes, alignment or arrowheads. While the Live Paint Bucket is the active tool and no ids, id or item are given, only the stroke for new art changes (the bucket paints edges with its color and weight) → {objects: how many objects took the stroke options}", has_doc, stroke_set ), @@ -31,7 +31,7 @@ pub fn specs() -> Vec { "Stroke Weight Up", [], Some("Cmd+Alt+."), - "{ids?|id?} raise each selected stroke's weight by one step of Units › Stroke (a quarter unit below one unit, then whole units; up to 1000 pt), each from its own weight: the selected objects' active or top stroke, type's stroked characters; objects without a stroke are left alone. With nothing selected (and no ids), the weight of the next object drawn. On a path directly in a graph series, the graph also stores the new weight of the topmost visible stroke, and on a graph label the new weight of its characters' stroke or its stroke row for every label of its kind, and on a graph's axis line, tick mark or radar ring its rows for every line of its kind (docs/mcp.md). With nothing selected, or while the Live Paint Bucket is the active tool and no ids, id or item are given, the weight for new art steps instead → {objects}", + "{ids?|id?} raise each selected stroke's weight by one step of Units › Stroke (a quarter unit below one unit, then whole units; up to 1000 pt), each from its own weight: the selected objects' active or top stroke, type's stroked characters; objects without a stroke are left alone. With nothing selected (and no ids), the weight of the next object drawn, and so while the Live Paint Bucket is the active tool and no ids or id are given. On a path directly in a graph series, the graph also stores the new weight of the topmost visible stroke, and on a graph label the new weight of its characters' stroke or its stroke row for every label of its kind, and on a graph's axis line, tick mark or radar ring its rows for every line of its kind (docs/mcp.md) → {objects}", has_doc, |s, p| stroke_step(s, p, true) ), @@ -49,7 +49,7 @@ pub fn specs() -> Vec { "Stroke Options", [], None, - "{arrowScale?: [start %, end %], swapArrows?: bool, flipProfile?: \"along\"|\"across\", brush?: name|null, item?: stroke item index|null, aligned?: bool (as stroke.set), ids?|id?, target?: \"object\"|\"contents\"} Stroke panel extras (with nothing selected, all but brush set up the next object drawn, and so while the Live Paint Bucket is the active tool and no ids, id, item or brush are given: the stroke it paints with)", + "{arrowScale?: [start %, end %], swapArrows?: bool, flipProfile?: \"along\"|\"across\", brush?: name|null, item?: stroke item index|null, aligned?: bool (as stroke.set), ids?|id?, target?: \"object\"|\"contents\"} Stroke panel extras (with nothing selected, all but brush set up the next object drawn, and so while the Live Paint Bucket is the active tool and no ids, id, item or brush are given)", has_doc, stroke_advanced ), @@ -233,9 +233,12 @@ fn own_stroke_or_leaves(s: &Session, p: &Value) -> Result Result { const C: &str = "stroke.set"; let change = StrokeChange::parse(p, C)?; + // The stroke the Live Paint Bucket paints with changes; the selection keeps its own, and its + // active Appearance row is not a target. + let bucket_p = super::paint::bucket_color_params(s, p); + let bucket = bucket_p.is_some(); + let p = bucket_p.as_ref().unwrap_or(p); let item = item_target(s, p, C)?.of_kind(s, false); - // The stroke the Live Paint Bucket paints with changes; the selection keeps its own. - let bucket = super::paint::for_bucket(s, p); let mut ids = if bucket { vec![] } else if item == ItemTarget::Top { @@ -582,10 +585,12 @@ fn stroke_advanced(s: &mut Session, p: &Value) -> Result { if scale.is_none() && flip.is_none() && !swap && brush.is_none() { return Err(bad(C, "nothing to change")); } - let item = item_target(s, p, C)?.of_kind(s, false); // As stroke.set: the stroke the Live Paint Bucket paints with changes; the selection keeps its own. // A brush still goes to the selection. - let bucket = brush.is_none() && super::paint::for_bucket(s, p); + let bucket_p = if brush.is_none() { super::paint::bucket_color_params(s, p) } else { None }; + let bucket = bucket_p.is_some(); + let p = bucket_p.as_ref().unwrap_or(p); + let item = item_target(s, p, C)?.of_kind(s, false); let ids = if bucket { vec![] } else { item.targets(s, p)? }; let new_art = bucket || no_targets(&ids, p); // The art of a graph design in a series keeps the design's stroke. diff --git a/crates/engine/src/cmd/xform.rs b/crates/engine/src/cmd/xform.rs index 0fc5340e2f..c592e552a4 100644 --- a/crates/engine/src/cmd/xform.rs +++ b/crates/engine/src/cmd/xform.rs @@ -30,7 +30,7 @@ pub fn specs() -> Vec { "Sample Color", [], None, - "{color (#rrggbbaa and #rgba are refused), stroke?: bool (default: whichever proxy is active), ids?, stop?: index, clearStroke?: bool} sample a color into the active fill/stroke (and the selection; `ids: []` changes only the paint default); `clearStroke: true` requires `stroke: false`, `ids: []` and no `stop`, and clears the default stroke after sampling an image into the fill; with `stop`, recolor that stop of the gradient behind the proxy instead (paint.editGradient); in a CMYK document an RGB color is stored as CMYK through the color settings, as paint.setFill stores it", + "{color (#rrggbbaa and #rgba are refused), stroke?: bool (default: whichever proxy is active), ids?, stop?: index, clearStroke?: bool} sample a color into the active fill/stroke (and the selection; `ids: []` changes only the paint default, and so does a sample without ids while the Live Paint Bucket is the active tool, `stop` included); `clearStroke: true` requires `stroke: false`, `ids: []` and no `stop`, and clears the default stroke after sampling an image into the fill; with `stop`, recolor that stop of the gradient behind the proxy instead (paint.editGradient); in a CMYK document an RGB color is stored as CMYK through the color settings, as paint.setFill stores it", has_doc, sample_color ), diff --git a/crates/engine/src/session/edit.rs b/crates/engine/src/session/edit.rs index d39818e135..10248e3434 100644 --- a/crates/engine/src/session/edit.rs +++ b/crates/engine/src/session/edit.rs @@ -321,6 +321,9 @@ impl Session { if self.script_running() { return Err(EngineError::Busy); } + // While the Live Paint Bucket is active, paint previews change only the bucket's colors, so + // each preview starts from the colors the interaction began with. + let bucket = self.tool_id() == cmd::LIVE_PAINT_BUCKET; let (paint, restore_paint) = { let menu = self.menu.clone(); let st = self.doc_mut()?; @@ -334,8 +337,10 @@ impl Session { st.doc = it.doc.clone(); // A batch, or a preview that changed the new-art paints (a pattern rename), started from // the paints the interaction began with. - let restore_paint = - cmd == "command.batch" || it.preview.as_ref().is_some_and(|(id, _)| id == "command.batch") || it.color_mode_paints.is_some(); + let restore_paint = bucket + || cmd == "command.batch" + || it.preview.as_ref().is_some_and(|(id, _)| id == "command.batch") + || it.color_mode_paints.is_some(); let paint = it.paint.clone(); it.preview_paint = None; it.color_mode_paints = None; diff --git a/crates/engine/src/tests/build.rs b/crates/engine/src/tests/build.rs index 345bb2dd51..41a4287492 100644 --- a/crates/engine/src/tests/build.rs +++ b/crates/engine/src/tests/build.rs @@ -3265,7 +3265,15 @@ fn live_paint_bucket_paint_and_stroke_commands_leave_the_selection_unpainted() { ("paint.none", json!({}), Box::new(|s: &Session| s.paint.fill == Paint::None)), ("paint.lastColor", json!({"stroke": false}), Box::new(move |s: &Session| s.paint.fill == Paint::solid(blue))), ("paint.lastGradient", json!({"stroke": false}), Box::new(move |s: &Session| is_gradient(&s.paint.fill))), - ("paint.complement", json!({"stroke": false}), Box::new(move |s: &Session| s.paint.fill == cyan)), + ( + "paint.complement", + json!({"stroke": false}), + Box::new({ + let cyan = cyan.clone(); + move |s: &Session| s.paint.fill == cyan + }), + ), + ("paint.sampleColor", json!({"color": "#00ffff", "stroke": false}), Box::new(move |s: &Session| s.paint.fill == cyan)), ("paint.editGradient", json!({"stroke": false, "angle": 45}), Box::new(move |s: &Session| is_gradient(&s.paint.fill))), ( "paint.editGradient", @@ -3329,6 +3337,69 @@ fn live_paint_bucket_named_objects_and_brushes_still_take_the_stroke() { assert_eq!(node(&s, rect).appearance.stroke().and_then(|st| st.brush.clone()).as_deref(), Some("3 pt. Round")); } +/// While the Live Paint Bucket is active and the Fill proxy is in front, a gradient preset and a +/// color sampled into a gradient stop change the bucket's fill, even when the selection's active +/// Appearance row is a stroke. +#[test] +fn live_paint_bucket_gradient_preset_and_sampled_stop_follow_the_active_proxy() { + let mut s = session(); + live(&mut s); + let rect = rect(&mut s, 300.0, 300.0, 40.0, 40.0); + s.execute("select.set", &json!({"ids": [rect.0]})).unwrap(); + s.execute("appearance.setActiveItem", &json!({"index": 1})).unwrap(); + s.select_tool("livePaintBucket", ViewInfo::default()).unwrap(); + s.execute("paint.toggleActive", &json!({"fill": true})).unwrap(); + assert_eq!(s.appearance_item(), Some(1), "the stroke row stays active"); + let (art, stroke) = (node(&s, rect), s.paint.stroke.clone()); + s.execute("gradient.presets.apply", &json!({"name": "vignette"})).unwrap(); + let Paint::Gradient(g) = &s.paint.fill else { panic!("the bucket's fill is not a gradient") }; + assert_eq!(g.gradient.kind, vectorcraft_color::GradientKind::Radial); + assert_eq!(s.paint.stroke, stroke, "the bucket's stroke stays"); + s.execute("paint.sampleColor", &json!({"color": "#00ffff", "stop": 0})).unwrap(); + let Paint::Gradient(g) = &s.paint.fill else { panic!("the bucket's fill is not a gradient") }; + assert_eq!(g.gradient.stops[0].color, Color::from_hex("#00ffff").unwrap(), "the sampled stop"); + assert_eq!(node(&s, rect), art, "the selection keeps its paint"); +} + +/// A gradient stop selected on the selection's gradient is not selected once the Live Paint +/// Bucket is active (its proxies show the default paint), and one selected on the bucket's +/// gradient is not selected once another tool is chosen. +#[test] +fn live_paint_bucket_and_the_selection_keep_their_own_selected_stop() { + let mut s = session(); + live(&mut s); + let rect = rect(&mut s, 300.0, 300.0, 40.0, 40.0); + s.execute("select.set", &json!({"ids": [rect.0]})).unwrap(); + s.execute("paint.editGradient", &json!({"stroke": false, "kind": "linear"})).unwrap(); + s.execute("gradient.selectStop", &json!({"index": 1})).unwrap(); + assert_eq!(s.selected_stop(), Some(1)); + s.select_tool("livePaintBucket", ViewInfo::default()).unwrap(); + assert_eq!(s.selected_stop(), None, "the selection's stop is not the bucket's"); + s.execute("paint.editGradient", &json!({"stroke": false, "kind": "linear"})).unwrap(); + s.execute("gradient.selectStop", &json!({"index": 0})).unwrap(); + assert_eq!(s.selected_stop(), Some(0)); + s.select_tool("selection", ViewInfo::default()).unwrap(); + assert_eq!(s.selected_stop(), None, "the bucket's stop is not the selection's"); +} + +/// 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] +fn live_paint_bucket_previews_start_from_the_interaction_colors() { + let mut s = session(); + let g = live(&mut s); + s.execute("select.set", &json!({"ids": [g.0]})).unwrap(); + s.select_tool("livePaintBucket", ViewInfo::default()).unwrap(); + s.execute("paint.setFill", &json!({"color": "#ff0000"})).unwrap(); + s.execute("paint.setStroke", &json!({"color": "#0000ff"})).unwrap(); + let (fill, stroke) = (s.paint.fill.clone(), s.paint.stroke.clone()); + s.begin_interaction("Swap").unwrap(); + s.preview("paint.swap", &json!({})).unwrap(); + s.preview("paint.swap", &json!({})).unwrap(); + s.commit_interaction().unwrap(); + assert_eq!((s.paint.fill.clone(), s.paint.stroke.clone()), (stroke, fill), "one swap"); +} + /// A color chosen with the Live Paint Bucket is the current fill: a tool held for a moment (the /// Hand) and let go leaves it in place, so the bucket paints with it afterwards, with New Art Has /// Basic Appearance off and on. diff --git a/crates/engine/src/tests/dynamic_symbols.rs b/crates/engine/src/tests/dynamic_symbols.rs index ff47ab54dc..e136d9f45b 100644 --- a/crates/engine/src/tests/dynamic_symbols.rs +++ b/crates/engine/src/tests/dynamic_symbols.rs @@ -1170,6 +1170,23 @@ fn live_paint_bucket_weight_steps_with_a_picked_symbol_object() { assert_eq!(overrides(&s, inst), 0); } +/// With an object of a dynamic symbol instance picked and the Live Paint Bucket active, a gradient +/// stop of the bucket's fill can be selected and cleared, and the instance keeps its art. +#[test] +fn live_paint_bucket_selects_its_gradient_stop_with_a_picked_symbol_object() { + let mut s = session(); + let inst = pair(&mut s, "dynamic"); + s.execute("symbol.instance.selectPart", &json!({"id": inst.0, "path": [1]})).unwrap(); + s.select_tool("livePaintBucket", ViewInfo::default()).unwrap(); + s.fill_active = true; + s.execute("paint.editGradient", &json!({"kind": "linear"})).unwrap(); + s.execute("gradient.selectStop", &json!({"index": 1})).unwrap(); + assert_eq!(s.selected_stop(), Some(1)); + s.execute("gradient.selectStop", &json!({"index": null})).unwrap(); + assert_eq!(s.selected_stop(), None); + assert_eq!(overrides(&s, inst), 0); +} + #[test] fn selecting_a_guide_too_lets_go_of_the_picked_object() { let mut s = session(); diff --git a/crates/mcp/src/tools/dispatch.rs b/crates/mcp/src/tools/dispatch.rs index 95c8e8671d..12c3b24f37 100644 --- a/crates/mcp/src/tools/dispatch.rs +++ b/crates/mcp/src/tools/dispatch.rs @@ -187,7 +187,7 @@ fn dispatch(b: &mut dyn Backend, name: &str, a: &Args) -> Result StrokeM return StrokeMixed { can_align: true, ..Default::default() }; } if app.session.tool_id() == "livePaintBucket" { - return StrokeMixed::default(); + return StrokeMixed { can_align: true, ..Default::default() }; } let Some(st) = app.session.active() else { return StrokeMixed::default() }; let key = (st.uid, st.revision); diff --git a/crates/ui-egui/src/panels/tests_strokeux.rs b/crates/ui-egui/src/panels/tests_strokeux.rs index b214006e97..fb31dd8514 100644 --- a/crates/ui-egui/src/panels/tests_strokeux.rs +++ b/crates/ui-egui/src/panels/tests_strokeux.rs @@ -125,18 +125,20 @@ fn align_stroke_styles_the_characters_the_type_tool_selects() { /// with, even when the selected objects' strokes differ, as it does with nothing selected. #[test] fn the_stroke_panel_shows_the_live_paint_bucket_stroke_as_one_stroke() { - let ctx = egui::Context::default(); let mut app = app_with_rect(); let a = app.session.active().unwrap().selection.objects[0].0; let b = run(&mut app, "shape.rectangle", json!({"x": 200, "y": 200, "width": 40, "height": 40}))["id"].as_u64().unwrap(); run(&mut app, "stroke.set", json!({"weight": 1, "ids": [a]})); run(&mut app, "stroke.set", json!({"weight": 7, "ids": [b]})); + run(&mut app, "select.set", json!({ "ids": [] })); + let none_selected = stroke_mixed(&app, &egui::Context::default()); + assert!(none_selected.can_align, "Align Stroke applies with nothing selected"); run(&mut app, "select.set", json!({ "ids": [a, b] })); - let mixed = stroke_mixed(&app, &ctx); + let mixed = stroke_mixed(&app, &egui::Context::default()); assert!(mixed.weight, "the selection's weights differ"); app.session.select_tool("livePaintBucket", Default::default()).unwrap(); - let mixed = stroke_mixed(&app, &ctx); - assert_eq!(mixed, StrokeMixed::default(), "one stroke, as with nothing selected"); + let mixed = stroke_mixed(&app, &egui::Context::default()); + assert_eq!(mixed, none_selected, "one stroke that Align Stroke applies to, as with nothing selected"); assert_eq!(stroke::shown_weight(&app, current_stroke(&app).as_ref(), &mixed), Some(app.session.paint.stroke_width)); } diff --git a/docs/mcp.md b/docs/mcp.md index a92cf69150..c90ced9420 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -4584,13 +4584,14 @@ already walks Image Trace. Short agent entry points: faces or edges the click reaches, including those that already had the paint. While the Live Paint Bucket is the active tool, a fill or stroke color chosen without `ids`, `id` or `item` (`paint.setFill`, `paint.setStroke`, `paint.none`, `paint.lastColor`, `paint.lastGradient`, `paint.editGradient`, - `paint.invert`, `paint.complement`, `paint.swap`, `paint.default`, a swatch or the Color Picker) becomes the color the - bucket paints with, and so do a stroke weight and the Stroke panel's options (`stroke.set`, `stroke.weightUp`, - `stroke.weightDown`, `stroke.setAdvanced` without `brush`): the selection keeps its paint, and no undo step is - recorded. The Fill and Stroke proxies (`paint.proxies`) show those colors, never mixed, the Stroke panel shows that - stroke as it does with nothing selected, and with New Art Has Basic Appearance off the selection's appearance does not - replace them after a command. They are the current fill and stroke, so another tool chosen afterwards keeps them - until a command or a new selection changes them. + `paint.invert`, `paint.complement`, `paint.sampleColor`, `gradient.presets.apply`, a swatch or the Color Picker), and + `paint.swap` or `paint.default` without `ids` or `id`, becomes the color the bucket paints with, and a stroke weight + (`stroke.set`, `stroke.weightUp`, `stroke.weightDown`) becomes the weight it paints with. The selection keeps its + paint, and no undo step is recorded. The Stroke panel's other options (`stroke.set`, `stroke.setAdvanced` without + `brush`) change the stroke for new art and leave the selection as it is; the bucket takes only the color and weight + of that stroke. The Fill and Stroke proxies (`paint.proxies`) show those colors, never mixed, the Stroke panel shows + that stroke as it does with nothing selected, and with New Art Has Basic Appearance off the selection's appearance + does not replace them after a command. They are also the fill and stroke for new art. With the Live Paint Bucket selected and no drag in progress, Left and Right without Shift, Alt or Cmd/Ctrl (which keep their shortcuts) run `paint.setFill {swatch, ids: []}` (or `paint.setStroke` when the Stroke proxy is in front) with the color swatch before or after the active paint in the