mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-19 00:27:49 +00:00
M5: a drag from a child of a selected frame moves the frame (#2360)
A press on a layer inside a selected one now drags the selection, and a click without a drag selects that layer (also in Dev Mode and for a single selection), as in Figma. Cmd/Ctrl, Shift and layers outside the selection are unchanged. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Model-Effort: Opus 5.5 drove; Opus 5.5 briefed; Sonnet 5.5 wrote at medium
This commit is contained in:
1 parent
ebb22e9539
commit
4806b95e8e
5 files changed
+89
-9
No files matched your search
@@ -444,8 +444,8 @@ pub(crate) enum Gesture {
|
||||
/// A Shift-press on this selected layer: it leaves the selection on release, unless the
|
||||
/// press became a drag.
|
||||
deselect: Option<NodeId>,
|
||||
/// A press on one layer of a multi-selection that keeps the selection to drag it all: a
|
||||
/// release without a drag selects just this layer.
|
||||
/// A press on one layer of a multi-selection, or on a layer inside a selected one, that
|
||||
/// keeps the selection to drag it all: a release without a drag selects just this layer.
|
||||
keep: Option<NodeId>,
|
||||
},
|
||||
Resize {
|
||||
|
||||
@@ -92,8 +92,14 @@ impl Session {
|
||||
// inside, the frame or canvas behind it, or a layer stacked below the selected layer the
|
||||
// press is in) drags the selection. In a gap between selected layers, what's there is hit.
|
||||
let in_own_box = |s: NodeId| selection_box(&doc, &[s]).is_some_and(|q| in_quad(&q, ev.p()));
|
||||
// A press on a layer inside a selected one (a child of a selected frame) drags the
|
||||
// selection too, and a click selects that layer; Cmd/Ctrl keeps the deep pick.
|
||||
let in_selected = |t: NodeId| sel.iter().any(|s| *s != t && doc.is_ancestor(*s, t));
|
||||
let behind_sel = |t: Option<NodeId>| {
|
||||
t.is_none_or(|t| sel.iter().any(|s| *s != t && (doc.is_ancestor(t, *s) || (in_own_box(*s) && paints_below(&doc, t, *s)))))
|
||||
t.is_none_or(|t| {
|
||||
(!ev.cmd && in_selected(t))
|
||||
|| sel.iter().any(|s| *s != t && (doc.is_ancestor(t, *s) || (in_own_box(*s) && paints_below(&doc, t, *s))))
|
||||
})
|
||||
};
|
||||
// What the press hit (a label or a painted layer): a click that doesn't become a drag
|
||||
// selects just it. A press that reaches nothing above the selection uses the selection as
|
||||
@@ -116,8 +122,12 @@ impl Session {
|
||||
let without_target = || sel.iter().copied().filter(|x| *x != target).collect::<Vec<_>>();
|
||||
// A release without a drag narrows the selection to the layer the press hit. A
|
||||
// selected frame's name label sits outside the selection bounds, so it counts too.
|
||||
let keep = clicked
|
||||
.filter(|c| (label.is_some() || in_sel_box) && !ev.cmd && (sel.contains(c) || sel.iter().any(|s| doc.is_ancestor(*s, *c))));
|
||||
// A layer inside a selected one counts as well: the press drags the selection, and
|
||||
// a click selects that layer.
|
||||
let keep = clicked.filter(|c| {
|
||||
!ev.cmd
|
||||
&& (((label.is_some() || in_sel_box) && (sel.contains(c) || sel.iter().any(|s| doc.is_ancestor(*s, *c)))) || in_selected(*c))
|
||||
});
|
||||
let new_sel = if keep.is_some() {
|
||||
sel.clone()
|
||||
} else if ev.shift && deselect.is_none() {
|
||||
@@ -135,7 +145,7 @@ impl Session {
|
||||
if !edits {
|
||||
if deselect.is_some() {
|
||||
self.set_selection(without_target());
|
||||
} else if let Some(k) = keep.filter(|_| sel.len() > 1) {
|
||||
} else if let Some(k) = keep.filter(|k| sel.as_slice() != [*k]) {
|
||||
self.set_selection(vec![k]);
|
||||
}
|
||||
return Ok(());
|
||||
|
||||
@@ -176,10 +176,11 @@ impl Session {
|
||||
let sel = self.selection().into_iter().filter(|x| *x != d).collect();
|
||||
self.set_selection(sel);
|
||||
} else if let Some(k) = keep {
|
||||
// A click (not a drag) on one layer of a multi-selection selects just it.
|
||||
// A click (not a drag) on one layer of a multi-selection, or on a layer
|
||||
// inside a selected one, selects just it.
|
||||
let doc = self.doc()?.clone();
|
||||
let sel = self.selection();
|
||||
if sel.len() > 1 && (sel.contains(&k) || sel.iter().any(|s| doc.is_ancestor(*s, k))) {
|
||||
if sel.as_slice() != [k] && (sel.contains(&k) || sel.iter().any(|s| doc.is_ancestor(*s, k))) {
|
||||
self.set_selection(vec![k]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -562,3 +562,71 @@ fn shift_click_takes_a_layer_out_where_nothing_can_move() {
|
||||
s.pointer(&ev(PointerKind::Up, 520.0, 20.0, SHIFT)).unwrap();
|
||||
assert_eq!(s.selection(), vec![k.empty], "Shift-click still takes the layer out");
|
||||
}
|
||||
|
||||
/// A top-level 300 x 300 frame with a filled 100 x 100 rectangle at (50, 50) and a nested frame
|
||||
/// at (200, 200 80x80) holding a rectangle at (210, 210 40x40).
|
||||
fn frame_with_child(s: &mut Session) -> (NodeId, NodeId, NodeId, NodeId) {
|
||||
let f = id(&ex(s, "frame.create", json!({"x": 0, "y": 0, "width": 300, "height": 300})));
|
||||
let c = id(&ex(s, "shape.rectangle", json!({"x": 50, "y": 50, "width": 100, "height": 100, "parent": f})));
|
||||
let n = id(&ex(s, "frame.create", json!({"x": 180, "y": 180, "width": 100, "height": 100, "parent": f})));
|
||||
let gc = id(&ex(s, "shape.rectangle", json!({"x": 200, "y": 200, "width": 40, "height": 40, "parent": n})));
|
||||
(f, c, n, gc)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_drag_from_a_child_of_a_selected_frame_moves_the_frame() {
|
||||
let mut s = Session::new();
|
||||
let (f, c, _n, gc) = frame_with_child(&mut s);
|
||||
let sib = id(&ex(&mut s, "shape.rectangle", json!({"x": 90, "y": 90, "width": 30, "height": 30})));
|
||||
let at = |s: &Session, i: NodeId| s.doc().unwrap().world_bounds(i).unwrap().origin();
|
||||
let local = |s: &Session, i: NodeId| {
|
||||
let d = s.doc().unwrap();
|
||||
let n = d.node(i).unwrap();
|
||||
let c = n.transform.as_coeffs();
|
||||
(c[4], c[5])
|
||||
};
|
||||
let c_local = local(&s, c);
|
||||
// (selection before, press point, modifiers, selection after, the layers that move by (10, 10), derivation)
|
||||
let rows: Vec<(Vec<NodeId>, (f64, f64), Mods, Vec<NodeId>, Vec<NodeId>, &str)> = vec![
|
||||
(vec![f], (60.0, 60.0), NONE, vec![f], vec![f, c, gc], "a drag from a child of the selected frame moves the frame"),
|
||||
(vec![f], (220.0, 220.0), NONE, vec![f], vec![f, c, gc], "a drag from a grandchild moves the top-level frame"),
|
||||
(vec![], (60.0, 60.0), NONE, vec![c], vec![c], "with nothing selected the child is picked and moved"),
|
||||
(vec![f], (60.0, 60.0), CMD, vec![c], vec![c], "Cmd picks the deepest layer and moves it"),
|
||||
(vec![f], (100.0, 100.0), NONE, vec![sib], vec![sib], "a sibling painted above the frame takes the press"),
|
||||
];
|
||||
for (before, from, m, after, moved, why) in rows {
|
||||
let all = [f, c, gc, sib];
|
||||
let home: Vec<Point> = all.iter().map(|i| at(&s, *i)).collect();
|
||||
ex(&mut s, "select.set", json!({"ids": before}));
|
||||
drag(&mut s, from, (from.0 + 10.0, from.1 + 10.0), m);
|
||||
assert_eq!(sorted(s.selection()), sorted(after), "{why}");
|
||||
for (i, h) in all.iter().zip(&home) {
|
||||
// The frame carries its children: they move in the world, not in their local space.
|
||||
let d = if moved.contains(i) { 10.0 } else { 0.0 };
|
||||
assert_eq!(at(&s, *i), Point::new(h.x + d, h.y + d), "{why}");
|
||||
}
|
||||
assert_eq!(local(&s, c), if moved == [c] { (c_local.0 + 10.0, c_local.1 + 10.0) } else { c_local }, "{why}: the child's local position");
|
||||
assert!(s.undo().unwrap(), "{why}: one undo step");
|
||||
for (i, h) in all.iter().zip(&home) {
|
||||
assert_eq!(at(&s, *i), *h, "{why}: undo restores");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_click_on_a_child_of_a_selected_frame_selects_the_child() {
|
||||
let mut s = Session::new();
|
||||
let (f, c, n, gc) = frame_with_child(&mut s);
|
||||
let home = s.doc().unwrap().world_bounds(c).unwrap().origin();
|
||||
for (p, want) in [((60.0, 60.0), c), ((190.0, 190.0), n)] {
|
||||
ex(&mut s, "select.set", json!({"ids": [f]}));
|
||||
click(&mut s, p.0, p.1, NONE);
|
||||
assert_eq!(s.selection(), vec![want], "a click selects the layer inside the selected frame");
|
||||
}
|
||||
assert_eq!(s.doc().unwrap().world_bounds(c).unwrap().origin(), home, "nothing moved");
|
||||
let _ = gc;
|
||||
s.tool.dev_mode = true;
|
||||
ex(&mut s, "select.set", json!({"ids": [f]}));
|
||||
click(&mut s, 60.0, 60.0, NONE);
|
||||
assert_eq!(s.selection(), vec![c], "in Dev Mode too");
|
||||
}
|
||||
+2
-1
@@ -57,7 +57,7 @@ interaction feel only partly compared: the interactions measured so far, case by
|
||||
|
||||
| Item | Status | Notes |
|
||||
|---|---|---|
|
||||
| Click, Shift-click, marquee, Shift-marquee toggle | done | Shift-drag on a selected layer moves the selection, kept to the dominant axis with no 45° snap (#498; `shift_drag_moves_the_selection`; measured in Figma's web app, 2026-11-08); a marquee selects the top-level layers it touches, by the box and a rotated shape by its outline (rectangle and ellipse measured, the other shapes by the same code); a partly covered top-level frame or section gives the layers in it the marquee touches, an enclosed one is selected itself, an empty frame on touch; a drag from a frame's background selects that frame only when the marquee also takes another top-level frame (then whole), and also takes what it touches outside it; selecting a frame whole keeps the marquee at the top level (a partly covered frame then comes whole too); locked and hidden layers are skipped (`marquee_behaviour_tests`, `selection_behaviour_tests`; measured in Figma's web app, 2026-11-11; Shift and Cmd/Ctrl marquees not measured) (a locked layer selected from the panel ignores the arrow keys and the nudge commands; its properties still edit; measured in Figma's web app, 2026-11-10) |
|
||||
| Click, Shift-click, marquee, Shift-marquee toggle | done | Shift-drag on a selected layer moves the selection, kept to the dominant axis with no 45° snap (#498; `shift_drag_moves_the_selection`; measured in Figma's web app, 2026-11-08); with a frame selected, a drag that starts on one of its children moves the frame and a click selects the child, as in Figma (#2360; `a_drag_from_a_child_of_a_selected_frame_moves_the_frame`, `a_click_on_a_child_of_a_selected_frame_selects_the_child`); a marquee selects the top-level layers it touches, by the box and a rotated shape by its outline (rectangle and ellipse measured, the other shapes by the same code); a partly covered top-level frame or section gives the layers in it the marquee touches, an enclosed one is selected itself, an empty frame on touch; a drag from a frame's background selects that frame only when the marquee also takes another top-level frame (then whole), and also takes what it touches outside it; selecting a frame whole keeps the marquee at the top level (a partly covered frame then comes whole too); locked and hidden layers are skipped (`marquee_behaviour_tests`, `selection_behaviour_tests`; measured in Figma's web app, 2026-11-11; Shift and Cmd/Ctrl marquees not measured) (a locked layer selected from the panel ignores the arrow keys and the nudge commands; its properties still edit; measured in Figma's web app, 2026-11-10) |
|
||||
| Deep select (Cmd/Ctrl-click, Cmd/Ctrl-marquee) | done | |
|
||||
| Select layer menu (every layer under the click) | done | shown only with more than one layer under the pointer; locked layers are listed with a padlock in the leading column and are selectable there, as Lock and unlock layers' note says (measured in Figma's web app, 2026-11-10; the "more than one layer" gate was measured on a single locked layer only) (`select_layer_marks_locked_layers_with_a_padlock_and_picks_them`, `select_layer_needs_more_than_one_layer_under_the_pointer`) |
|
||||
| Escape with layers selected | done | clears the selection at once, whatever the nesting; it never selects the parent. Measured in the Figma web app (2026-11-08) with a rectangle in a group in a frame, selected from the canvas (a double-click into the group), from the Layers panel, and after Tab moved the selection to its sibling: one Escape selects nothing, a second leaves nothing selected. Escape still leaves text and vector editing, ends gestures and the pen first, and ends the focus view once nothing or the focused frame is selected (`selection_behaviour_tests`, `devfocus_tests`) |
|
||||
@@ -210,6 +210,7 @@ This audit records candidates for subsequent fixes; their behaviour is unchanged
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-11-19 | patch | M5, #2360: with a frame selected, a drag that starts on one of its children moves the frame and a click selects the child (a press on a layer inside a selected one drags the selection), as in Figma; Cmd/Ctrl, Shift and layers outside the frame are unchanged. |
|
||||
| 2026-11-18 | patch | M5, #2372: the arrow keys move a layer along the canvas axes inside a rotated parent (the step was applied along the parent's axes, so Down moved a child of a frame rotated 90 degrees sideways); auto layout children are unchanged |
|
||||
| 2026-11-18 | patch | M1, #2355: Cmd/Ctrl+V with one layer inside a frame selected pasted the copy onto the page on top of the frame; it now goes into the layer's parent just above it (in an auto layout frame, the item after it, so the layout grows), keeping today's behaviour for a page-level layer, several layers, an instance's children and a board atom. Tests: `paste_sibling_tests` (5) |
|
||||
| 2026-11-08 | minor | M8, #2109: in vector edit mode the Align commands (`align.left` to `align.bottom`, Alt+A/H/D/W/V/S) and Distribute horizontal and vertical spacing act on the selected points when neither `ids` nor `id` is given (either one targets layers), as in Figma (measured in Figma on 2026-11-08): each point moves along one axis only, to its box's left, horizontal centre, right, top, vertical centre or bottom, and distribute spaces the points evenly between the outermost two in order along the axis; handles go with their vertex, a single point stays, with no point selected nothing moves (the layer is not aligned to its frame, as measured in Figma), and one undo restores them. The Design panel draws the alignment row first, with a Distribute menu from three points. Numbers unchanged. |
|
||||
|
||||
Reference in new issue
Block a user