mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-16 03:51:16 +00:00
Appearance: aligned edits with a graph design's art follow the art's stack
- appearance.moveItem with from "contents" and aligned: true is refused when the objects' stacks differ, as it is for rows. - paint.invert and paint.complement with an item remember the paint of an object they recolored, not that of design art they left out. - effect.remove and effect.duplicate with indices and aligned: true are an error, and change nothing, when the design art given first has no effect at one of the indices.
This commit is contained in:
@@ -1365,6 +1365,10 @@ fn move_item(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
if ids.is_empty() {
|
||||
return Err(bad(C, "select objects or give ids"));
|
||||
}
|
||||
// The Contents row's place counts the rows below it, which isn't one place in several different stacks either.
|
||||
if aligned && appearances_differ(&s.doc()?.doc, &with_reference(design_reference(s, p, C)?, &ids)) {
|
||||
return Err(bad(C, "rows of objects whose appearances differ can't be reordered together"));
|
||||
}
|
||||
return move_contents(s, &ids, to);
|
||||
}
|
||||
let ids = require_targets(s, p, C)?;
|
||||
|
||||
@@ -387,6 +387,20 @@ fn edit_effects_at(
|
||||
indices: &[usize],
|
||||
mut f: impl FnMut(&mut Vec<Effect>, &[usize]) -> bool,
|
||||
) -> Result<Vec<NodeId>> {
|
||||
// With a graph design's art given first, the indices are effects of its list: one it doesn't have names no effect,
|
||||
// and the edit is refused as a whole, as it is in a list that lacks one of them.
|
||||
if let Some(of) = reference_of(s, p, item, cmd)?
|
||||
&& let Some(n) = s.doc()?.doc.node(of)
|
||||
{
|
||||
let ap = &n.appearance;
|
||||
let len = match item.effects_item(ap, cmd)? {
|
||||
None => ap.effects.len(),
|
||||
Some(i) => ap.items.get(i).map_or(0, |it| it.effects().len()),
|
||||
};
|
||||
if indices.iter().any(|i| *i >= len) {
|
||||
return Err(EngineError::Other(none.into()));
|
||||
}
|
||||
}
|
||||
// Each target's list and the positions in it, in the order the targets first come up.
|
||||
let mut targets: Vec<(NodeId, Option<usize>, Vec<usize>)> = vec![];
|
||||
for &index in indices {
|
||||
@@ -1284,7 +1298,9 @@ fn expand_appearance(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let colorized_ok = super::paint::check_colorized(&s.doc()?.doc).is_ok();
|
||||
let ids = s.edit("Expand Appearance", |d, _| {
|
||||
let before = d.clone();
|
||||
// The art of graph designs in the graphs and series among the roots stays as the graph draws it.
|
||||
// The art of graph designs in the graphs and series among the roots stays as the graph draws it. A group whose
|
||||
// own effect turns it into other art as a whole (a blur, feather or inner glow makes it an image) takes its
|
||||
// art into that art, which draws it, so that art has no place to go back to.
|
||||
let designs = super::appearance::design_art_in(d, &roots);
|
||||
// A dimension selected with the art it measures keeps its own lines and label: it is out
|
||||
// of the document while the art expands.
|
||||
|
||||
@@ -869,6 +869,77 @@ fn aligned_rows_of_a_graph_designs_art_and_a_different_stack_are_not_moved() {
|
||||
assert_eq!(paints, [art_was.items[1].paint().clone(), art_was.items[0].paint().clone(), art_was.items[1].paint().clone()]);
|
||||
}
|
||||
|
||||
/// The Contents row of a graph design's copy and of a group whose stack differs is not moved with `aligned: true`, as
|
||||
/// the rows are not.
|
||||
#[test]
|
||||
fn aligned_contents_row_of_a_graph_designs_copy_and_a_different_stack_is_not_moved() {
|
||||
let rows = |s: &Session, id: NodeId| (*s.doc().unwrap().doc.node(id).unwrap().appearance).clone();
|
||||
let (mut s, _, copy, _, _) = design_art();
|
||||
s.execute("shape.rectangle", &json!({"x": 700, "y": 700, "width": 10, "height": 10})).unwrap();
|
||||
let g = NodeId(s.execute("object.group", &json!({})).unwrap()["id"].as_u64().unwrap());
|
||||
s.execute("appearance.addFill", &json!({"ids": [g.0]})).unwrap();
|
||||
s.execute("appearance.addFill", &json!({"ids": [g.0]})).unwrap();
|
||||
assert_ne!(rows(&s, copy), rows(&s, g));
|
||||
let (copy_was, g_was) = (rows(&s, copy), rows(&s, g));
|
||||
let steps = s.doc().unwrap().history.undo.len();
|
||||
let e = s.execute("appearance.moveItem", &json!({"ids": [copy.0, g.0], "from": "contents", "to": 1, "aligned": true})).unwrap_err();
|
||||
assert!(e.to_string().contains("appearances differ"), "{e}");
|
||||
assert_eq!((rows(&s, copy), rows(&s, g)), (copy_was, g_was));
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), steps);
|
||||
}
|
||||
|
||||
/// Invert with an `item` remembers the paint of an object it recolored, not that of a graph design's art given first,
|
||||
/// which it leaves out.
|
||||
#[test]
|
||||
fn invert_of_an_item_remembers_the_recolored_paint_not_the_design_arts() {
|
||||
let (mut s, _, art, mark) = aligned_design_art();
|
||||
s.execute("paint.invert", &json!({"ids": [art.0, mark.0], "item": 0, "stroke": false})).unwrap();
|
||||
let Paint::Solid { color, .. } = s.doc().unwrap().doc.node(mark).unwrap().appearance.items[0].paint().clone() else {
|
||||
panic!("the mark's fill stays a solid color");
|
||||
};
|
||||
assert_ne!(color, vectorcraft_color::Color::rgb(0.0, 0.0, 1.0), "the mark's blue fill is inverted");
|
||||
assert_eq!(s.last_solid, color, "the mark's inverted fill is remembered, not the art's red one");
|
||||
}
|
||||
|
||||
/// With a graph design's art given first and `aligned: true`, `effect.remove` and `effect.duplicate` with `indices` are an
|
||||
/// error and change nothing when one of the indices names no effect of the art.
|
||||
#[test]
|
||||
fn aligned_effect_indices_past_the_end_of_a_graph_designs_art_are_refused() {
|
||||
let rows = |s: &Session, id: NodeId| (*s.doc().unwrap().doc.node(id).unwrap().appearance).clone();
|
||||
let (mut s, _, art, mark) = aligned_design_art();
|
||||
s.execute("effect.apply", &json!({"effect": "stylize.dropShadow", "ids": [mark.0], "item": null})).unwrap();
|
||||
s.edit("Shadow", |d, _| {
|
||||
let shadow = d.node(mark).unwrap().appearance.effects[0].clone();
|
||||
d.node_mut(art).unwrap().appearance.effects.push(shadow);
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
let (art_was, mark_was) = (rows(&s, art), rows(&s, mark));
|
||||
let steps = s.doc().unwrap().history.undo.len();
|
||||
for cmd in ["effect.remove", "effect.duplicate"] {
|
||||
let e = s.execute(cmd, &json!({"ids": [art.0, mark.0], "item": null, "indices": [0, 9], "aligned": true})).unwrap_err();
|
||||
assert!(e.to_string().contains("no effects at indices 0, 9"), "{cmd}: {e}");
|
||||
assert_eq!((rows(&s, art), rows(&s, mark)), (art_was.clone(), mark_was.clone()), "{cmd}");
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), steps, "{cmd}");
|
||||
}
|
||||
// With index 0 alone, which the art has, the mark's equal effect is removed.
|
||||
s.execute("effect.remove", &json!({"ids": [art.0, mark.0], "item": null, "indices": [0], "aligned": true})).unwrap();
|
||||
assert!(rows(&s, mark).effects.is_empty());
|
||||
}
|
||||
|
||||
/// A blur on a series group makes the whole group an image, which draws the design's art with the series' other art:
|
||||
/// Expand Appearance does not put the art back beside the image.
|
||||
#[test]
|
||||
fn expanding_a_blurred_series_group_takes_a_graph_designs_art_into_the_image() {
|
||||
let (mut s, id, copy, _, _) = design_art();
|
||||
let series_group = series(s.doc().unwrap().doc.node(id).unwrap(), 0).id;
|
||||
s.execute("effect.apply", &json!({"effect": "blur.gaussian", "ids": [series_group.0]})).unwrap();
|
||||
s.execute("effect.expandAppearance", &json!({"ids": [series_group.0]})).unwrap();
|
||||
let d = &s.doc().unwrap().doc;
|
||||
assert!(matches!(d.node(series_group).unwrap().kind, NodeKind::Image(_)));
|
||||
assert!(d.node(copy).is_none());
|
||||
}
|
||||
|
||||
/// The paint commands leave the art of a graph design in a series out, a copy of the design given by id with an item
|
||||
/// included.
|
||||
#[test]
|
||||
|
||||
@@ -1070,7 +1070,7 @@ fn proxy_recolor(s: &mut Session, p: &Value, cmd: &str, label: &str, f: &dyn Fn(
|
||||
return Ok(json!({ "changed": changed as usize }));
|
||||
}
|
||||
let item = item_target(s, p, cmd)?.of_kind(s, !stroke);
|
||||
let (r, shown_item) = match item {
|
||||
let (r, shown_item, edited) = match item {
|
||||
ItemTarget::Item { index, .. } => {
|
||||
let ids = super::appearance::drop_design_art(&s.doc()?.doc, item.targets(s, p)?);
|
||||
let mut changed = 0;
|
||||
@@ -1080,15 +1080,19 @@ fn proxy_recolor(s: &mut Session, p: &Value, cmd: &str, label: &str, f: &dyn Fn(
|
||||
changed += paint.is_some_and(|paint| super::colorcmds::map_paint(paint, f)) as usize;
|
||||
Ok(())
|
||||
})?;
|
||||
(json!({ "changed": changed }), Some(index))
|
||||
(json!({ "changed": changed }), Some(index), Some(ids))
|
||||
}
|
||||
// The proxy recolors its paints, including a colorized image's fill, without changing image pixels or pattern tiles.
|
||||
ItemTarget::Top => {
|
||||
let q = json!({"fill": !stroke, "stroke": stroke, "includeImages": false, "includePatterns": false, "ids": ids.iter().map(|i| i.0).collect::<Vec<_>>()});
|
||||
(super::colorcmds::recolor(s, &q, cmd, label, f)?, None)
|
||||
(super::colorcmds::recolor(s, &q, cmd, label, f)?, None, None)
|
||||
}
|
||||
};
|
||||
let shown_ids = if shown_item.is_some() { ids } else { leaf_targets(s, &ids)? };
|
||||
// The paint remembered is one the edit recolored: a graph design's art that the item edit leaves out gives none.
|
||||
let shown_ids = match edited {
|
||||
Some(ids) => ids,
|
||||
None => leaf_targets(s, &ids)?,
|
||||
};
|
||||
if let Some(shown) = shown_ids.first().and_then(|id| s.doc().ok()?.doc.node(*id).map(|n| proxy_paint(n, stroke, shown_item))) {
|
||||
s.remember_paint(&shown);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user