mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 04:11:52 +01:00
train: #8245
This commit is contained in:
commit
6eb32b5541
9 files changed
+123
-11
No files matched your search
@@ -110,7 +110,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Move Rows",
|
||||
[],
|
||||
None,
|
||||
"{ids|id, target, place?: \"above\"|\"below\"|\"inside\" (default inside), copy?: bool} drag rows in the Layers panel: above or below the target row (beside it, in its layer or group), or inside a layer, group or Intertwine group (on top of its contents). Layers go only in layers or at the top level, objects in layers, groups and Intertwine groups; an object placed beside a top-level layer goes inside it. An object placed in an Intertwine group becomes a member drawn in its row's order, with no arranged areas, and one placed in a group that is a member becomes part of that member; one that is or holds an Intertwine group, a Repeat, a graph or a Live Paint group is refused. A member moved out of its Intertwine group drops its arranged areas, and a group left with one member is replaced by that member, or becomes a plain group of it when the group has an opacity, blending, appearance, mask, lock or hidden state of its own (with no member, it is removed). A row never goes into itself; a locked layer or group takes nothing. `copy` (Alt-drag) moves copies. Every selected object left hidden or locked, such as one moved into a hidden layer or group, is deselected (the key object too). One undo step → {ids}",
|
||||
"{ids|id, target, place?: \"above\"|\"below\"|\"inside\" (default inside), copy?: bool} drag rows in the Layers panel: above or below the target row (beside it, in its layer or group), or inside a layer, group or Intertwine group (on top of its contents). Layers go only in layers or at the top level, objects in layers, groups and Intertwine groups; an object placed beside a top-level layer goes inside it. An object placed in an Intertwine group becomes a member drawn in its row's order, with no arranged areas, and one placed in a group that is a member becomes part of that member; one that is or holds an Intertwine group, a Repeat, a graph or a Live Paint group is refused. A member moved out of its Intertwine group drops its arranged areas, and a group left with one member is replaced by that member, or becomes a plain group of it when the group has an opacity, blending, appearance, mask, lock or hidden state of its own (with no member, it is removed). A row never goes into itself; a locked layer or group takes nothing. `copy` (Alt-drag) moves copies, which may also go above or below a row they copy (the target among `ids`). Every selected object left hidden or locked, such as one moved into a hidden layer or group, is deselected (the key object too). One undo step → {ids}",
|
||||
has_doc,
|
||||
move_rows
|
||||
),
|
||||
@@ -774,9 +774,11 @@ fn move_rows(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
if ids.is_empty() {
|
||||
return Err(bad(C, "no such rows"));
|
||||
}
|
||||
// Never into itself or a row inside it.
|
||||
// Never into itself or a row inside it. A copy may go above or below one of the rows it
|
||||
// copies, which a move there would leave where it is (#8237).
|
||||
let beside_itself = copy && place != Place::Inside && ids.contains(&target);
|
||||
let around = d.ancestry(target).unwrap_or_default();
|
||||
if ids.iter().any(|i| around.contains(i)) {
|
||||
if ids.iter().any(|i| around.contains(i) && !(beside_itself && *i == target)) {
|
||||
return Err(bad(C, "a row can't go into itself"));
|
||||
}
|
||||
let nodes: Vec<&Node> = ids.iter().filter_map(|i| d.node(*i)).collect();
|
||||
@@ -788,6 +790,11 @@ fn move_rows(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
parent => (parent, Some(target)),
|
||||
},
|
||||
};
|
||||
// A copy beside a top-level layer it copies, with objects among the rows, would go inside
|
||||
// that layer: into itself.
|
||||
if parent.is_some_and(|p| ids.contains(&p)) {
|
||||
return Err(bad(C, "a row can't go into itself"));
|
||||
}
|
||||
if let Some(n) = nodes.iter().find(|n| !accepts(d, parent, n)) {
|
||||
let into = parent.and_then(|p| d.node(p)).map_or("the top level", |p| if p.is_layer() { "a layer" } else { p.kind_label() });
|
||||
return Err(bad(C, format!("{} can't go into {into}", n.display_name())));
|
||||
|
||||
@@ -643,6 +643,45 @@ fn alt_drag_copies_rows_and_the_selected_art_moves_between_layers() {
|
||||
assert_eq!(s.doc().unwrap().selection.objects, vec![a, g], "it stays selected");
|
||||
}
|
||||
|
||||
/// #8237: a copy may go above or below a row it copies, so a lone layer, the top layer dragged up
|
||||
/// and the bottom one dragged down can be copied. A move there, or a copy inside the row, is still
|
||||
/// refused.
|
||||
#[test]
|
||||
fn a_copy_goes_above_or_below_a_row_it_copies() {
|
||||
let mut s = session();
|
||||
let layers = |s: &Session| s.doc().unwrap().doc.layers.iter().map(|l| l.id).collect::<Vec<_>>();
|
||||
let [only] = layers(&s)[..] else { panic!("one layer") };
|
||||
for place in ["above", "below", "inside"] {
|
||||
assert!(s.execute("layer.move", &json!({"ids": [only.0], "target": only.0, "place": place})).is_err(), "a move {place} itself");
|
||||
}
|
||||
assert!(s.execute("layer.move", &json!({"ids": [only.0], "target": only.0, "place": "inside", "copy": true})).is_err());
|
||||
assert_eq!(layers(&s), vec![only], "nothing changed");
|
||||
let above = ids(&run(&mut s, "layer.move", json!({"ids": [only.0], "target": only.0, "place": "above", "copy": true})));
|
||||
assert_eq!(layers(&s), vec![only, above[0]], "the copy above the original");
|
||||
let below = ids(&run(&mut s, "layer.move", json!({"ids": [only.0], "target": only.0, "place": "below", "copy": true})));
|
||||
assert_eq!(layers(&s), vec![below[0], only, above[0]], "and one below it");
|
||||
run(&mut s, "edit.undo", json!({}));
|
||||
assert_eq!(layers(&s), vec![only, above[0]], "each copy is one undo step");
|
||||
}
|
||||
|
||||
/// #8237 review: rows that hold an object can't sit beside a top-level layer, so copied beside a
|
||||
/// top-level layer among them they would go inside it: a copy of that layer inside itself. Refused,
|
||||
/// and nothing changes.
|
||||
#[test]
|
||||
fn a_copy_with_objects_beside_a_copied_top_level_layer_is_refused() {
|
||||
let mut s = session();
|
||||
let bottom = s.doc().unwrap().doc.layers[0].id;
|
||||
let other = id(&run(&mut s, "layer.new", json!({})));
|
||||
let r = rect(&mut s, 0.0);
|
||||
assert_eq!(s.doc().unwrap().doc.parent_of(r), Some(other), "the rectangle is in the other layer");
|
||||
let count = s.doc().unwrap().doc.node_count();
|
||||
for place in ["above", "below"] {
|
||||
let p = json!({"ids": [bottom.0, r.0], "target": bottom.0, "place": place, "copy": true});
|
||||
assert!(s.execute("layer.move", &p).is_err(), "{place}: the layer's copy would go inside it");
|
||||
}
|
||||
assert_eq!(s.doc().unwrap().doc.node_count(), count, "nothing copied");
|
||||
}
|
||||
|
||||
/// The selected art in rows dragged into a hidden layer or group is deselected, the key object
|
||||
/// included. Undo puts the rows back and selects the art again.
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user