mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-14 03:01:11 +00:00
M1: Paste over selection puts the copies just above the selected layer
Shift+Cmd/Ctrl+V pasted into the selected layer's parent at its top-left, but appended the copies, so they went to the top of the parent's layers whatever was selected. In an auto layout frame that put them at the end of the flow, away from the layer they were pasted over. They now go just above the selected layer, in the copied order: in the Layers panel the row above it, in an auto layout frame the item after it. A section pasted over a layer in a frame still goes on the page, on top of its layers, as before. Paste to replace already kept the replaced layer's place. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
7b34dbab00
commit
c74bcd0b0e
@@ -329,14 +329,22 @@ pub(super) fn paste_over(s: &mut Session, _p: &Value) -> Result<Value> {
|
||||
let sel = s.selection();
|
||||
let page = s.page()?;
|
||||
let doc = s.doc()?;
|
||||
let (parent, at) = match sel.first() {
|
||||
let (parent, at, above) = match sel.first() {
|
||||
Some(i) => {
|
||||
let parent = doc.node(*i).and_then(|n| n.parent).unwrap_or(page);
|
||||
(parent, doc.world_bounds(*i).map(|b| (b.x0, b.y0)))
|
||||
(parent, doc.world_bounds(*i).map(|b| (b.x0, b.y0)), doc.index_in_parent(*i).map(|ix| ix + 1))
|
||||
}
|
||||
None => (page, None),
|
||||
None => (page, None, None),
|
||||
};
|
||||
let ids = paste_into(s, parent, at)?;
|
||||
if let Some(above) = above {
|
||||
let doc = s.doc_mut()?;
|
||||
for (k, i) in
|
||||
ids.iter().filter(|i| doc.node(**i).is_some_and(|n| n.parent == Some(parent))).copied().collect::<Vec<_>>().into_iter().enumerate()
|
||||
{
|
||||
doc.reorder(i, above + k)?;
|
||||
}
|
||||
}
|
||||
s.set_selection(ids.clone());
|
||||
Ok(json!({"ids": ids}))
|
||||
}
|
||||
|
||||
@@ -345,6 +345,24 @@ fn copy_paste_and_duplicate() {
|
||||
assert_eq!(d["ids"].as_array().unwrap().len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paste_over_puts_the_copies_just_above_the_selected_layer() {
|
||||
let mut s = sess();
|
||||
let frame = id(&s.execute("frame.create", &json!({"x": 0, "y": 0, "width": 200, "height": 200})).unwrap());
|
||||
let layer =
|
||||
|s: &mut Session, x: f64| id(&s.execute("shape.rectangle", &json!({"x": x, "y": 10, "width": 10, "height": 10, "parent": frame})).unwrap());
|
||||
let (a, b, c) = (layer(&mut s, 10.0), layer(&mut s, 30.0), layer(&mut s, 50.0));
|
||||
let kids = |s: &Session| s.doc().unwrap().node(frame).unwrap().children.clone();
|
||||
assert_eq!(kids(&s), vec![a, b, c]);
|
||||
s.execute("edit.copy", &json!({"ids": [b, c]})).unwrap();
|
||||
s.set_selection(vec![a]);
|
||||
let pasted: Vec<NodeId> = s.execute("edit.pasteOver", &json!({})).unwrap()["ids"].as_array().unwrap().iter().filter_map(params::id_of).collect();
|
||||
assert_eq!(pasted.len(), 2);
|
||||
assert_eq!(kids(&s), vec![a, pasted[0], pasted[1], b, c], "in the selected layer's frame, just above it, in the copied order");
|
||||
assert_eq!(s.doc().unwrap().world_bounds(pasted[0]).unwrap().x0, 10.0, "at the selected layer's position");
|
||||
assert_eq!(s.selection(), pasted);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn boolean_and_flatten() {
|
||||
let mut s = sess();
|
||||
|
||||
+2
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user