mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-20 00:58:19 +00:00
M8: a Shift-click range in the Layers panel keeps a frame, not its covered children, as in Figma (#2330)
The change from #2330 by @TrevorBrown-dev, as one commit.
This commit is contained in:
1 parent
94a3524a90
commit
b5d43a7de2
4 files changed
+113
-4
No files matched your search
@@ -951,6 +951,64 @@ fn search_fields_keep_their_text_in_the_middle() {
|
||||
assert!(off < 1.0, "Search assets is {off} points off the middle");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_shift_range_across_frames_keeps_a_frame_and_not_its_covered_children() {
|
||||
let mut s = Session::new();
|
||||
let frame1 = id(s.execute("frame.create", &json!({"x": 0, "y": 0, "width": 100, "height": 100, "name": "Frame 1"})).unwrap());
|
||||
let rect2 = rect(&mut s, "Rect 2", 0.0, Some(frame1));
|
||||
let rect3 = rect(&mut s, "Rect 3", 30.0, Some(frame1));
|
||||
let frame2 = id(s.execute("frame.create", &json!({"x": 200, "y": 0, "width": 100, "height": 100, "name": "Frame 2"})).unwrap());
|
||||
let rect4 = rect(&mut s, "Rect 4", 0.0, Some(frame2));
|
||||
s.execute("select.none", &json!({})).unwrap();
|
||||
let mut u = Ui::new(s);
|
||||
u.app.ui.expanded.extend([frame1, frame2]);
|
||||
u.frame(vec![]);
|
||||
let (row4, row2) = (u.row_at(rect4), u.row_at(rect2));
|
||||
click(&mut u, row4, Modifiers::NONE);
|
||||
click(&mut u, row2, SHIFT);
|
||||
assert_eq!(
|
||||
sorted(u.app.session.selection()),
|
||||
sorted(vec![rect4, frame1]),
|
||||
"the range keeps Frame 1 and drops its covered children {rect3:?} and {rect2:?}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_second_shift_click_after_a_reverse_cross_frame_range_extends_the_range() {
|
||||
let mut s = Session::new();
|
||||
let frame1 = id(s.execute("frame.create", &json!({"x": 0, "y": 0, "width": 100, "height": 100, "name": "Frame 1"})).unwrap());
|
||||
let rect2 = rect(&mut s, "Rect 2", 0.0, Some(frame1));
|
||||
let rect3 = rect(&mut s, "Rect 3", 30.0, Some(frame1));
|
||||
let frame2 = id(s.execute("frame.create", &json!({"x": 200, "y": 0, "width": 100, "height": 100, "name": "Frame 2"})).unwrap());
|
||||
let rect4 = rect(&mut s, "Rect 4", 0.0, Some(frame2));
|
||||
s.execute("select.none", &json!({})).unwrap();
|
||||
let mut u = Ui::new(s);
|
||||
u.app.ui.expanded.extend([frame1, frame2]);
|
||||
u.frame(vec![]);
|
||||
let (row2, row4, row3) = (u.row_at(rect2), u.row_at(rect4), u.row_at(rect3));
|
||||
click(&mut u, row2, Modifiers::NONE);
|
||||
click(&mut u, row4, SHIFT);
|
||||
assert_eq!(sorted(u.app.session.selection()), sorted(vec![rect4, frame1]));
|
||||
// Rows run Frame 2, Rect 4, Frame 1, Rect 3, Rect 2: the range from Rect 2 to Rect 3 is those two.
|
||||
click(&mut u, row3, SHIFT);
|
||||
assert_eq!(sorted(u.app.session.selection()), sorted(vec![rect3, rect2]), "the range still runs from Rect 2, not a toggle");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_shift_range_inside_one_frame_is_unchanged() {
|
||||
let mut s = Session::new();
|
||||
let frame = id(s.execute("frame.create", &json!({"x": 0, "y": 0, "width": 100, "height": 100, "name": "F"})).unwrap());
|
||||
let kids = [0.0, 30.0, 60.0].map(|x| rect(&mut s, "k", x, Some(frame)));
|
||||
s.execute("select.none", &json!({})).unwrap();
|
||||
let mut u = Ui::new(s);
|
||||
u.app.ui.expanded.insert(frame);
|
||||
u.frame(vec![]);
|
||||
let (first, last) = (u.row_at(kids[0]), u.row_at(kids[2]));
|
||||
click(&mut u, first, Modifiers::NONE);
|
||||
click(&mut u, last, SHIFT);
|
||||
assert_eq!(sorted(u.app.session.selection()), sorted(kids.to_vec()));
|
||||
}
|
||||
|
||||
/// The centre of `id`'s icon, a top-level row: the row's left edge is the first point from the
|
||||
/// left at which the pointer is over it, and the icon's centre is 8 (margin) + 4 + 22 points
|
||||
/// further right.
|
||||
|
||||
@@ -76,6 +76,42 @@ fn up_and_down_walk_the_rows_and_shift_extends() {
|
||||
assert_eq!(doc.node(c).unwrap().transform.translation().x, 200.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_keyboard_shift_range_keeps_an_anchor_covered_by_a_selected_frame() {
|
||||
let mut s = Session::new();
|
||||
let frame1 = id(s.execute("frame.create", &json!({"x": 0, "y": 0, "width": 100, "height": 100, "name": "Frame 1"})).unwrap());
|
||||
let mk = |s: &mut Session, name: &str, parent: NodeId| {
|
||||
id(s.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 20, "height": 20, "parent": parent, "props": {"name": name}})).unwrap())
|
||||
};
|
||||
let rect2 = mk(&mut s, "Rect 2", frame1);
|
||||
let rect3 = mk(&mut s, "Rect 3", frame1);
|
||||
let frame2 = id(s.execute("frame.create", &json!({"x": 200, "y": 0, "width": 100, "height": 100, "name": "Frame 2"})).unwrap());
|
||||
let rect4 = mk(&mut s, "Rect 4", frame2);
|
||||
s.execute("select.none", &json!({})).unwrap();
|
||||
let mut u = Ui::new(s);
|
||||
u.app.ui.expanded.extend([frame1, frame2]);
|
||||
u.frame(vec![]);
|
||||
click_row(&mut u, rect2);
|
||||
let p4 = u.row_at(rect4);
|
||||
let shift = Modifiers { shift: true, ..Default::default() };
|
||||
u.frame_with(vec![Event::PointerMoved(p4)], shift);
|
||||
let button = |pressed| Event::PointerButton { pos: p4, button: egui::PointerButton::Primary, pressed, modifiers: shift };
|
||||
u.frame_with(vec![button(true)], shift);
|
||||
u.frame_with(vec![button(false)], shift);
|
||||
let mut got = sel(&u);
|
||||
got.sort();
|
||||
let mut want = vec![rect4, frame1];
|
||||
want.sort();
|
||||
assert_eq!(got, want, "the pointer range keeps the frame");
|
||||
// Rows: Frame 2, Rect 4, Frame 1, Rect 3, Rect 2. Shift+Down runs from Rect 2 (the anchor).
|
||||
key(&mut u, Key::ArrowDown, true);
|
||||
let mut got = sel(&u);
|
||||
got.sort();
|
||||
let mut want = vec![rect3, rect2];
|
||||
want.sort();
|
||||
assert_eq!(got, want, "the keyboard range extends from Rect 2's row, not from the current row");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn left_and_right_open_close_and_move_between_levels() {
|
||||
let (mut u, _, frame, child, _) = setup();
|
||||
|
||||
@@ -637,6 +637,14 @@ fn matching(doc: &Document, id: NodeId, q: &str, out: &mut Vec<Row>) {
|
||||
}
|
||||
}
|
||||
|
||||
/// The range anchor while it is still part of the selection: selected itself, or covered by a
|
||||
/// selected frame (a range across parents selects the frame and not its children).
|
||||
fn live_anchor(app: &FigApp, sel: &[NodeId]) -> Option<NodeId> {
|
||||
let a = app.ui.layer_anchor?;
|
||||
let covered = || app.session.ds().is_ok_and(|ds| ds.doc.ancestors(a).iter().any(|p| sel.contains(p)));
|
||||
(sel.contains(&a) || covered()).then_some(a)
|
||||
}
|
||||
|
||||
/// Arrow keys while the layers panel has the keyboard: Up/Down select the row above or below
|
||||
/// (Shift extends the range from the anchor), Left collapses a row or goes to its parent, Right
|
||||
/// expands a row or goes to its first child. Returns whether the key was used.
|
||||
@@ -669,7 +677,7 @@ pub(crate) fn key_nav(app: &mut FigApp, key: egui::Key, shift: bool) -> bool {
|
||||
let Some((j, next)) = j.and_then(|j| rows.get(j).map(|r| (j, r.id))) else { return true };
|
||||
if shift {
|
||||
// The rows from the anchor to the new one, with the moving end last.
|
||||
let anchor = app.ui.layer_anchor.filter(|a| sel.contains(a)).unwrap_or(cur);
|
||||
let anchor = live_anchor(app, &sel).unwrap_or(cur);
|
||||
let a = rows.iter().position(|r| r.id == anchor).unwrap_or(i);
|
||||
let ids: Vec<NodeId> = if a <= j {
|
||||
rows.get(a..=j).unwrap_or_default().iter().map(|r| r.id).collect()
|
||||
@@ -909,7 +917,8 @@ fn select_clicked(app: &mut FigApp, rows: &[Row], sel: &[NodeId], id: NodeId, m:
|
||||
app.ui.pages_focus = None;
|
||||
let order: Vec<NodeId> = rows.iter().map(|r| r.id).collect();
|
||||
let pos = |x: NodeId| order.iter().position(|o| *o == x);
|
||||
let anchor = app.ui.layer_anchor.filter(|a| sel.contains(a)).and_then(pos);
|
||||
let live = live_anchor(app, sel);
|
||||
let anchor = live.and_then(pos);
|
||||
if m.shift
|
||||
&& let (Some(ai), Some(bi)) = (anchor, pos(id))
|
||||
{
|
||||
@@ -921,6 +930,11 @@ fn select_clicked(app: &mut FigApp, rows: &[Row], sel: &[NodeId], id: NodeId, m:
|
||||
s.push(*x);
|
||||
}
|
||||
}
|
||||
// A layer under a selected ancestor is covered by it, not a member of its own.
|
||||
if let Ok(ds) = app.session.ds() {
|
||||
let all = s.clone();
|
||||
s.retain(|x| !ds.doc.ancestors(*x).iter().any(|a| all.contains(a)));
|
||||
}
|
||||
app.run("select.set", json!({"ids": s}));
|
||||
} else if m.shift || m.command {
|
||||
let mut s = sel.to_vec();
|
||||
|
||||
+3
-2
@@ -1,6 +1,6 @@
|
||||
# UI and interaction parity
|
||||
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-17 · **Change:** minor (points align and distribute in vector edit mode as in Figma: the six Align commands, the keys Alt+A/H/D/W/V/S, and Distribute horizontal and vertical spacing act on the selected points, each moving along one axis to their box's edge or centre line, spaced evenly between the outermost for distribute, with the alignment row first in the Design panel (#2109); going back to a page shows it where it was left, not fitted again; Duplicate repeats the last copy's move and its rotation (about the copy's centre, or the selection's centre for several layers), not its size, and forgets the step when the selection changes, measured in Figma's web app on 2026-11-12 (#2293); M8: a double-click on a layer's icon zooms to it instead of renaming, measured in Figma's web app on 2026-11-12; Tidy up keeps the order and sizes and evens the gaps, as measured in Figma's web app on 2026-11-12, rounds the gap half up, tidies overlapping rows and packs a grid along its longer axis, and is greyed out for fewer than three layers, a diagonal and an irregular layout (M8); after Crop is chosen in the image fill's colour picker, a drag on the image crops it instead of moving the layer, and no internal gesture message shows (#2307); Align is disabled for a layer in an auto layout frame's flow, as measured in Figma's web app on 2026-11-12, with a tip saying the frame places it; Select layer lists locked layers with a padlock and selects them, and shows only with more than one layer under the pointer (#1560); M8: Scale tool handle drags pivot on the opposite handle whatever the origin, and the origin starts at the centre (measured in Figma's web app, 2026-11-09); M8: a selected polygon or star has a Count handle on the canvas, on its first point clockwise from the top; Zoom to selection leaves a 40 pt margin and clears the bottom toolbar, measured in Figma's web app; M1: Paste over selection puts the pasted layers just above the selected layer; drag modifiers compared in Figma's web app (2026-11-08): Shift locks a move to the dominant axis, Alt copies, Shift keeps a resize's ratio, Alt keeps its centre, all read afresh on every move, and FigCraft matches (Ctrl/Cmd not measurable); a mirror mode (angle, or angle and length) on a sharp point turns it smooth, as in Figma (#2110); M8: Tab while renaming the last layer wraps to the first row, measured in Figma's web app on 2026-11-12; the text caret takes the text's solid fill colour (#2156); the Rotation field shows and sets the rotation on the page, in frames and groups, through node.set absoluteRotation (#2196); the eyedropper picks a magnified image's pixel under the pointer, not a blend with its neighbours (#2189); Selection colors shows from one distinct colour when a selected layer has children, and from two otherwise, measured in Figma's web app on 2026-11-09 on a frame, a group and plain rectangles; the crosshair of the shape and Text tools is drawn dark with a white edge, so it shows on a white frame whatever the system's pointer style (#2198); a boolean group takes a corner radius (and smoothing) that rounds every sharp corner of its result (#2222); the Point section's X and Y in vector edit mode show Mixed and set every selected point of the layer being edited, as in Figma; Preferences ▸ Invert zoom direction reverses wheel zoom, pinch unchanged (#2145); Shift while rotating lands on absolute multiples of 15°, measured in Figma; Flatten bakes a vector's point corner radius into its path (#2195); a click on a fill, stroke or effect row's grip or background highlights it, Cmd/Ctrl+C copies that paint or effect and Cmd/Ctrl+V pastes it onto the selected layers, as the help center's Copy and paste properties between layers says (#1494); wrap style per paragraph and in text styles (#1827); the Annotation tool (Shift+T, `tool.annotation {id?}`): with a layer selected (or an `id`) it asks the UI for that layer's note at once, and in the tool a press on a layer selects it and asks for its note, a press on empty canvas does nothing; the marquee follows Figma's measured rules: a partly covered frame or section gives the layers in it the marquee touches, a rotated shape is touched by its outline, a drag from inside a frame selects that frame only when the marquee also takes another top-level frame (then whole) (`marquee_behaviour_tests`); copy, cut and paste in vector edit mode act on the selected points and segments (#1875); M8, #2146: K focuses the Scale tool's factor field with its text selected, so K, 2, Enter scales the selection by two about the panel's origin (FigCraft's starts at the top left; Figma's grid starts at the centre, left for a follow-up because the origin also sets where a handle drag pivots, which is not measured) in one undo step, after which the tool returns to Move with the selection kept; Escape in the field closes it with the tool back on Move and nothing changed (measured in Figma'Line truncated
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-19 · **Change:** minor (M8: a Shift-click range in the Layers panel across parents keeps a frame and not its covered children, measured in Figma's web app on 2026-11-12; points align and distribute in vector edit mode as in Figma: the six Align commands, the keys Alt+A/H/D/W/V/S, and Distribute horizontal and vertical spacing act on the selected points, each moving along one axis to their box's edge or centre line, spaced evenly between the outermost for distribute, with the alignment row first in the Design panel (#2109); going back to a page shows it where it was left, not fitted again; Duplicate repeats the last copy's move and its rotation (about the copy's centre, or the selection's centre for several layers), not its size, and forgets the step when the selection changes, measured in Figma's web app on 2026-11-12 (#2293); M8: a double-click on a layer's icon zooms to it instead of renaming, measured in Figma's web app on 2026-11-12; Tidy up keeps the order and sizes and evens the gaps, as measured in Figma's web app on 2026-11-12, rounds the gap half up, tidies overlapping rows and packs a grid along its longer axis, and is greyed out for fewer than three layers, a diagonal and an irregular layout (M8); after Crop is chosen in the image fill's colour picker, a drag on the image crops it instead of moving the layer, and no internal gesture message shows (#2307); Align is disabled for a layer in an auto layout frame's flow, as measured in Figma's web app on 2026-11-12, with a tip saying the frame places it; Select layer lists locked layers with a padlock and selects them, and shows only with more than one layer under the pointer (#1560); M8: Scale tool handle drags pivot on the opposite handle whatever the origin, and the origin starts at the centre (measured in Figma's web app, 2026-11-09); M8: a selected polygon or star has a Count handle on the canvas, on its first point clockwise from the top; Zoom to selection leaves a 40 pt margin and clears the bottom toolbar, measured in Figma's web app; M1: Paste over selection puts the pasted layers just above the selected layer; drag modifiers compared in Figma's web app (2026-11-08): Shift locks a move to the dominant axis, Alt copies, Shift keeps a resize's ratio, Alt keeps its centre, all read afresh on every move, and FigCraft matches (Ctrl/Cmd not measurable); a mirror mode (angle, or angle and length) on a sharp point turns it smooth, as in Figma (#2110); M8: Tab while renaming the last layer wraps to the first row, measured in Figma's web app on 2026-11-12; the text caret takes the text's solid fill colour (#2156); the Rotation field shows and sets the rotation on the page, in frames and groups, through node.set absoluteRotation (#2196); the eyedropper picks a magnified image's pixel under the pointer, not a blend with its neighbours (#2189); Selection colors shows from one distinct colour when a selected layer has children, and from two otherwise, measured in Figma's web app on 2026-11-09 on a frame, a group and plain rectangles; the crosshair of the shape and Text tools is drawn dark with a white edge, so it shows on a white frame whatever the system's pointer style (#2198); a boolean group takes a corner radius (and smoothing) that rounds every sharp corner of its result (#2222); the Point section's X and Y in vector edit mode show Mixed and set every selected point of the layer being edited, as in Figma; Preferences ▸ Invert zoom direction reverses wheel zoom, pinch unchanged (#2145); Shift while rotating lands on absolute multiples of 15°, measured in Figma; Flatten bakes a vector's point corner radius into its path (#2195); a click on a fill, stroke or effect row's grip or background highlights it, Cmd/Ctrl+C copies that paint or effect and Cmd/Ctrl+V pastes it onto the selected layers, as the help center's Copy and paste properties between layers says (#1494); wrap style per paragraph and in text styles (#1827); the Annotation tool (Shift+T, `tool.annotation {id?}`): with a layer selected (or an `id`) it asks the UI for that layer's note at once, and in the tool a press on a layer selects it and asks for its note, a press on empty canvas does nothing; the marquee follows Figma's measured rules: a partly covered frame or section gives the layers in it the marquee touches, a rotated shape is touched by its outline, a drag from inside a frame selects that frame only when the marquee also takes another top-level frame (then whole) (`marquee_behaviour_tests`); copy, cut and paste in vector edit mode act on the selected points and segments (#1875); M8, #2146: K focuses the Scale tool's factor field with its text selected, so K, 2, Enter scales the selection by two about the panel's origin (FigCraft's starts at the top left; Figma's grid starts at the centre, left for a follow-up because the origin also sets where a handle drag pivots, which is not measured) in one undo step, after which Line truncated
|
||||
|
||||
Fine canvas control is what Figma users feel first: handles, snapping, nudging, modifier keys,
|
||||
drag behaviour, numeric precision. This checklist covers the tools, gestures and panels. Status:
|
||||
@@ -43,7 +43,7 @@ interaction feel only partly compared: the interactions measured so far, case by
|
||||
|
||||
| Item | Status | Notes |
|
||||
|---|---|---|
|
||||
| Rows: click, Shift-click range, Cmd/Ctrl-click toggle; the selection follows on the canvas and a canvas selection is revealed | done | `layers_behaviour_tests`; selected hierarchies share a continuous background with rounded outer corners, including nested selections |
|
||||
| Rows: click, Shift-click range, Cmd/Ctrl-click toggle; the selection follows on the canvas and a canvas selection is revealed | done | `layers_behaviour_tests`; a range across parents keeps a frame and not its covered children (Rect 4 then Shift on Rect 2 in another frame gives Rect 4 and the frame between; measured in Figma's web app, 2026-11-12); selected hierarchies share a continuous background with rounded outer corners, including nested selections |
|
||||
| Expand and collapse: Alt-click opens or closes everything inside; Collapse layers (Alt+L) keeps the way to the selection open | done | Alt-click pinned (the documentation is silent) |
|
||||
| Drag to reorder and into frames, groups and auto layout: insertion line, spring-loaded open, several layers together, Escape cancels | done | several layers dropped together land together (they split apart before); instances and a layer's own children refuse drops |
|
||||
| Eye and padlock: click, or drag across rows to set several in one step; layers in a locked frame show a faint padlock | done | the toggles no longer vanish under the pointer (clicks on them could miss) (a child's padlock can't be toggled while its parent is locked) |
|
||||
@@ -210,6 +210,7 @@ This audit records candidates for subsequent fixes; their behaviour is unchanged
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-11-19 | patch | M8: a Shift-click range in the Layers panel keeps a frame and not its covered children: a range across parents selects a frame whose row is inside it, and drops the rows under that frame, as measured in Figma's web app on 2026-11-12 (Rect 4 in one frame, Shift-click Rect 2 in another: Rect 4 and the second frame, 2 selected); a range among siblings is unchanged; Cmd with Shift reduces the combined set the same way, not measured |
|
||||
| 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) |
|
||||
|
||||
Reference in new issue
Block a user