Merge pull request #8858 from dotCooCoo/fix/style-redefine-series-own-links

Graphic Styles: Redefine Graphic Style keeps the own style of a path inside a series group linked to the target
This commit is contained in:
BFlat
2026-11-21 10:56:45 +07:00
committed by GitHub
4 changed files with 148 additions and 5 deletions
+139
View File
@@ -3455,6 +3455,145 @@ fn redefining_a_graphic_style_keeps_an_edited_mark_of_a_linked_series_group() {
assert!(marks[1..].iter().all(|m| d.node(*m).unwrap().extras().graphic_style == Some(style.id)));
}
/// A column graph whose series 0 group is linked to style "Blue" (as a file can hold it) and whose first path directly
/// inside that group is linked to style "Green" and has its look: the session, the graph, the group, series 0's paths,
/// and the ids of "Blue" and "Green".
fn linked_group_with_a_green_mark() -> (Session, NodeId, NodeId, Vec<NodeId>, u32, u32) {
let (mut s, id, _, marks) = column_marks();
let (group, _) = series_0_group(&s, id);
let (blue, green) = blue_and_green_styles(&mut s);
link_group_and_member(&mut s, group, &blue, marks[0], &green);
(s, id, group, marks, blue.id, green.id)
}
/// Graphic styles "Blue" (a blue fill at 50% opacity) and "Green" (a green fill at full opacity), made from one new
/// rectangle that is linked to neither.
fn blue_and_green_styles(s: &mut Session) -> (vectorcraft_doc::GraphicStyle, vectorcraft_doc::GraphicStyle) {
let (rect, _) = blue_style(s, "Blue", false);
s.execute("appearance.setItem", &json!({"ids": [rect.0], "index": top_row(s, rect, true), "color": "#00ff00", "opacity": 100})).unwrap();
s.execute("graphicStyle.new", &json!({"id": rect.0, "name": "Green"})).unwrap();
let d = &s.doc().unwrap().doc;
(d.graphic_style("Blue").unwrap().clone(), d.graphic_style("Green").unwrap().clone())
}
/// Links `group` to `outer` with its look and `member` to `inner` with its look, as a file can hold them.
fn link_group_and_member(
s: &mut Session,
group: NodeId,
outer: &vectorcraft_doc::GraphicStyle,
member: NodeId,
inner: &vectorcraft_doc::GraphicStyle,
) {
s.edit("Link", |d, _| {
let g = d.node_mut(group).unwrap();
g.appearance = outer.appearance.clone().into();
g.extras_mut().graphic_style = Some(outer.id);
let m = d.node_mut(member).unwrap();
m.appearance = inner.appearance.clone().into();
m.extras_mut().graphic_style = Some(inner.id);
Ok(())
})
.unwrap();
}
/// Asserts that `d` holds what `was` holds for a redefinition of style "Blue": its definition, the link of `group`, the
/// look and link of each of `members`, and everything graph `id` stores (series paints and label rows included).
fn assert_same_redefine_state(
d: &vectorcraft_doc::Document,
was: &vectorcraft_doc::Document,
id: NodeId,
group: NodeId,
members: &[NodeId],
when: &str,
) {
assert_eq!(d.graphic_style("Blue"), was.graphic_style("Blue"), "{when}: the definition of Blue");
assert_eq!(d.node(group).unwrap().extras().graphic_style, was.node(group).unwrap().extras().graphic_style, "{when}: the group's link");
for m in members {
let (a, b) = (d.node(*m).unwrap(), was.node(*m).unwrap());
assert_eq!((&a.appearance, a.extras().graphic_style), (&b.appearance, b.extras().graphic_style), "{when}: member {m:?}");
}
assert_eq!(d.node(id).unwrap().extras().graph, was.node(id).unwrap().extras().graph, "{when}: what the graph stores");
}
/// Redefine Graphic Style with another style's look (`from`) on a linked series group leaves a path of the group that is
/// linked to that other style linked to it, and restyles and links the group's other paths; one undo takes the
/// redefinition back and redo makes it again.
#[test]
fn redefining_a_graphic_style_from_another_style_keeps_a_mark_linked_to_it() {
let (mut s, id, group, marks, blue, green) = linked_group_with_a_green_mark();
let own = s.doc().unwrap().doc.node(marks[0]).unwrap().appearance.clone();
let look = s.doc().unwrap().doc.graphic_style("Green").unwrap().appearance.fill_paint();
let was = s.doc().unwrap().doc.clone();
s.execute("graphicStyle.redefine", &json!({"name": "Blue", "from": "Green"})).unwrap();
let after = s.doc().unwrap().doc.clone();
let first = after.node(marks[0]).unwrap();
assert_eq!((&first.appearance, first.extras().graphic_style), (&own, Some(green)), "the mark keeps its own style");
assert!(marks[1..].iter().all(|m| after.node(*m).unwrap().appearance.fill_paint() == look));
assert!(marks[1..].iter().all(|m| after.node(*m).unwrap().extras().graphic_style == Some(blue)));
assert_eq!(after.node(group).unwrap().extras().graphic_style, None);
assert_eq!(spec(&s, id).series_paints[0].fill, Some(look), "the graph stores the new look");
s.execute("edit.undo", &json!({})).unwrap();
assert_same_redefine_state(&s.doc().unwrap().doc, &was, id, group, &marks, "after one undo");
s.execute("edit.redo", &json!({})).unwrap();
assert_same_redefine_state(&s.doc().unwrap().doc, &after, id, group, &marks, "after redo");
}
/// Redefine Graphic Style from an object on a linked series group leaves a path of the group that is linked to another
/// style as it is, restyles and links the group's other paths; one undo takes the redefinition back and redo makes it
/// again.
#[test]
fn redefining_a_graphic_style_from_an_object_keeps_a_mark_linked_to_another_style() {
let (mut s, id, group, marks, blue, green) = linked_group_with_a_green_mark();
let own = s.doc().unwrap().doc.node(marks[0]).unwrap().appearance.clone();
let red = NodeId(s.execute("shape.rectangle", &json!({"x": 700, "y": 700, "width": 10, "height": 10})).unwrap()["id"].as_u64().unwrap());
s.execute("appearance.setItem", &json!({"ids": [red.0], "index": top_row(&s, red, true), "color": "#ff0000", "opacity": 100})).unwrap();
let look = s.doc().unwrap().doc.node(red).unwrap().appearance.fill_paint();
let was = s.doc().unwrap().doc.clone();
s.execute("graphicStyle.redefine", &json!({"name": "Blue", "id": red.0})).unwrap();
let after = s.doc().unwrap().doc.clone();
let first = after.node(marks[0]).unwrap();
assert_eq!((&first.appearance, first.extras().graphic_style), (&own, Some(green)), "the mark keeps its own style");
assert!(marks[1..].iter().all(|m| after.node(*m).unwrap().appearance.fill_paint() == look));
assert!(marks[1..].iter().all(|m| after.node(*m).unwrap().extras().graphic_style == Some(blue)));
assert_eq!(after.node(group).unwrap().extras().graphic_style, None);
assert_eq!(spec(&s, id).series_paints[0].fill, Some(look), "the graph stores the new look");
s.execute("edit.undo", &json!({})).unwrap();
assert_same_redefine_state(&s.doc().unwrap().doc, &was, id, group, &marks, "after one undo");
s.execute("edit.redo", &json!({})).unwrap();
assert_same_redefine_state(&s.doc().unwrap().doc, &after, id, group, &marks, "after redo");
}
/// Redefine Graphic Style on a graph's Legend group linked to the style leaves a label of the group that is linked to
/// another style with its look and its link, restyles and links the group's other label, and clears and unlinks the
/// group; one undo takes the redefinition back and redo makes it again.
#[test]
fn redefining_a_graphic_style_keeps_a_legend_label_linked_to_another_style() {
let mut s = Session::new();
s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap();
let id = graph(&mut s, "column");
let legend = group(s.doc().unwrap().doc.node(id).unwrap(), "Legend").id;
let labels = [text_id(&s, id, "Legend", "2024"), text_id(&s, id, "Legend", "2025")];
let (blue, green) = blue_and_green_styles(&mut s);
link_group_and_member(&mut s, legend, &blue, labels[0], &green);
let own = s.doc().unwrap().doc.node(labels[0]).unwrap().appearance.clone();
let red = NodeId(s.execute("shape.rectangle", &json!({"x": 700, "y": 700, "width": 10, "height": 10})).unwrap()["id"].as_u64().unwrap());
s.execute("appearance.setItem", &json!({"ids": [red.0], "index": top_row(&s, red, true), "color": "#ff0000", "opacity": 100})).unwrap();
let look = s.doc().unwrap().doc.node(red).unwrap().appearance.fill_paint();
let was = s.doc().unwrap().doc.clone();
s.execute("graphicStyle.redefine", &json!({"name": "Blue", "id": red.0})).unwrap();
let after = s.doc().unwrap().doc.clone();
let kept = after.node(labels[0]).unwrap();
assert_eq!((&kept.appearance, kept.extras().graphic_style), (&own, Some(green.id)), "the label keeps its own style");
let other = after.node(labels[1]).unwrap();
assert_eq!((other.appearance.fill_paint(), other.extras().graphic_style), (look, Some(blue.id)), "the other label follows");
let g = after.node(legend).unwrap();
assert_eq!((g.appearance.items.is_empty(), g.extras().graphic_style), (true, None), "the group is cleared and unlinked");
s.execute("edit.undo", &json!({})).unwrap();
assert_same_redefine_state(&s.doc().unwrap().doc, &was, id, legend, &labels, "after one undo");
s.execute("edit.redo", &json!({})).unwrap();
assert_same_redefine_state(&s.doc().unwrap().doc, &after, id, legend, &labels, "after redo");
}
/// Series `index`'s group: its object opacity and blend mode, and those of each path directly inside it.
fn group_transparency(s: &Session, id: NodeId, index: u32) -> ((f32, BlendMode), Vec<(f32, BlendMode)>) {
let n = s.doc().unwrap().doc.node(id).unwrap().clone();
+6 -3
View File
@@ -76,7 +76,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Redefine Graphic Style",
["Window", "Appearance"],
None,
"{name?, id?} | {name, from} replace the style (default: the one the object was last linked to) with the look of object `id` or the first selected object (a graph series group with no fill, stroke, effect, opacity, blend mode, isolation, knockout or style link of its own: the topmost path directly in it; a graph's Axes or Legend group: its topmost line or label); the objects still linked to it update, and that object becomes linked. With `from`, the style takes the look of the style named `from` (its fills, strokes, effects, opacity, blend mode, isolate and knockout) and keeps its own name and place; `from` and the objects linked to it stay as they are, `from` naming the style itself or a style with the same look changes nothing, and `from` with `id` is an error. The art of a graph design in a series keeps its look and is unlinked, as the source or as a linked object. A linked graph series group passes the style to the paths directly in it, a linked Axes group to its lines and labels and a linked Legend group to its labels, other than the source and paths linked to the style whose look was edited, and is left cleared (as appearance.clear) and unlinked. On a linked path directly in a graph series, the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke and the object's opacity and blend mode (exceptions: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring (a graph's Axes group stands for the lines and labels directly in it, its Legend group for the labels), the graph stores that object's topmost visible fill and stroke rows and object opacity and blend mode for every label or line of its kind → {name}",
"{name?, id?} | {name, from} replace the style (default: the one the object was last linked to) with the look of object `id` or the first selected object (a graph series group with no fill, stroke, effect, opacity, blend mode, isolation, knockout or style link of its own: the topmost path directly in it; a graph's Axes or Legend group: its topmost line or label); the objects still linked to it update, and that object becomes linked. With `from`, the style takes the look of the style named `from` (its fills, strokes, effects, opacity, blend mode, isolate and knockout) and keeps its own name and place; `from` and the objects linked to it stay as they are, `from` naming the style itself or a style with the same look changes nothing, and `from` with `id` is an error. The art of a graph design in a series keeps its look and is unlinked, as the source or as a linked object. A linked graph series group passes the style to the paths directly in it, a linked Axes group to its lines and labels and a linked Legend group to its labels, other than the source, paths linked to the style whose look was edited and members linked to another style, and is left cleared (as appearance.clear) and unlinked. On a linked path directly in a graph series, the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke and the object's opacity and blend mode (exceptions: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring (a graph's Axes group stands for the lines and labels directly in it, its Legend group for the labels), the graph stores that object's topmost visible fill and stroke rows and object opacity and blend mode for every label or line of its kind → {name}",
has_doc,
style_redefine
),
@@ -554,10 +554,13 @@ fn style_redefine(s: &mut Session, p: &Value) -> Result<Value> {
linked.into_iter().partition(|nid| !super::graph::is_design_art(d, *nid) && d.node(*nid).is_some_and(|n| in_sync(n, &old)));
set_link(d, &edited, None);
// A linked graph series group passes the style to the paths directly inside it, so the graph stores it, and
// goes back to the empty appearance the graph draws it with. The source and the edited paths keep their look.
// goes back to the empty appearance the graph draws it with; a linked Axes or Legend group does the same with its
// lines and labels. The source and the edited paths keep their look, and a member linked to another style keeps
// its look and its link.
let mut follow_marks = super::graph::series_group_marks(d, &follow);
let edited: HashSet<NodeId> = edited.into_iter().collect();
follow_marks.retain(|nid| Some(*nid) != src && !edited.contains(nid));
let takes_style = |nid: NodeId| d.node(nid).is_some_and(|n| n.extras().graphic_style.is_none_or(|g| g == id));
follow_marks.retain(|nid| Some(*nid) != src && !edited.contains(nid) && takes_style(*nid));
super::appearance::clear_stood_for(d, &super::appearance::stood_for(&follow, &follow_marks));
let g = d.graphic_styles[i].clone();
let mut shared = None;
+2 -1
View File
@@ -957,7 +957,8 @@ link, and `graphicStyle.apply` with `add` unlinks the group. With `appearance.tr
target group's paths keeps its look on a move, and a `source` that is the group's only path is an error.
`graphicStyle.redefine` gives the style to the paths directly in a series group linked to it, whether or not the group
has rows of its own, links them, and clears and unlinks the group; the source and the paths linked to the style whose
look was edited keep their look. Read as a source, by `graphicStyle.new`, `graphicStyle.redefine` or
look was edited keep their look, and a path in the group linked to another style keeps its look and its link. Read as a
source, by `graphicStyle.new`, `graphicStyle.redefine` or
`appearance.transfer`, a series group that has no fill, stroke, effect, opacity, blend mode, isolation, knockout or
style link of its own gives the look and the style link of the topmost path directly in it, and a move with
`appearance.transfer` clears each of those paths; a series group that has one of them is read itself.
+1 -1
View File
@@ -2128,7 +2128,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
A graphic style dragged onto the Graphic Styles panel's New Graphic Style button is duplicated, as the panel menu's Duplicate Graphic Style does, and both put the copy at the end of the list, as the help page describes ([the help page](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=391)). VectorCraft's own rules: the button takes the drop with no art selected; a dragged style that is highlighted brings the other highlighted styles, copied in panel order in one undo step, and the copies are highlighted; the copy is named `<name> copy`, with a number when that is taken, and no art is linked to it (`a_style_dropped_on_new_graphic_style_is_duplicated_at_the_end` in `crates/ui-egui/src/panels/graphic_styles.rs`, `tests::styles::duplicate_puts_the_copy_at_the_end_of_the_list_in_one_undo_step`).
A graphic style dragged onto the Graphic Styles panel's Delete Graphic Style button is deleted, which the help page gives as another way to delete a style besides the panel menu's Delete Graphic Style; art that used the style keeps its look and is no longer linked to it ([the help page](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=392)). VectorCraft's own rules: the drop asks first as the button does, and with Alt held it deletes without asking; the button takes the drop with no style highlighted; a dragged style that is highlighted brings the other highlighted styles, deleted in one undo step (`a_style_dropped_on_delete_graphic_style_is_deleted_as_the_button_deletes` in `crates/ui-egui/src/panels/graphic_styles.rs`).
The Appearance panel's thumbnail dropped on a graphic style with Alt held replaces that style with the look of the object the panel shows; the style keeps its name and the art that uses it takes the new look, as the help page describes ([the help page](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=568)). VectorCraft's own rules: art dragged off the canvas does the same with its first object; the style keeps its place in the list, is outlined while one is held over it with Alt, and the replacement is one undo step; an object already linked to the style with its look changes nothing; without Alt the drop makes a new style (`art_or_an_appearance_dropped_on_a_style_with_alt_replaces_that_style` in `crates/ui-egui/src/panels/graphic_styles.rs`).
A graphic style dragged onto another style in the Graphic Styles panel with Alt held gives that style the dragged style's look; the replaced style keeps its name and the art that uses it takes the new look, as the help page describes ([the help page](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=568)). VectorCraft's own rules: the dragged style and the art linked to it stay as they are; the replaced style keeps its place in the list and is outlined while a style is held over it with Alt; the replacement is one undo step; a style dropped on itself, or on a style with the same look, changes nothing and records no undo step; without Alt the style moves (`graphicStyle.redefine {name, from}`, `a_style_dropped_on_another_with_alt_replaces_that_style` in `crates/ui-egui/src/panels/graphic_styles.rs`, `tests::styles::redefine_from_a_style_gives_the_style_that_look`).
A graphic style dragged onto another style in the Graphic Styles panel with Alt held gives that style the dragged style's look; the replaced style keeps its name and the art that uses it takes the new look, as the help page describes ([the help page](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=568)). VectorCraft's own rules: the dragged style and the art linked to it stay as they are, including a path linked to the dragged style inside a graph series group that uses the replaced style; the replaced style keeps its place in the list and is outlined while a style is held over it with Alt; the replacement is one undo step; a style dropped on itself, or on a style with the same look, changes nothing and records no undo step; without Alt the style moves (`graphicStyle.redefine {name, from}`, `a_style_dropped_on_another_with_alt_replaces_that_style` in `crates/ui-egui/src/panels/graphic_styles.rs`, `tests::styles::redefine_from_a_style_gives_the_style_that_look`, `cmd::graph::tests::redefining_a_graphic_style_from_another_style_keeps_a_mark_linked_to_it`). As VectorCraft's own rule, Redefine Graphic Style from an object also leaves a path inside such a series group, or a line or label inside a graph's Axes or Legend group that uses the style, with its look and its link when it is linked to another style (`redefining_a_graphic_style_from_an_object_keeps_a_mark_linked_to_another_style`, `redefining_a_graphic_style_keeps_a_legend_label_linked_to_another_style`).
In the Graphic Styles panel's thumbnail and list views, a style with no fill and no stroke, one with only effects or transparency included, shows its preview shape with a black outline, a white fill and a red slash, as the help page describes for the panel's thumbnails ([Graphic styles](https://helpx.adobe.com/illustrator/using/graphic-styles.html)); its effects still draw on that shape. The Control bar's Style picker and chip, graphic style library panels and the large preview on the selected object show the same marker. A fill or stroke row that paints None does not count as a fill or stroke, and a hidden row or one with zero opacity does; these rules, the marker outside the panel's thumbnails and the slash's direction and size are VectorCraft's own (`a_style_with_no_fill_and_no_stroke_shows_an_outlined_shape_and_a_red_slash` in `crates/ui-egui/src/panels/graphic_styles.rs`).
In the Graphic Styles panel's thumbnail and list views, right-clicking a style item opens its context menu offering Graphic Style Options…, Duplicate Graphic Style (or Duplicate Graphic Styles when multiple styles are selected), Delete Graphic Style (or Delete Graphic Styles), Redefine Graphic Style (enabled when canvas art is selected), and Break Link to Graphic Style (enabled when the selection is linked to this style). Right-clicking an unselected style selects it first, while right-clicking an item in an existing multi-selection preserves the multi-selection. Default Graphic Style disables Options and Delete. Secondary button hold still triggers large preview on tiles/rows. Tests: `right_click_context_menu_in_graphic_styles_panel`, `right_click_context_menu_default_style_disables_options_and_delete`, and `right_click_context_menu_preserves_multiselection_and_works_in_list_view` in `crates/ui-egui/src/panels/graphic_styles.rs`.
Applying a style to several objects, and Redefine Graphic Style, give the objects one shared copy of the style's appearance instead of a copy each; an object that is edited later gets its own copy, and an object whose placed gradients are fitted to its own bounds gets its own. The undo history's memory estimate counts a shared appearance once. Saved files are unchanged (`crates/engine/src/tests/styles.rs`).