M1: A drag on a section's background, or an artboard's in it, draws a marquee

The background of a top-level frame with layers already acted like the
canvas: a press there starts a marquee inside it. A section and the
frames in it got none of that, so a drag anywhere in a section with
artboards picked up the section (or the artboard) and moved it, and
nothing in it could be marked out with the pointer.

- An unselected section with layers, and a frame with layers directly
  in a section, now act like a top-level frame's background: a click
  deselects, a drag draws a marquee. A section still moves by its name
  label, or by its body once selected.
- A marquee started in a section selects among the section's layers as
  one started on the page does among the page's (artboards it encloses
  whole, else the layers it touches inside them); one started in an
  artboard in a section selects inside that artboard.
- With Cmd/Ctrl held, a drag from such a background draws the deep
  marquee instead of moving the frame or section, selecting the nested
  layers it touches. This holds when the artboard or section is
  selected too: with Cmd/Ctrl its background counts as background, and
  the press doesn't fall back to dragging the selection. A Cmd/Ctrl
  click there without a drag still selects the frame or section, and
  without Cmd/Ctrl a selected section or artboard still drags by its
  body.

The comment above board_background ("unless the frame is selected")
still describes the press without Cmd/Ctrl.

Tests: section_marquee_tests.
This commit is contained in:
Denis Gomes committed 2026-11-19 15:11:18 -05:00
1 parent 4e35fb9cea
commit 26860bd367
5 files changed
+168 -10

No files matched your search

