Merge pull request #2829 from storytold/fix/1560-right-click-locked

M5: a right-click on a locked layer picks it, so the menu's Lock/Unlock unlocks it
This commit is contained in:
BFlat
2026-12-01 14:37:53 +07:00
committed by GitHub
5 changed files with 47 additions and 3 deletions
+6 -1
View File
@@ -65,7 +65,12 @@ impl Session {
/// `deep`: it reaches through a nested frame, component or instance where that has no
/// visible fill (see [`figcraft_doc::geometry::HitOpts::deep`]).
pub fn hit_pick(&self, doc: &Document, page: NodeId, p: Point, tol: f64, deep: bool) -> Option<NodeId> {
let opts = figcraft_doc::geometry::HitOpts { deep, ..Default::default() };
self.hit_pick_opts(doc, page, p, tol, figcraft_doc::geometry::HitOpts { deep, ..Default::default() })
}
/// [`Session::hit_pick`] with `opts`: a right-click reaches locked layers too, so its menu can
/// unlock the one under the pointer.
pub fn hit_pick_opts(&self, doc: &Document, page: NodeId, p: Point, tol: f64, opts: figcraft_doc::geometry::HitOpts) -> Option<NodeId> {
let sel = self.selection();
let result = crate::booleans::result_outline(doc, &sel);
let image = |paint: &figcraft_color::ImagePaint, n: &figcraft_doc::Node, lp: Point| crate::canvas::image_hit::coverage(doc, paint, n, lp);
+3 -1
View File
@@ -480,7 +480,9 @@ pub fn open_context_menu(app: &mut FigApp, pos: Pos2, deep: bool) {
let (doc, page, sel, zoom) = (ds.doc.clone(), ds.page, ds.selection.clone(), ds.view.zoom.max(1e-6));
// A frame's name label is the frame, as on a press, even where it sits over a section.
let label = figcraft_engine::tools::label_at(&doc, page, &app.session.tool.labels, p);
let hit = app.session.hit_pick(&doc, page, p, 2.0 / zoom, deep);
// A locked layer is picked too: the menu's Lock/Unlock then unlocks it.
let opts = figcraft_doc::geometry::HitOpts { deep, locked: true };
let hit = app.session.hit_pick_opts(&doc, page, p, 2.0 / zoom, opts);
let target = label.or_else(|| hit.map(|leaf| figcraft_doc::geometry::select_target(&doc, leaf, &sel, deep)));
if let Some(target) = target
&& !sel.contains(&target)
@@ -0,0 +1,34 @@
//! A right-click on a locked layer picks it (#1560), so the menu's Lock/Unlock unlocks the layer
//! under the pointer, where a left click passes through it.
use figcraft_engine::Session;
use serde_json::json;
use crate::layers_drag_tests::Ui;
use crate::present_tests::id;
#[test]
fn a_right_click_on_a_locked_layer_picks_it_and_the_menu_unlocks_it() {
let mut s = Session::new();
let lower = id(&s.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 80, "height": 80})).unwrap());
let upper = id(&s.execute("shape.rectangle", &json!({"x": 120, "y": 120, "width": 80, "height": 80})).unwrap());
s.execute("object.toggleLock", &json!({"ids": [upper], "locked": true})).unwrap();
s.set_selection(vec![lower]);
let mut u = Ui::new(s);
u.frame(vec![]);
let locked = |u: &Ui| u.app.session.doc().unwrap().node(upper).unwrap().locked;
// Where only the locked layer is, and where it covers the other one.
for (x, y) in [(190.0, 190.0), (150.0, 150.0)] {
u.app.session.set_selection(vec![lower]);
let at = u.app.to_screen(x, y);
crate::canvas::open_context_menu(&mut u.app, at, false);
assert_eq!(u.app.session.selection(), vec![upper], "at {x},{y}: the locked layer is picked");
assert_eq!(u.app.ui.context_menu.as_ref().map(|m| m.1.clone()), Some(vec![upper]), "the menu acts on it");
}
crate::menus::invoke(&mut u.app, "object.toggleLock");
assert!(!locked(&u), "Lock/Unlock unlocked the layer under the pointer");
// Empty canvas still opens the canvas's menu, leaving the selection alone.
let at = u.app.to_screen(600.0, 600.0);
crate::canvas::open_context_menu(&mut u.app, at, false);
assert_eq!(u.app.session.selection(), vec![upper]);
}
+2
View File
@@ -109,6 +109,8 @@ mod component_swap_default_tests;
#[cfg(test)]
mod component_swap_search_tests;
#[cfg(test)]
mod context_menu_locked_tests;
#[cfg(test)]
mod context_menu_tests;
#[cfg(test)]
mod corner_individual_tests;
+2 -1
View File
@@ -81,7 +81,7 @@ interaction feel only partly compared: the interactions measured so far, case by
| Pixel grid snapping, pixel preview, 2x preview | done | moves, resizes and new shapes land on whole pixels; frames, sections and components always do, also with snapping off or next to a layer off the grid, as the help says (`frames_land_on_whole_pixels_whatever_they_snap_to`); the pixel grid shows from 400% (`view_behaviour_tests`) |
| Numeric fields: arithmetic, scrubbing by dragging the label (or the field itself with Alt held), mixed values | done | Numeric panels use `widgets::number_field`; Corner smoothing has an original code-drawn icon, a 24 pt drag target and an accessible name, with live changes, fractional values preserved across consecutive drags, Shift/Alt rates, 0–100% clamping and one-step undo/redo (`corner_individual_tests`); Typography line height, letter spacing and paragraph spacing share its leading-icon scrub logic (#373), retaining their existing unit parsing, Auto/Mixed values, variable chips and selected-character targeting (`typography_scrub_tests`). Scrubbing the label: half a step a point (0.5 px; 0.5% of opacity, 0.5° of rotation), as measured in Figma on 2026-11-08 (a 12.2 px drag moved X by 6, a 61.2 px drag by 31; rotation by 6° and opacity by 5% for 12.2 px), ten times that with Shift (5 steps a point) and a tenth of that with Alt (0.05 steps a point; neither measured), each stretch at the rate held while it was dragged, one undo step when let go; past the edge of the screen it goes on where the platform reports the mouse's own motion (desktop), otherwise it stops there. Arrow keys: Up/Down step a pixel field by the small nudge and Shift by the big nudge (the preferences), other fields by their own step and ten of it; they work while typing (from what is typed) and with the keyboard on the field. Typing: `+ - * /`, brackets, units (`px`, `°`, `%`, `x`, `ms`), a decimal comma; `+10`, `*2`, `/4` are relative to the value, and `50%`, `+10%`, `-10%` too in a field that isn't a percentage. Enter, Tab or a click elsewhere commits (Tab and Shift+Tab move to the next and previous control), Escape restores; a field left as it was commits nothing (no undo step, and a rounded display isn't written back). Mixed values show "Mixed": a number sets them all, a relative edit or an arrow key goes to each layer from its own value in one undo step, for X, Y, W, H, rotation, opacity, corner radius and stroke weight (elsewhere `+10` on Mixed sets 10 and `*2` does nothing) (`field_tests`). Left: scrubbing a Mixed field (nothing happens), `x2`-style suffix edits, the pointer isn't wrapped to the other side of the screen; the Shift and Alt rates and the speed by height are not compared with Figma's, and the rotation scrub's direction is not confirmed; while scrubbing, the pointer's height sets the speed (more than 100 points above where the scrub began: 2x; that far below: 1/2; twice as far: 1/4), a toast names the speed when it changes, and Shift and Alt multiply as before ("Change the speed that you scrub the field by moving the cursor towards the top of the screen to increase the scrubbing speed, or towards the bottom of the screen to reduce it", Scrub fields; #1837). While a field is scrubbed, the canvas hides the selection's frame, handles and size label (and a text's coloured selection), so the value being changed shows on the layer, and brings them back when it is let go (#1319, `colorpicker_selection_tests::scrubbing_a_field_hides_the_selections_frame_until_let_go`). FigCraft's own, off by default (Preferences ▸ Scroll wheel changes number fields, `pref.wheelStepsFields`, #286): the scroll wheel over the field that has the keyboard steps it as the arrow keys do (Shift: the big step; a trackpad every 24 points), and the panel under it doesn't scroll meanwhile; a field without the keyboard never takes the wheel (`field_wheel_tests`) |
| Transform box at small sizes | done | a press inside a layer smaller than its handles moves it, the nearest handle wins, handles answer just outside and are hidden under 16 px on screen; cursors follow each handle and the box's rotation |
| Locked layers | done | selectable from the layers panel; no handles, not dragged with the rest of a selection |
| Locked layers | done | selectable from the layers panel; no handles, not dragged with the rest of a selection; a left click, hover or marquee passes through them, a right-click picks the one under the pointer so the menu's Lock/Unlock unlocks it (#1560) |
| Edit ▸ Set default properties: new layers take the selected layer's properties | done | from a shape (any layer but text): new rectangles, ellipses, polygons and stars drawn or clicked with their tools take its fills, strokes and their settings, effects, opacity, blend and corners; from a text layer: new text from the Text tool takes its fills and font (#2028). Silent in the help center on frames, lines and arrows: they keep their own look, as do layers made by commands; the defaults last for the session |
| Smart selection spacing | partial | with layers in a row, a column or an aligned grid selected, the Layout section shows horizontal and vertical spacing ("Mixed" until set; typed, scrubbed, fractional and negative) and pink handles in the gaps on the canvas drag them, one undo step, Escape cancels (`arrange.spacing`; sizes, parents and offsets within each track kept; at most 2,000 layers; flow children, locked layers and layers inside instances left out). A ring at each layer's centre drags it to another place in a regular row, column or complete top-left-aligned grid: the others close up and make room around it with the gaps kept, and with Cmd/Ctrl held the two layers swap places instead, previewed live while dragging (`selection_reorder_tests`; no ring on a layer under 16 px on screen). Not covered: reordering irregular grids, and several marked layers moved together. Checked by its author on macOS and in the app on Windows (#402) |
| Tidy up | partial | measured in Figma's web app on 2026-11-12 (a row, a column, a 2 x 3 grid of unequal sizes and its transpose, and many runs on the gap, the unavailable cases among them): the order and the sizes are kept; in a row or a column the first layer also stays and the other axis is untouched (a grid can move a layer on both axes, as below). A row (one group of layers whose Y ranges overlap, side by side) evens its horizontal gaps and a column its vertical gaps to one gap: the most common existing gap (the smaller of two equally common ones), else the mean rounded to a whole number, half up (30, 40, 30 gives 30; 80, 20, 45 gives 48; 10, 10, 50, 90 gives 10; 10, 25 gives 18; 10, 25, 30 gives 22). Layers of a row may overlap along X, and overlapping layers in a chain count as a row (the first and third needn't touch): the negative gap counts in the mean (50 px squares at X 0, 60, 105, 170, gaps 10, -5, 15, give X 0, 57, 114, 171; squares at X 0, 40, 80, 150 give 0, 40, 80, 120). Measured in Figma's web app on 2026-11-13: a negative gap is raised so no layer reaches the one two places before it, floor(-w / 2) + 1 for the narrowest interior layer's width w, so 10, 20 and 30 wide interior layers among 100s give -4, -9 and -14 (X 0, 96, 102, 198, 294, 390 for widths 100, 10, 100 x4), while six layers 100 wide keep the most common gap, -40; only those widths were measured, and an explicit `spacing` is not raised. A grid (two or more rows and columns, one layer in every cell) is packed along the axis with more groups: a column is as wide as its widest layer around the middle of where its layers were, the first column stays, each layer is centred in its column to a whole pixel with Snap to pixel grid on, and every column is stacked from the selection's top; a grid with more rows than columns is the mirror image (centred rows, laid out left to right). The vertical gap reads 51 or 52 in Figma's own runs (mean 51.67), so FigCraft's positions along a stack can differ by a pixel there. Unavailable, as measured, for fewer than three layers, for layers that all overlap each other (one row and one column), for a diagonal and for an irregular layout: a greyed-out row with a tip in the Design panel's menu, the command moving nothing and adding no undo step. Not measured, FigCraft's choices: a 2 x 2 grid packed as columns; layers in an auto layout flow being unavailable (the frame places them; the measurement could not tell this from an irregular layout); the 2,000 layer cap; rotated layers counting by their box; gaps a pixel apart being different gaps; an explicit `spacing` setting the gap and taking two layers; no rounding with Snap to pixel grid off. Tests: tidy_tests |
@@ -227,6 +227,7 @@ This audit records candidates for subsequent fixes; their behaviour is unchanged
|---|---|---|
| 2026-12-01 | minor | M3, #1749: Draw mode in the toolbar's mode switcher only chose the Pencil, and lit up whenever the Pencil was the tool; the drawing tools stayed behind one flyout. Draw mode is now a mode of the toolbar (`UiState::draw_mode`): the Pen and the Pencil get a button each right after Move, one click apart, and picking the Pen keeps Draw mode; Design, Prototype or Inspect leaves it, and the Pencil chosen from Design's flyout or by its key no longer switches the mode. The reference draws its drawing tools as large standing pictures; ours keep the toolbar's own icons. Tests: `draw_mode_toolbar_tests`. |
| 2026-12-01 | patch | #649: emoji in layer names, comments and other UI text drew as plain monochrome glyphs; on desktop they now draw in colour from the system's emoji face, loaded once something shows emoji |
| 2026-12-01 | patch | M5, #1560: a right-click on a locked layer opened the menu for whatever was selected (or the layer under the locked one), because the pick skipped locked layers, so unlocking one from the canvas meant finding it in the Layers panel. The right-click now reaches locked layers (`Session::hit_pick_opts` with `HitOpts::locked`) and selects the one under the pointer, and the menu's Lock/Unlock unlocks it; a left click, hover and marquee still pass through locked layers. Tests: `context_menu_locked_tests`. |
| 2026-12-01 | patch | M3, #2295: a layer's link (Copy link to selection, Cmd/Ctrl+L, or Copy link to page: `figcraft://node/<id>`) was only an MCP resource address; a command given it as a layer id refused it. Every command, the control channel and MCP now take the link wherever they take a layer id, so a link the user copies can be pasted to an agent as it is. Tests: `node_link_tests` |
| 2026-12-01 | minor | #2036: commands' keys can be changed in the Keyboard shortcuts panel (record a key, a question before taking another command's key, reset one or all; a search lists commands with no key so they can get one) and by `pref.shortcut` / `pref.shortcutsReset`; the keymap answers with them everywhere and the preferences keep them. Tests: `custom_keys_tests`, `shortcut_rebind_tests` |
| 2026-12-01 | patch | #286: an opt-in preference (Scroll wheel changes number fields, `pref.wheelStepsFields`, off by default) lets the scroll wheel over the focused number field step it as the arrow keys do, Shift the big step. Test: `field_wheel_tests` |