mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-29 01:34:37 +01:00
Merge pull request #2483 from denisg0mes/shift-double-click-goes-deeper-alongside
M1: Shift with a double-click goes deeper and keeps the rest of the selection
This commit is contained in:
6 files changed
+164
-1
No files matched your search
@@ -649,6 +649,10 @@ pub struct ToolState {
|
||||
pub place_at: Option<Point>,
|
||||
/// The document (uid) and page the crosshair was shown on.
|
||||
pub(crate) place_on: Option<(u64, NodeId)>,
|
||||
/// The last two Move or Scale presses, oldest first: where each was and the selection just
|
||||
/// before it. A Shift double-click works from the selection its first click found. A press
|
||||
/// with another tool clears them, and so does the double-click that uses them.
|
||||
pub(crate) selections_before_last_two_presses: [Option<(Point, Vec<NodeId>)>; 2],
|
||||
}
|
||||
|
||||
impl ToolState {
|
||||
|
||||
@@ -139,6 +139,38 @@ impl Session {
|
||||
return crate::vectoredit::begin_many(self, &ids);
|
||||
}
|
||||
// Groups, frames and boolean groups: select one level deeper (the layer under the pointer).
|
||||
if ev.shift && !ev.cmd {
|
||||
// Both presses recorded here are this double-click's; without them (the presses came in
|
||||
// one frame with the double-click, or with another tool) the current selection stands in.
|
||||
let before_the_clicks = match std::mem::take(&mut self.tool.selections_before_last_two_presses) {
|
||||
[Some((first, before)), Some((second, _))] if within_slop(ev, first) && within_slop(ev, second) => before,
|
||||
_ => sel.clone(),
|
||||
};
|
||||
let entered_here = before_the_clicks.iter().any(|s| *s == leaf || doc.is_ancestor(*s, leaf));
|
||||
let deeper = if entered_here {
|
||||
figcraft_doc::geometry::enter_target(&doc, leaf, &before_the_clicks)
|
||||
} else {
|
||||
let mut branch = doc.ancestors(leaf);
|
||||
branch.reverse();
|
||||
branch.push(leaf);
|
||||
let clicked = select_target(&doc, leaf, &before_the_clicks, false);
|
||||
let beside_the_selection = before_the_clicks
|
||||
.iter()
|
||||
.filter_map(|s| branch.iter().rposition(|b| doc.is_ancestor(*b, *s)))
|
||||
.max()
|
||||
.and_then(|shared| branch.get(shared + 1))
|
||||
.copied();
|
||||
let start = beside_the_selection.filter(|b| doc.is_ancestor(clicked, *b)).unwrap_or(clicked);
|
||||
figcraft_doc::geometry::enter_target(&doc, leaf, &[start])
|
||||
};
|
||||
let mut alongside: Vec<NodeId> = before_the_clicks
|
||||
.into_iter()
|
||||
.filter(|s| doc.contains(*s) && *s != deeper && !doc.is_ancestor(*s, deeper) && !doc.is_ancestor(deeper, *s))
|
||||
.collect();
|
||||
alongside.push(deeper);
|
||||
self.set_selection(alongside);
|
||||
return Ok(());
|
||||
}
|
||||
let deeper = figcraft_doc::geometry::enter_target(&doc, leaf, &sel);
|
||||
if deeper != target || !sel.contains(&deeper) {
|
||||
self.set_selection(vec![deeper]);
|
||||
|
||||
@@ -162,6 +162,11 @@ impl Session {
|
||||
}
|
||||
let tool = self.acting_tool();
|
||||
let edits = matches!(tool, ToolId::Move | ToolId::Scale) && !self.tool.dev_mode;
|
||||
// Presses with another tool don't record the selection: the ones from before them aren't
|
||||
// this double-click's.
|
||||
if ev.kind == PointerKind::Down && !matches!(tool, ToolId::Move | ToolId::Scale) {
|
||||
self.tool.selections_before_last_two_presses = Default::default();
|
||||
}
|
||||
if edits && self.origin_pointer(ev)? {
|
||||
return Ok(());
|
||||
}
|
||||
@@ -181,6 +186,9 @@ impl Session {
|
||||
}
|
||||
// A click on the canvas deselects a ruler guide (the UI selects guides itself).
|
||||
self.ds_mut()?.guide = None;
|
||||
let now = self.ds()?.selection.clone();
|
||||
let [_, last] = std::mem::take(&mut self.tool.selections_before_last_two_presses);
|
||||
self.tool.selections_before_last_two_presses = [last, Some((ev.p(), now))];
|
||||
self.move_down(ev)
|
||||
}
|
||||
ToolId::Hand => {
|
||||
|
||||
@@ -596,6 +596,8 @@ mod shapebuilder_tests;
|
||||
#[cfg(test)]
|
||||
mod shapes_behaviour_tests;
|
||||
#[cfg(test)]
|
||||
mod shift_double_click_tests;
|
||||
#[cfg(test)]
|
||||
mod shortcut_parity_tests;
|
||||
#[cfg(test)]
|
||||
mod sketch_import_tests;
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::Session;
|
||||
use crate::params::id_of;
|
||||
use crate::tools::{PointerEvent, PointerKind};
|
||||
use figcraft_doc::NodeId;
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
struct Board {
|
||||
frame: NodeId,
|
||||
inner: NodeId,
|
||||
rect: NodeId,
|
||||
}
|
||||
|
||||
fn board(s: &mut Session, x: f64) -> Board {
|
||||
let frame = ex(s, "frame.create", json!({"x": x, "y": 0, "width": 300, "height": 300}));
|
||||
let rect = ex(s, "shape.rectangle", json!({"x": 50, "y": 50, "width": 100, "height": 100, "parent": frame}));
|
||||
let other = ex(s, "shape.rectangle", json!({"x": 200, "y": 200, "width": 40, "height": 40, "parent": frame}));
|
||||
let inner = ex(s, "object.group", json!({"ids": [rect, other]}));
|
||||
let extra = ex(s, "shape.rectangle", json!({"x": 250, "y": 20, "width": 20, "height": 20, "parent": frame}));
|
||||
ex(s, "object.group", json!({"ids": [inner, extra]}));
|
||||
Board { frame, inner, rect }
|
||||
}
|
||||
|
||||
fn send(s: &mut Session, kind: PointerKind, x: f64, y: f64, shift: bool) {
|
||||
s.pointer(&PointerEvent { shift, ..PointerEvent::at(kind, x, y, 1.0) }).unwrap();
|
||||
}
|
||||
|
||||
fn double_click(s: &mut Session, x: f64, y: f64, shift: bool) -> Vec<NodeId> {
|
||||
send(s, PointerKind::Down, x, y, shift);
|
||||
send(s, PointerKind::Up, x, y, shift);
|
||||
send(s, PointerKind::Down, x, y, shift);
|
||||
send(s, PointerKind::DoubleClick, x, y, shift);
|
||||
send(s, PointerKind::Up, x, y, shift);
|
||||
send(s, PointerKind::Move, x + 1.0, y, shift);
|
||||
let mut sel = s.selection();
|
||||
sel.sort();
|
||||
sel
|
||||
}
|
||||
|
||||
fn sorted(mut v: Vec<NodeId>) -> Vec<NodeId> {
|
||||
v.sort();
|
||||
v
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shift_double_clicks_go_deeper_in_a_neighbouring_artboard_and_keep_the_rest() {
|
||||
let mut s = Session::new();
|
||||
let a = board(&mut s, 0.0);
|
||||
let b = board(&mut s, 400.0);
|
||||
s.execute("select.none", &json!({})).unwrap();
|
||||
|
||||
assert_eq!(double_click(&mut s, 100.0, 100.0, false), vec![a.inner], "a plain double-click enters the artboard");
|
||||
assert_eq!(double_click(&mut s, 500.0, 100.0, true), sorted(vec![a.inner, b.inner]), "Shift: the neighbour's layer joins");
|
||||
assert_eq!(double_click(&mut s, 500.0, 100.0, true), sorted(vec![a.inner, b.rect]), "Shift again: a level deeper there");
|
||||
assert_eq!(double_click(&mut s, 100.0, 100.0, true), sorted(vec![a.rect, b.rect]), "and in the first artboard too");
|
||||
assert!(s.ds().unwrap().vector_edit.is_none());
|
||||
assert_eq!(s.doc().unwrap().node(a.frame).unwrap().children.len(), 1, "nothing moved out of place");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_shift_double_click_on_a_neighbouring_row_adds_its_layer_at_the_selected_depth() {
|
||||
let mut s = Session::new();
|
||||
let section = ex(&mut s, "node.create", json!({"type": "section", "x": -100, "y": -100, "width": 1200, "height": 1000}));
|
||||
let artboard = ex(&mut s, "frame.create", json!({"x": 0, "y": 0, "width": 1000, "height": 800}));
|
||||
s.execute("node.reparent", &json!({"ids": [artboard], "parent": section})).unwrap();
|
||||
let content = ex(&mut s, "frame.create", json!({"x": 100, "y": 100, "width": 600, "height": 400, "parent": artboard}));
|
||||
let specs = ex(&mut s, "frame.create", json!({"x": 0, "y": 100, "width": 600, "height": 200, "parent": content}));
|
||||
let names: Vec<NodeId> = (0..3)
|
||||
.map(|i| {
|
||||
let row = ex(&mut s, "frame.create", json!({"x": 30, "y": i * 30, "width": 560, "height": 22, "parent": specs}));
|
||||
let name = ex(&mut s, "frame.create", json!({"x": 0, "y": 0, "width": 120, "height": 22, "parent": row}));
|
||||
ex(&mut s, "text.create", json!({"text": "Client:", "x": 0, "y": 0, "parent": name}));
|
||||
name
|
||||
})
|
||||
.collect();
|
||||
s.execute("select.set", &json!({"ids": [names[0]]})).unwrap();
|
||||
|
||||
assert_eq!(double_click(&mut s, 135.0, 238.0, true), sorted(vec![names[0], names[1]]), "the next row's name joins the selected one");
|
||||
assert_eq!(double_click(&mut s, 135.0, 268.0, true), sorted(names.clone()), "and the row after it");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_shift_double_click_with_the_hand_keeps_a_selection_made_after_earlier_presses() {
|
||||
let mut s = Session::new();
|
||||
let a = board(&mut s, 0.0);
|
||||
let b = board(&mut s, 400.0);
|
||||
s.execute("select.set", &json!({"ids": [a.inner]})).unwrap();
|
||||
for _ in 0..2 {
|
||||
send(&mut s, PointerKind::Down, 100.0, 100.0, false);
|
||||
send(&mut s, PointerKind::Up, 100.0, 100.0, false);
|
||||
}
|
||||
s.execute("select.set", &json!({"ids": [b.inner]})).unwrap();
|
||||
s.set_tool(crate::tools::ToolId::Hand);
|
||||
|
||||
assert_eq!(double_click(&mut s, 100.0, 100.0, true), sorted(vec![a.inner, b.inner]), "the Move presses' selection doesn't come back");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_shift_double_click_without_its_presses_keeps_the_current_selection() {
|
||||
let mut s = Session::new();
|
||||
let a = board(&mut s, 0.0);
|
||||
let b = board(&mut s, 400.0);
|
||||
s.execute("select.set", &json!({"ids": [a.inner]})).unwrap();
|
||||
for _ in 0..2 {
|
||||
send(&mut s, PointerKind::Down, 1000.0, 1000.0, false);
|
||||
send(&mut s, PointerKind::Up, 1000.0, 1000.0, false);
|
||||
}
|
||||
s.execute("select.set", &json!({"ids": [b.inner]})).unwrap();
|
||||
|
||||
send(&mut s, PointerKind::DoubleClick, 100.0, 100.0, true);
|
||||
assert_eq!(sorted(s.selection()), sorted(vec![a.inner, b.inner]), "a double-click alone works from the selection it finds");
|
||||
}
|
||||
+2
-1
@@ -1,6 +1,6 @@
|
||||
# UI and interaction parity
|
||||
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-24 · **Change:** minor (M1: Frame selection makes a frame without a fill; M1: centred auto-width text keeps its middle as it grows and shrinks; M1: a drag on a section's background, or on the background of a frame in it, draws a marquee; the Layers panel's eye and padlock stay at the list's right edge, and a name takes at most 400 pt; in vector edit mode, deleting a point selects the next one on its path, so Delete pressed again goes on along it; the hover and selection outline of a curved layer bends smoothly instead of showing straight pieces; text copied while editing, or a whole text layer copied, pastes into a text edit with its formatting and its layer's colour, and Shift+Cmd/Ctrl+V (also Alt+Cmd/Ctrl+V) pastes it in the style at the caret; crop mode: the layer's sides and corners crop its image in an auto layout frame too, up to the image's edges, change a locked ratio (Shift keeps it), the image's own corners scale freely with Shift proportional as a resize does, and crop mode and vector edit mode end each other; after a click on a layer row the arrow keys nudge the selection, or move a layer in an auto layout flow one place, as in Figma; the rows take the arrows once they have the keyboard (F6); Shift+Cmd/Ctrl+V with several layers selected pastes after the last of them as seen: next in an auto layout frame's flow, else below the lowest or right of the rightmost, at the selection's own gap; Tab and Shift+Tab while editing a text layer go on to the next or previous text layer of its frame, in reading order, with all of its text selected; a file opens again on the page and at the view it was left at; the desktop app reopens the files open when it quit, in their tabs' order with the same one in front, and with nothing to reopen starts on the Home screen instead of in a new file; a dropdown, button menu or context menu in the panels that is taller than the window scrolls, so its last rows can be picked; frames, sections, components and instances move, resize and draw on whole pixels whatever Snap to pixel grid says and whatever they snap to, as Figma's help says; the pixel grid shows on a dark canvas and dark fills as well as on white, its lines one screen pixel wide in a light grey at a fifth of its strength, as measured in Figma; Shift+Cmd/Ctrl+' says at the bottom of the window whether snapping to the pixel grid is now on or off; Paste properties links the copied layer's colour, effect, grid and text styles and binds the variables it follows, and a frame's layout grids come along; links another file lacks paste as values; mind maps from the toolbar and the keyboard: Shapes ▸ Mind map places one with a click, Cmd/Ctrl+Enter adds a child and Shift+Cmd/Ctrl+Enter a sibling, Tab goes to the next sibling (#2226); a dragged layer is drawn from a sprite that moves with its outline (#2033); the Scale tool keeps variable-bound lengths scaled: a scaled instance keeps its bindings and draws them at the variable's value times its scale factor, other scaled layers keep the scaled value and drop the binding (#2090); 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 imLine truncated
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-24 · **Change:** minor (Shift with a double-click goes a level deeper and keeps the rest of the selection, so layers nested in neighbouring artboards can be selected together; M1: Frame selection makes a frame without a fill; M1: centred auto-width text keeps its middle as it grows and shrinks; M1: a drag on a section's background, or on the background of a frame in it, draws a marquee; the Layers panel's eye and padlock stay at the list's right edge, and a name takes at most 400 pt; in vector edit mode, deleting a point selects the next one on its path, so Delete pressed again goes on along it; the hover and selection outline of a curved layer bends smoothly instead of showing straight pieces; text copied while editing, or a whole text layer copied, pastes into a text edit with its formatting and its layer's colour, and Shift+Cmd/Ctrl+V (also Alt+Cmd/Ctrl+V) pastes it in the style at the caret; crop mode: the layer's sides and corners crop its image in an auto layout frame too, up to the image's edges, change a locked ratio (Shift keeps it), the image's own corners scale freely with Shift proportional as a resize does, and crop mode and vector edit mode end each other; after a click on a layer row the arrow keys nudge the selection, or move a layer in an auto layout flow one place, as in Figma; the rows take the arrows once they have the keyboard (F6); Shift+Cmd/Ctrl+V with several layers selected pastes after the last of them as seen: next in an auto layout frame's flow, else below the lowest or right of the rightmost, at the selection's own gap; Tab and Shift+Tab while editing a text layer go on to the next or previous text layer of its frame, in reading order, with all of its text selected; a file opens again on the page and at the view it was left at; the desktop app reopens the files open when it quit, in their tabs' order with the same one in front, and with nothing to reopen starts on the Home screen instead of in a new file; a dropdown, button menu or context menu in the panels that is taller than the window scrolls, so its last rows can be picked; frames, sections, components and instances move, resize and draw on whole pixels whatever Snap to pixel grid says and whatever they snap to, as Figma's help says; the pixel grid shows on a dark canvas and dark fills as well as on white, its lines one screen pixel wide in a light grey at a fifth of its strength, as measured in Figma; Shift+Cmd/Ctrl+' says at the bottom of the window whether snapping to the pixel grid is now on or off; Paste properties links the copied layer's colour, effect, grid and text styles and binds the variables it follows, and a frame's layout grids come along; links another file lacks paste as values; mind maps from the toolbar and the keyboard: Shapes ▸ Mind map places one with a click, Cmd/Ctrl+Enter adds a child and Shift+Cmd/Ctrl+Enter a sibling, Tab goes to the next sibling (#2226); a dragged layer is drawn from a sprite that moves with its outline (#2033); the Scale tool keeps variable-bound lengths scaled: a scaled instance keeps its bindings and draws them at the variable's value times its scale factor, other scaled layers keep the scaled value and drop the binding (#2090); 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 paLine 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:
|
||||
@@ -230,6 +230,7 @@ This audit records candidates for subsequent fixes; their behaviour is unchanged
|
||||
| 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-15 | patch | M1: typing in centred auto-width text kept its left edge, so the text crept to the right. It now keeps its middle, half of each width change going to each side, also when rotated, under the same conditions as right-aligned text keeps its right edge (#1477). Tests: `text_behaviour_tests` |
|
||||
| 2026-11-15 | patch | M1: Frame selection (Alt+Cmd/Ctrl+G) gave the new frame the white fill a drawn frame gets, which covered the page behind the framed layers. It now has no fill; a frame drawn with the Frame tool keeps its white fill. Test: `frames_behaviour_tests` |
|
||||
| 2026-11-18 | patch | M1: a double-click with Shift held, on a layer in another artboard than the selected one, left only that artboard's layer selected, so layers nested in neighbouring artboards couldn't be selected together. It now goes a level deeper as a double-click does and keeps the rest of the selection: the selected layer it went into, or the layer a click would select there, is replaced by the one a level below, as in Figma. Where nothing on that branch is selected it starts beside the selection, just inside the deepest layer the branch shares with a selected one, so a Shift double-click on the next row of a list adds that row's label beside the selected label instead of collapsing the selection to the list. The selection it works from is the one before the double-click's two clicks, which Shift had already toggled. Test: `shift_double_click_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`. |
|
||||
|
||||
Reference in new issue
Block a user