Merge pull request #8328 from dotCooCoo/fix/followup-8305

Color Guide: a script run or a resting link keeps the base color it showed
This commit is contained in:
BFlat
2026-11-18 03:19:34 +07:00
committed by GitHub
2 changed files with 54 additions and 6 deletions
+53 -5
View File
@@ -116,10 +116,11 @@ pub(crate) fn before_command(app: &VectorcraftApp) -> LinkBefore {
let group =
st.zip(s).and_then(|(st, s)| st.doc.swatch_groups.iter().find(|g| g.swatches.iter().any(|w| w.name == s.swatch)).map(|g| g.name.clone()));
let docs = if s.is_some() { app.session.documents().iter().map(|d| d.uid).collect() } else { Vec::new() };
// The color it shows: its swatch's tint in its document, while that is a spot color there.
// The color it shows: its swatch's tint in its document, while that is a spot color there and
// the link does not rest (a resting link shows the color it last showed).
let shown = st
.zip(s)
.filter(|(st, s)| st.doc.swatch(&s.swatch).is_some_and(|w| w.spot))
.filter(|(st, s)| !s.resting && st.doc.swatch(&s.swatch).is_some_and(|w| w.spot))
.and_then(|(st, s)| st.doc.tint_paint(&s.swatch, s.tint)?.color());
let color = s.map(|_| shown.unwrap_or_else(|| base_color(app)));
LinkBefore { active, group, color, docs, active_index: app.session.active_index() }
@@ -225,7 +226,7 @@ fn follow_batch(app: &VectorcraftApp, base: u64, name: String, steps: &[Value],
for (i, step) in steps.iter().enumerate() {
let sid = step["command"].as_str().unwrap_or_default();
let (p, r) = (&step["params"], results.get(i).unwrap_or(&Value::Null));
if sid.starts_with("script.") || sid.starts_with("plugin.") {
if runs_code(sid) {
return None;
}
match docs.in_base() {
@@ -268,15 +269,23 @@ fn follow_batch(app: &VectorcraftApp, base: u64, name: String, steps: &[Value],
spots.next().is_none().then_some(first)
}
/// Whether command `id` runs a script or a plug-in (Run Script, a plug-in filter or a plug-in's own
/// command), whose commands the panel does not follow.
fn runs_code(id: &str) -> bool {
matches!(id, "script.run" | "plugin.run") || vectorcraft_engine::cmd::plugin::is_command_id(id)
}
/// Command `id` ran with `params` and replied `reply`: a spot color base linked to a swatch that
/// Swatch Options renamed links to the new name, and one whose swatch a command deleted or made a
/// process color is no longer linked to it, so a later spot color of the same name does not
/// become the base; the base keeps the color it showed. A `command.batch`'s steps are followed in
/// order ([`follow_batch`]).
/// order ([`follow_batch`]). A script or a plug-in may do anything, so it ends the link.
pub(crate) fn after_command(app: &mut VectorcraftApp, id: &str, params: &Value, reply: &Value, before: LinkBefore) {
let Some(s) = app.ui.color_guide_spot.as_ref() else { return };
let (base, n) = (s.doc, s.swatch.clone());
let name = if id == "command.batch" {
let name = if runs_code(id) {
None
} else if id == "command.batch" {
let steps = params["commands"].as_array().map(Vec::as_slice).unwrap_or_default();
let results = reply["results"].as_array().map(Vec::as_slice).unwrap_or_default();
follow_batch(app, base, n, steps, results, &before)
@@ -1388,6 +1397,45 @@ mod tests {
assert_eq!(spot_name(&app).as_deref(), Some("Ink U"));
}
/// While the link rests, a new spot color of the same name that the panel did not follow does
/// not give the base its color when the next command ends the link.
#[test]
fn a_resting_link_keeps_the_color_it_showed() {
let mut app = spot_app(1.0);
let ctx = egui::Context::default();
frame(&mut app, &ctx);
let shown = base_color(&app);
app.session.execute("swatch.delete", &json!({"name": "Ink"})).unwrap();
frame(&mut app, &ctx);
app.session.execute("swatch.new", &json!({"name": "Ink", "color": "#00cc66", "spot": true})).unwrap();
frame(&mut app, &ctx);
assert!(app.ui.color_guide_spot.as_ref().is_some_and(|s| s.resting), "resting");
assert_eq!(base_color(&app), shown, "a resting link shows the color it showed");
app.run("swatch.new", json!({"name": "Spare", "color": "#999999"})).unwrap();
assert!(app.ui.color_guide_spot.is_none(), "another command ends it");
assert_eq!(base_color(&app), shown, "the base keeps the color it showed");
}
/// A script run ends the link: a script that deletes the spot color and makes another of the
/// same name does not make the new one the base, and the base keeps the color it showed. Listing
/// scripts or plug-ins keeps it.
#[test]
fn a_script_run_ends_the_link() {
let mut app = spot_app(1.0);
let ctx = egui::Context::default();
frame(&mut app, &ctx);
// Commands that only list scripts or plug-ins keep the link, also as batch steps.
app.run("script.engines", json!({})).unwrap();
app.run("plugin.list", json!({})).unwrap();
app.run("command.batch", json!({"commands": [{"command": "script.engines"}]})).unwrap();
assert!(app.ui.color_guide_spot.is_some(), "a script or plug-in listing");
let shown = base_color(&app);
let source = "vc.run('swatch.delete', {name: 'Ink'}); vc.run('swatch.new', {name: 'Ink', color: '#00cc66', spot: true});";
app.run("script.run", json!({"source": source, "name": "t.js"})).unwrap();
assert!(app.ui.color_guide_spot.is_none(), "a script ran");
assert_eq!(base_color(&app), shown, "the base keeps the color it showed");
}
/// A `command.batch` that switches, opens, closes or moves documents follows the spot color
/// base's swatch in its own document and leaves the link alone for steps in the others.
#[test]
+1 -1
View File
@@ -1767,7 +1767,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- **Sample Color from Screen:** an eyedropper button in the Color Picker and `ui.sampleScreenColor` (which can be given a key in Keyboard Shortcuts) pick a color anywhere on the screen with the system's sampler: `NSColorSampler` on macOS, the XDG desktop portal's [PickColor](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Screenshot.html) on Linux, a still copy of every monitor under a crosshair on Windows, and the EyeDropper API in browsers that have it. The color becomes the fill or the stroke as one undo step, or the Color Picker's color, converted from display sRGB into the working RGB space. On Linux, a session without a portal that has PickColor, a portal that does not return from the call within 25 seconds (VectorCraft's own limit) or leaves the bus before it answers, and a portal that ends the request another way each show a status message and end the wait. On Windows, the copy is read as sRGB, so the colors of HDR and wide-gamut displays are not converted; Escape, a click of another mouse button or switching to another window cancels (VectorCraft's own rules). The BSDs and other browsers have no sampler yet; the button is gray there.
- **Color Guide color groups:** with variation cells selected, the Color Guide's Save Color Group to Swatches button saves those cells as one swatch group, and with none selected it saves the harmony colors, as the [help page](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf) describes saving several selected variations together (printed page 135). The group takes the cells in grid order (row by row, left to right, each cell once), is named after the harmony rule and is one undo step; these are VectorCraft's own rules. A selection lasts until the base, the Color Guide Options, the variation mode, the harmony rule, the library limit or the colors the grid shows (for example after a new swatch while the guide is limited to the document's swatches) change.
- **Color Guide colors dragged to Swatches:** a variation cell dragged from the Color Guide onto the Swatches panel's list becomes a swatch of that color, as the [help page](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf) describes for saving variations as individual swatches (printed page 135). In VectorCraft a harmony strip color drags the same way, a drag carries only the grabbed color (the selected cells stay selected and the selection is not saved), it carries the color the cell shows (snapped to the Limit to Library colors), keeps the color's model and does not paint the selected art; the swatch follows the panel's rules for a dropped color (`swatch.new`, one undo step, a color that is already a swatch is added again under another name, a drop on a color group joins it). These are VectorCraft's own rules. Tests: `a_dragged_guide_color_carries_its_color_and_applies_nothing` and `a_guide_color_dragged_onto_the_swatches_panel_becomes_a_swatch` in `crates/ui-egui/src/panels/color_guide.rs`.
- **Color Guide tints of a spot color:** when the Color Guide's base is a spot color, or a tint of one, chosen in the Swatches panel, with the Color panel's tint slider or with the base chip, the cells right of the center in the base row of Tints/Shades are tints of that spot color: a click paints the art with the tint, a drag carries it, and Save Colors as Swatches and Save Color Group to Swatches make tint swatches ("Ink 60%") linked to the spot color, so they follow an edit of it. The [help page](https://helpx.adobe.com/illustrator/desktop/manage-colors/learn-color-basics/color-guide-panel-overview.html) says spot colors are kept only on the right side of Tints/Shades and every other variation gives process colors. The tint percentages (the base's tint reduced by the share each cell goes toward white), the shades on the left staying process colors, a Limit to Library giving process colors, and a global process base keeping plain colors are VectorCraft's own rules. So are these: renaming the spot color in Swatch Options, also as a `command.batch` step, keeps it the base, and so do an Undo and a Redo of the rename; deleting it (or its color group), making it a process color or closing its document ends the link, so a later spot color of the same name does not become the base until it is chosen, and the base keeps the color it showed. A batch's steps in other documents leave the link alone. `swatch.new {colors}` and `swatch.newGroup {colors}` take `{swatch, tint}` entries. Tests: `a_spot_color_base_gives_tints_of_that_spot_color`, `a_tinted_spot_base_gives_lighter_tints_and_a_lost_link_gives_process_colors`, `a_renamed_spot_color_stays_the_base`, `a_deleted_spot_color_ends_the_link`, `an_undone_rename_keeps_the_link`, `a_batch_follows_the_spot_color_across_documents`, `a_deleted_color_group_ends_the_link`, `saved_spot_tints_are_tint_swatches_of_the_spot_color`, `a_dragged_spot_tint_becomes_a_tint_swatch`, `a_clicked_spot_color_swatch_becomes_a_linked_color_guide_base`, `colors_entries_naming_a_spot_color_save_tint_swatches`.
- **Color Guide tints of a spot color:** when the Color Guide's base is a spot color, or a tint of one, chosen in the Swatches panel, with the Color panel's tint slider or with the base chip, the cells right of the center in the base row of Tints/Shades are tints of that spot color: a click paints the art with the tint, a drag carries it, and Save Colors as Swatches and Save Color Group to Swatches make tint swatches ("Ink 60%") linked to the spot color, so they follow an edit of it. The [help page](https://helpx.adobe.com/illustrator/desktop/manage-colors/learn-color-basics/color-guide-panel-overview.html) says spot colors are kept only on the right side of Tints/Shades and every other variation gives process colors. The tint percentages (the base's tint reduced by the share each cell goes toward white), the shades on the left staying process colors, a Limit to Library giving process colors, and a global process base keeping plain colors are VectorCraft's own rules. So are these: renaming the spot color in Swatch Options, also as a `command.batch` step, keeps it the base, and so do an Undo and a Redo of the rename; deleting it (or its color group), making it a process color or closing its document ends the link, so a later spot color of the same name does not become the base until it is chosen, and the base keeps the color it showed. A batch's steps in other documents leave the link alone. Running a script or a plug-in, also as a batch step, ends the link, and a spot color of the same name that appears while the link waits for an Undo does not give the base its color. `swatch.new {colors}` and `swatch.newGroup {colors}` take `{swatch, tint}` entries. Tests: `a_spot_color_base_gives_tints_of_that_spot_color`, `a_tinted_spot_base_gives_lighter_tints_and_a_lost_link_gives_process_colors`, `a_renamed_spot_color_stays_the_base`, `a_deleted_spot_color_ends_the_link`, `an_undone_rename_keeps_the_link`, `a_batch_follows_the_spot_color_across_documents`, `a_deleted_color_group_ends_the_link`, `a_resting_link_keeps_the_color_it_showed`, `a_script_run_ends_the_link`, `saved_spot_tints_are_tint_swatches_of_the_spot_color`, `a_dragged_spot_tint_becomes_a_tint_swatch`, `a_clicked_spot_color_swatch_becomes_a_linked_color_guide_base`, `colors_entries_naming_a_spot_color_save_tint_swatches`.
- **Stroke visibility (#1253):** adding paint to a previously unpainted zero-width stroke restores the existing 1 pt default (`PaintDefaults::default`, `Appearance::set_stroke`), for the selected appearance item, the new-art defaults and Swap Fill/Stroke. Positive widths are kept; recoloring a painted zero-width stroke keeps its explicit zero. A real Eyedropper-to-new-shape sequence reproduces the zero-width inheritance. Five engine regressions cover creation, defaults, targeted items, preserved widths and one-step Undo/Redo (`crates/engine/tests/it/stroke_visibility.rs`).
- **Gradients:** lossless, validated gradient params; gradients follow rotate, reflect, shear, non-uniform scale and distortions; the Gradient tool edits the fill or stroke of the active proxy, type included; an interactive on-canvas annotator (move, length/angle, rotate, add/move/delete/duplicate stops, midpoints, a stop popover, Delete and arrow keys). The Gradient panel has the Fill/Stroke proxy, a gradient-swatch dropdown with Save to Swatches, midpoint locations, Alt-drag to copy or swap stops, swatch drops on the ramp and a stop eyedropper; copied appearances and graphic styles place gradients on each target's own bounds; gradient handles, both ends of a vector drawn on the art and the start of a clicked one snap as other drawn points do (path segments, construction guides and View › Snap to Glyph's guides included) and honour Constrain Angle. Gradient stops stay linked to global and spot swatches. Freeform gradients (points and lines) are edited on the canvas; radial gradients have an extent ellipse, an aspect handle and an off-centre focal point (SVG `fx`/`fy`, PDF two-point radials). A stroke's gradient runs within, along or across it. Object ▸ Expand turns gradients into N objects or a gradient mesh.
A gradient stop that loses its link to a spot swatch (the swatch deleted, a recolor or adjustment that unlinks it, a library gradient, or a library character style linked to a swatch the document lacks) keeps the color it shows at full tint and drops the process plates it printed with that ink, as a stop given a plain color does; this is VectorCraft's own rule. Evidence: `tests::mapping_links_drops_the_process_plates_of_unlinked_stops` in `crates/color`, `tests::linked_stops::deleting_a_spot_swatch_takes_the_process_plates_of_the_stops_it_unlinks` and `tests::library::library_stops_unlinked_from_their_swatch_keep_no_process_plates` in `crates/engine`.