+20 -6
View File
@@ -79,15 +79,22 @@ impl Session {
// layers in it is like the canvas (a press starts a marquee inside it) unless the frame is
// selected; stepping out from a selected descendant is handled by the marquee below.
// An empty frame (or a widget, or a board object such as a sticky) is picked and dragged.
let in_section = |n: &figcraft_doc::Node| n.parent.and_then(|p| doc.node(p)).is_some_and(|p| matches!(p.kind, NodeKind::Section { .. }));
let board_background = |leaf: NodeId| {
!sel.contains(&leaf)
(ev.cmd || !sel.contains(&leaf))
&& doc.node(leaf).is_some_and(|n| {
n.parent == Some(page) && n.kind.is_frame_like() && !n.children.is_empty() && !crate::widgets::is_widget(n) && !n.is_board_atom()
let board = match n.kind {
NodeKind::Section { contents_hidden } => !contents_hidden,
ref k => k.is_frame_like() && (n.parent == Some(page) || in_section(n)),
};
board && !n.children.is_empty() && !crate::widgets::is_widget(n) && !n.is_board_atom()
})
};
let label = label_at(&doc, page, &self.tool.labels, ev.p());
let hit = label.or_else(|| self.hit(&doc, page, ev.p(), ev.tol() * 2.0));
let target = label.or_else(|| hit.filter(|leaf| ev.cmd || !board_background(*leaf)).map(|leaf| select_target(&doc, leaf, &sel, ev.cmd)));
let leaf = self.hit(&doc, page, ev.p(), ev.tol() * 2.0);
let hit = label.or(leaf);
let background_under_cmd = leaf.filter(|l| ev.cmd && label.is_none() && board_background(*l));
let target = label.or_else(|| leaf.filter(|leaf| !board_background(*leaf)).map(|leaf| select_target(&doc, leaf, &sel, ev.cmd)));
// A press inside the selection's box that reaches nothing above it (an unfilled shape's
// 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.
@@ -105,8 +112,15 @@ impl Session {
// selects just it. A press that reaches nothing above the selection uses the selection as
// its drag target instead; that fallback is not a clicked layer.
let clicked = target;
let marks_out_a_selected_board = background_under_cmd.is_some_and(|b| sel.contains(&b));
let target = match sel.iter().copied().find(|s| !locked_in(&doc, *s)) {
Some(first) if label.is_none() && !ev.shift && behind_sel(target) && selection_box(&doc, &sel).is_some_and(|q| in_quad(&q, ev.p())) => {
Some(first)
if label.is_none()
&& !ev.shift
&& !marks_out_a_selected_board
&& behind_sel(target)
&& selection_box(&doc, &sel).is_some_and(|q| in_quad(&q, ev.p())) =>
{
Some(first)
}
_ => target,
@@ -186,7 +200,7 @@ impl Session {
if let Some(f) = parent {
self.set_selection(vec![f]);
} else if !ev.shift {
self.set_selection(vec![]);
self.set_selection(background_under_cmd.into_iter().collect());
}
self.tool.gesture = Gesture::Marquee {
start: ev.p(),
+29 -3
View File
@@ -38,11 +38,34 @@ impl Session {
/// (its children), or the focus view's frame.
pub(crate) fn marquee_within(&self, p: Point) -> Result<Option<NodeId>> {
let (doc, page) = (self.doc()?, self.page()?);
let within = frame_at(doc, page, p, &[]).filter(|f| doc.node(*f).is_some_and(|n| n.parent == Some(page)));
let within = within.filter(|f| doc.world_bounds(*f).is_some_and(|b| b.contains(p)));
let deepest = frame_at(doc, page, p, &[]).filter(|f| doc.world_bounds(*f).is_some_and(|b| b.contains(p)));
let mut chain = deepest.map(|f| doc.ancestors(f)).unwrap_or_default();
chain.reverse();
chain.extend(deepest);
let mut within = None;
for c in chain.into_iter().filter(|c| *c != page) {
let Some(n) = doc.node(c) else { break };
match &n.kind {
NodeKind::Section { contents_hidden: false } => within = Some(c),
k if k.is_frame_like() => {
within = Some(c);
break;
}
_ => break,
}
}
Ok(self.ds()?.focused().or(within))
}
fn marquee_root(&self, within: Option<NodeId>) -> Result<(NodeId, Option<NodeId>)> {
let (doc, page) = (self.doc()?, self.page()?);
Ok(match within.and_then(|w| doc.node(w)) {
Some(n) if matches!(n.kind, NodeKind::Section { .. }) => (n.id, None),
Some(n) => (n.parent.unwrap_or(page), Some(n.id)),
None => (page, None),
})
}
/// The selection a marquee over page rect `r` makes from `base` (what was selected before):
/// the layers it touches (`deep`: nested ones too); `additive` (Shift) toggles them.
pub(crate) fn marquee_selection(&self, r: Rect, within: Option<NodeId>, deep: bool, base: &[NodeId], additive: bool) -> Result<Vec<NodeId>> {
@@ -51,7 +74,10 @@ impl Session {
let mut hits = match (deep, focused) {
(true, _) => figcraft_doc::geometry::marquee_deep(doc, page, r),
(false, Some(f)) => figcraft_doc::geometry::marquee(doc, page, r, Some(f)),
(false, None) => figcraft_doc::geometry::marquee_select(doc, page, r, within),
(false, None) => {
let (root, start_inside) = self.marquee_root(within)?;
figcraft_doc::geometry::marquee_select(doc, root, r, start_inside)
}
};
if let Some(f) = focused {
hits.retain(|h| *h != f && doc.is_ancestor(f, *h));
+2
View File
@@ -563,6 +563,8 @@ mod scaled_instance_tests;
#[cfg(test)]
mod section_contents_tests;
#[cfg(test)]
mod section_marquee_tests;
#[cfg(test)]
mod section_tests;
#[cfg(test)]
mod select_area_tests;
+115
View File
@@ -0,0 +1,115 @@
use figcraft_doc::NodeId;
use serde_json::{Value, json};
use crate::Session;
use crate::params::id_of;
use crate::tools::{PointerEvent, PointerKind};
fn ex(s: &mut Session, cmd: &str, p: Value) -> NodeId {
id_of(&s.execute(cmd, &p).unwrap_or_else(|e| panic!("{cmd}: {e}"))["id"]).unwrap()
}
fn rect(s: &mut Session, x: f64, y: f64, parent: NodeId) -> NodeId {
ex(s, "shape.rectangle", json!({"x": x, "y": y, "width": 40, "height": 40, "parent": parent}))
}
struct Scene {
section: NodeId,
left: NodeId,
right: NodeId,
in_left: [NodeId; 2],
in_right: NodeId,
}
fn scene(s: &mut Session) -> Scene {
let section = ex(s, "node.create", json!({"type": "section", "x": 0, "y": 0, "width": 1000, "height": 600}));
let left = ex(s, "frame.create", json!({"x": 50, "y": 50, "width": 300, "height": 300, "parent": section}));
let right = ex(s, "frame.create", json!({"x": 400, "y": 50, "width": 300, "height": 300, "parent": section}));
let in_left = [rect(s, 20.0, 20.0, left), rect(s, 120.0, 120.0, left)];
let in_right = rect(s, 20.0, 20.0, right);
s.execute("select.none", &json!({})).unwrap();
Scene { section, left, right, in_left, in_right }
}
fn ev(kind: PointerKind, p: (f64, f64), cmd: bool) -> PointerEvent {
PointerEvent { cmd, ..PointerEvent::at(kind, p.0, p.1, 1.0) }
}
fn drag(s: &mut Session, a: (f64, f64), b: (f64, f64), cmd: bool) -> Vec<NodeId> {
s.pointer(&ev(PointerKind::Down, a, cmd)).unwrap();
s.pointer(&ev(PointerKind::Move, b, cmd)).unwrap();
s.pointer(&ev(PointerKind::Up, b, cmd)).unwrap();
let mut sel = s.selection();
sel.sort();
sel
}
fn x_of(s: &Session, id: NodeId) -> f64 {
s.doc().unwrap().world_bounds(id).unwrap().x0
}
fn sorted(mut v: Vec<NodeId>) -> Vec<NodeId> {
v.sort();
v
}
#[test]
fn a_drag_on_an_artboards_background_in_a_section_selects_what_it_touches() {
let mut s = Session::new();
let k = scene(&mut s);
assert_eq!(drag(&mut s, (60.0, 60.0), (110.0, 110.0), false), vec![k.in_left[0]]);
assert_eq!(drag(&mut s, (340.0, 340.0), (60.0, 60.0), false), sorted(k.in_left.to_vec()));
assert_eq!((x_of(&s, k.section), x_of(&s, k.left)), (0.0, 50.0), "nothing moved");
}
#[test]
fn a_drag_on_a_sections_background_selects_the_artboards_layers_it_touches() {
let mut s = Session::new();
let k = scene(&mut s);
assert_eq!(drag(&mut s, (20.0, 400.0), (480.0, 80.0), false), sorted(vec![k.in_left[0], k.in_left[1], k.in_right]));
assert_eq!(drag(&mut s, (20.0, 20.0), (720.0, 380.0), false), sorted(vec![k.left, k.right]), "artboards it encloses go whole");
assert_eq!(x_of(&s, k.section), 0.0, "the section stays put");
}
#[test]
fn a_selected_section_still_drags_and_a_click_on_its_background_steps_out_to_it() {
let mut s = Session::new();
let k = scene(&mut s);
s.execute("select.set", &json!({"ids": [k.section]})).unwrap();
drag(&mut s, (20.0, 400.0), (120.0, 400.0), false);
assert_eq!(x_of(&s, k.section), 100.0);
s.execute("select.set", &json!({"ids": [k.in_right]})).unwrap();
assert_eq!(drag(&mut s, (900.0, 500.0), (900.0, 500.0), false), vec![k.section]);
}
#[test]
fn cmd_drag_from_a_background_marks_out_nested_layers_and_cmd_click_still_picks_the_frame() {
let mut s = Session::new();
let k = scene(&mut s);
assert_eq!(drag(&mut s, (60.0, 60.0), (110.0, 110.0), true), vec![k.in_left[0]]);
assert_eq!(drag(&mut s, (20.0, 400.0), (480.0, 80.0), true), sorted(vec![k.in_left[0], k.in_left[1], k.in_right]));
assert_eq!((x_of(&s, k.section), x_of(&s, k.left)), (0.0, 50.0), "nothing moved");
assert_eq!(drag(&mut s, (300.0, 300.0), (300.0, 300.0), true), vec![k.left]);
assert_eq!(drag(&mut s, (900.0, 500.0), (900.0, 500.0), true), vec![k.section]);
}
#[test]
fn cmd_drag_inside_a_selected_artboard_or_section_marks_out_nested_layers_instead_of_moving_it() {
let mut s = Session::new();
let k = scene(&mut s);
s.execute("select.set", &json!({"ids": [k.left]})).unwrap();
assert_eq!(drag(&mut s, (130.0, 75.0), (90.0, 90.0), true), vec![k.in_left[0]]);
s.execute("select.set", &json!({"ids": [k.section]})).unwrap();
assert_eq!(drag(&mut s, (20.0, 400.0), (480.0, 80.0), true), sorted(vec![k.in_left[0], k.in_left[1], k.in_right]));
assert_eq!((x_of(&s, k.section), x_of(&s, k.left)), (0.0, 50.0), "nothing moved");
s.execute("select.set", &json!({"ids": [k.left]})).unwrap();
assert_eq!(drag(&mut s, (300.0, 300.0), (300.0, 300.0), true), vec![k.left], "a Cmd click keeps the artboard");
assert_eq!(drag(&mut s, (80.0, 80.0), (80.0, 80.0), true), vec![k.in_left[0]], "a Cmd click on a layer in it picks the layer");
let mut s = Session::new();
let board = ex(&mut s, "frame.create", json!({"x": 0, "y": 0, "width": 400, "height": 400}));
let inner = [rect(&mut s, 20.0, 20.0, board), rect(&mut s, 200.0, 200.0, board)];
s.execute("select.set", &json!({"ids": [board]})).unwrap();
assert_eq!(drag(&mut s, (330.0, 30.0), (10.0, 300.0), true), sorted(inner.to_vec()), "a top-level artboard too");
assert_eq!(x_of(&s, board), 0.0);
}
+2 -1
View File
@@ -1,6 +1,6 @@
# UI and interaction parity
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-19 · **Change:** minor (Type settings ▸ Details ▸ Position sets the selected text layers to superscript or subscript, or neither (#2338); Shift with the Pencil, Marker or Highlighter draws one straight segment from where the stroke started, at the nearest 45° step, as the Line tool and the Pen do (#2447); the Design panel's header names a selected component or component set, after its icon, instead of only its type (#2347); dragging near the canvas edge pans the view toward it, as measured in Figma: 40 px/s for each px within about 15 px of the edge, 600 px/s at it, for moving layers, the selection box, drawing and prototype connections (#2015); 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 marqLine truncated
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-19 · **Change:** minor (M1: a drag on a section's background, or on the background of a frame in it, draws a marquee; Type settings ▸ Details ▸ Position sets the selected text layers to superscript or subscript, or neither (#2338); Shift with the Pencil, Marker or Highlighter draws one straight segment from where the stroke started, at the nearest 45° step, as the Line tool and the Pen do (#2447); the Design panel's header names a selected component or component set, after its icon, instead of only its type (#2347); dragging near the canvas edge pans the view toward it, as measured in Figma: 40 px/s for each px within about 15 px of the edge, 600 px/s at it, for moving layers, the selection box, drawing and prototype connections (#2015); 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 folLine 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:
@@ -211,6 +211,7 @@ This audit records candidates for subsequent fixes; their behaviour is unchanged
| Date | Change | Summary |
|---|---|---|
| 2026-11-15 | patch | M1: in a section, a press on the section's background or on the background of a frame in it picked up the section or the frame, so a drag moved it and nothing inside could be marked out. An unselected section with layers, and a frame with layers directly in a section, now act like a top-level frame's background: a click deselects and a drag draws a marquee. The marquee selects among the section's layers as one on the page does among the page's, or inside the frame it starts in. With Cmd/Ctrl held the drag draws the deep marquee, on a selected artboard or section too instead of moving it; a Cmd/Ctrl click without a drag still selects the frame or section. A section moves by its name label, or by its body once selected. Test: `section_marquee_tests` |
| 2026-11-19 | patch | M4, #2338: superscript and subscript were drawn (#1868) but nothing in the interface set them. Type settings ▸ Details now starts with Position: None, Superscript (X²) or Subscript (X₂), for the selected text layers, through `text.setFeatures` (`sups`, `subs`; choosing one clears the other). It shows the layers' current position, none when they differ. Raising a range of characters on its own needs per-run features and is left for a separate change. Test: `typography::variable_tests::details_position_sets_superscript_subscript_or_neither`. |
| 2026-11-19 | patch | M1, #2447: Shift did nothing with the Pencil: a stroke stayed freehand while the Line tool and the Pen keep theirs to 45° steps. With Shift held, the Pencil (and the Marker and Highlighter) now draws one straight segment from where the stroke started to the pointer, at the nearest 45° step; the preview shows it. A Shift-click without a move draws nothing, as before. Tests: `pencil_shift_tests`. |
| 2026-11-19 | patch | M3, #2347: with one component or component set selected, the Design panel's header said only "Component" or "Component set", so the selected one's name was only in the Layers panel. It now shows the name after a component icon (cut short with an ellipsis clear of the quick actions), with the type, and the whole name when cut, on hover. Other layers keep their type. Test: `component_header_tests::the_header_names_the_selected_component_or_set`. |