mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-15 23:02:36 +00:00
M8: Duplicate repeats the copy's rotation as well as its move, and forgets the step on a deselect (#2293) (#2313)
* M8: Duplicate repeats the copy's rotation as well as its move, and forgets the step on a deselect (#2293) Duplicate remembered only the shift of the copies' bounds corner, so a turned copy repeated an arbitrary offset and no rotation. The step is now the move of the copies' centre in the page frame plus the turn each copy has over its source, applied to the new copies about their own centre (one layer) or their shared centre (several). Size is not stepped; a resized copy repeats its move, not its growth. Measured in Figma's web app on 2026-11-12. The step was already dropped when the selection changes to anything but the copies (clean_selection), and a test now pins that. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Model-Effort: Opus 5.5 drove; Fable 5.2 queued; Opus 5.5 briefed; Sonnet 5.5 measured and wrote at medium * M8: the duplicate step ignores turns in place, size changes and flips (#2293) The move of the step is now measured per pair, as each copy's own centre minus its source's, less the shift a size change gives that centre (taken in the source's frame), averaged over the pairs. A turn about a layer's own centre, uneven layers and a widened-then-turned copy no longer record a move. A copy whose flip state differs from its source's repeats no turn, since flips were not measured. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Model-Effort: Opus 5.5 drove; Fable 5.2 queued; Opus 5.5 briefed; Sonnet 5.5 measured and wrote at medium * M8: a turn of several copies together is not counted as a move in the duplicate step (#2293) Duplicated::step took the mean of the per-pair centre moves, so a Rotate on several uneven layers (turned together about the selection centre) read as an extra move and the next Duplicate applied it. The step now also tries the reading where the copies were turned together about the sources' bounds centre, and uses it when every copy fits it and the in-place reading does not fit. Two tests cover a turn together and a move plus turn together. 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 * M8: the duplicate step reads a turn about the rotation handle's centre, and a resize after a turn, as no move (#2293) 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 * M8: the duplicate step turns several layers about their handle box's centre, with no pivot inferred (#2293) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Model-Effort: Opus 5.5 drove; Fable 5.2 briefed; Sonnet 5.5 wrote at medium * Docs: repair a row the earlier merges garbled (Alt-drag duplicate) 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 --------- Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bad07e4433
commit
adad8a08ad
3 files changed
+389
-12
No files matched your search
+112
-10
@@ -3,7 +3,7 @@
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
use figcraft_doc::{Document, Effect, ExportSetting, ImageData, LayoutGrid, Node, NodeId, NodeKind};
|
||||
use figcraft_geom::Affine;
|
||||
use figcraft_geom::{Affine, Point};
|
||||
use serde_json::{Map, Value, json};
|
||||
|
||||
use super::{CommandSpec, ok};
|
||||
@@ -616,7 +616,8 @@ fn delete(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
|
||||
/// Layers duplicated last (Duplicate or Alt-drag) and their copies, in the same order. While the
|
||||
/// copies are the selection, Duplicate places the next copies as far from them as they are from
|
||||
/// their sources, measured then: so moving the copies first sets the step.
|
||||
/// their sources, measured then (their move and turn, not their size): so moving or turning the
|
||||
/// copies first sets the step.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Duplicated {
|
||||
pub sources: Vec<NodeId>,
|
||||
@@ -629,9 +630,12 @@ impl Duplicated {
|
||||
!self.copies.is_empty() && set(&self.copies) == set(sel)
|
||||
}
|
||||
|
||||
/// The page offset from the sources to the copies, if both are still there and the copies move
|
||||
/// freely (an auto layout places its own).
|
||||
fn offset(&self, doc: &Document) -> Option<(f64, f64)> {
|
||||
/// The step from the sources to the copies, if both are still there and the copies move freely
|
||||
/// (an auto layout places its own): the mean move of the copies' own centres in the page frame
|
||||
/// (less what a size change shifts them by), and the turn every copy has over its source (zero
|
||||
/// unless they all agree, or when a flip differs). A turn is not counted as a move, whether each
|
||||
/// copy turned about its own centre or the copies turned together about their shared centre.
|
||||
fn step(&self, doc: &Document) -> Option<Step> {
|
||||
let free = self
|
||||
.copies
|
||||
.iter()
|
||||
@@ -639,19 +643,109 @@ impl Duplicated {
|
||||
if !free || self.sources.iter().chain(&self.copies).any(|i| !doc.contains(*i)) {
|
||||
return None;
|
||||
}
|
||||
let (a, b) = (doc.bounds_of(&self.sources)?, doc.bounds_of(&self.copies)?);
|
||||
let d = (b.x0 - a.x0, b.y0 - a.y0);
|
||||
(d.0.is_finite() && d.1.is_finite() && (d.0 != 0.0 || d.1 != 0.0)).then_some(d)
|
||||
// A flip reads as a half turn and was not measured: never repeat a turn across one.
|
||||
let flips_differ = self
|
||||
.sources
|
||||
.iter()
|
||||
.zip(&self.copies)
|
||||
.any(|(s, c)| figcraft_geom::is_flipped(doc.world_transform(*s)) != figcraft_geom::is_flipped(doc.world_transform(*c)));
|
||||
let turns: Vec<f64> = self
|
||||
.sources
|
||||
.iter()
|
||||
.zip(&self.copies)
|
||||
.map(|(s, c)| {
|
||||
let d = figcraft_geom::rotation_degrees(doc.world_transform(*c)) - figcraft_geom::rotation_degrees(doc.world_transform(*s));
|
||||
let d = d.rem_euclid(360.0);
|
||||
if d > 180.0 { d - 360.0 } else { d }
|
||||
})
|
||||
.collect();
|
||||
let angle = match turns.first() {
|
||||
Some(first) if !flips_differ && turns.iter().all(|t| (t - first).abs() < 1e-6) => *first,
|
||||
_ => 0.0,
|
||||
};
|
||||
// Per pair, where the copy's own centre is, less what its size change moved that centre by
|
||||
// (a growing edge shifts it, in the source's frame), and where the source's centre is.
|
||||
let mut pairs = Vec::new();
|
||||
for (s, c) in self.sources.iter().zip(&self.copies) {
|
||||
let (sn, cn) = (doc.node(*s)?, doc.node(*c)?);
|
||||
let (sw, cw) = (doc.world_transform(*s), doc.world_transform(*c));
|
||||
let (ps, pc) = (sw * Point::new(sn.width / 2.0, sn.height / 2.0), cw * Point::new(cn.width / 2.0, cn.height / 2.0));
|
||||
let grow = Point::new((cn.width - sn.width) / 2.0, (cn.height - sn.height) / 2.0);
|
||||
let shift_in = |x: Affine| x * grow - x * Point::ORIGIN;
|
||||
// The order of a turn and a resize isn't recorded. A resize then a turn shifts the centre
|
||||
// along the source's axes; a turn then a resize, along the copy's. Take the copy's only
|
||||
// when it alone makes this pair's own move zero: a pure resize plus turn, either order,
|
||||
// with no move must give no move. Otherwise keep the source's.
|
||||
let (by_source, by_copy) = (pc - shift_in(sw), pc - shift_in(cw));
|
||||
let still = |q: Point| (q.x - ps.x).hypot(q.y - ps.y) < 1e-6;
|
||||
let corrected = if still(by_copy) && !still(by_source) { by_copy } else { by_source };
|
||||
pairs.push((ps, corrected));
|
||||
}
|
||||
// The mean of the residuals, and whether they all agree (the copies fit that reading).
|
||||
let fit = |res: &[(f64, f64)]| {
|
||||
let n = res.len() as f64;
|
||||
let mean = (res.iter().map(|m| m.0).sum::<f64>() / n, res.iter().map(|m| m.1).sum::<f64>() / n);
|
||||
let agree = res.iter().all(|m| (m.0 - mean.0).hypot(m.1 - mean.1) < 1e-6);
|
||||
(mean, agree)
|
||||
};
|
||||
// Reading A, each copy turned about its own centre: the residual is the move of its centre.
|
||||
let each: Vec<(f64, f64)> = pairs.iter().map(|(ps, pc)| (pc.x - ps.x, pc.y - ps.y)).collect();
|
||||
let (mut mv, each_fits) = fit(&each);
|
||||
// Reading B, the copies turned together about the sources' centre (as a Rotate on several
|
||||
// layers does): the residual is what is left once each source's centre is turned that way.
|
||||
// The centre is `turn_centre`, never read from the copies: a turn about another point shifts
|
||||
// every residual by the same vector, so where the copies are can't say which point they
|
||||
// turned about. Such a turn reads as this one plus a move.
|
||||
if angle != 0.0
|
||||
&& pairs.len() > 1
|
||||
&& !each_fits
|
||||
&& let Some(c) = turn_centre(doc, &self.sources)
|
||||
{
|
||||
let together: Vec<(f64, f64)> = pairs
|
||||
.iter()
|
||||
.map(|(ps, pc)| {
|
||||
let q = figcraft_geom::translation(figcraft_geom::rotate_about(Affine::translate(ps.to_vec2()), c, angle));
|
||||
(pc.x - q.x, pc.y - q.y)
|
||||
})
|
||||
.collect();
|
||||
let (m, together_fits) = fit(&together);
|
||||
if together_fits {
|
||||
mv = m;
|
||||
}
|
||||
}
|
||||
let (dx, dy) = mv;
|
||||
let step = Step { dx, dy, angle };
|
||||
(step.dx.is_finite() && step.dy.is_finite() && step.angle.is_finite() && (dx != 0.0 || dy != 0.0 || angle != 0.0)).then_some(step)
|
||||
}
|
||||
}
|
||||
|
||||
/// What Duplicate repeats: a move of the copies' centre in the page frame, then a turn about the
|
||||
/// centre of the new copies. Size is not part of it.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
struct Step {
|
||||
dx: f64,
|
||||
dy: f64,
|
||||
angle: f64,
|
||||
}
|
||||
|
||||
/// Where several layers turn, for the step and for its repeat: the centre of their handle box
|
||||
/// (`selection_box`), the point the Rotate handle and the rotate keys turn a selection about.
|
||||
/// One layer: its own centre. Several: their bounds centre, or the centre of the box turned
|
||||
/// with them when they share a rotation. `transform.rotate` without a pivot turns about the
|
||||
/// bounds centre instead, so its turn of layers that share a rotation repeats as a turn plus
|
||||
/// a move.
|
||||
fn turn_centre(doc: &Document, ids: &[NodeId]) -> Option<Point> {
|
||||
let q = crate::tools::selection_box(doc, ids)?;
|
||||
Some(Point::new(q.iter().map(|c| c.x).sum::<f64>() / 4.0, q.iter().map(|c| c.y).sum::<f64>() / 4.0))
|
||||
}
|
||||
|
||||
fn duplicate(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let ids = req_targets("edit.duplicate", s, p)?;
|
||||
let rename = s.prefs.rename_duplicates;
|
||||
let explicit = num(p, "dx").is_some() || num(p, "dy").is_some();
|
||||
let ds = s.ds()?;
|
||||
let roots_now = z_sorted(&ds.doc, &roots(&ds.doc, &ids));
|
||||
let repeat = ds.last_duplicate.as_ref().filter(|d| !explicit && d.is_selection(&roots_now)).and_then(|d| d.offset(&ds.doc));
|
||||
let repeat = ds.last_duplicate.as_ref().filter(|d| !explicit && d.is_selection(&roots_now)).and_then(|d| d.step(&ds.doc));
|
||||
let doc = s.doc_mut()?;
|
||||
let ids = roots_now;
|
||||
let mut out = Vec::new();
|
||||
@@ -670,7 +764,7 @@ fn duplicate(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
_ => (0.0, 0.0),
|
||||
};
|
||||
match repeat {
|
||||
Some((rx, ry)) => super::arrange::move_world(doc, nid, rx, ry)?,
|
||||
Some(st) => super::arrange::move_world(doc, nid, st.dx, st.dy)?,
|
||||
None => {
|
||||
let nn = doc.get_mut(nid)?;
|
||||
nn.transform = Affine::translate((dx, dy)) * nn.transform;
|
||||
@@ -683,6 +777,14 @@ fn duplicate(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
out.push(nid);
|
||||
}
|
||||
// A repeated turn is about the new copies' centre: one layer's own, several layers' shared one.
|
||||
if let Some(st) = repeat.filter(|st| st.angle != 0.0)
|
||||
&& let Some(c) = turn_centre(doc, &out)
|
||||
{
|
||||
for nid in out.iter().copied() {
|
||||
super::arrange::rotate_world(doc, nid, c, st.angle)?;
|
||||
}
|
||||
}
|
||||
crate::library::count_inserted(doc, &out);
|
||||
// Board connectors copied with what they join join the copies.
|
||||
let map = crate::board::copy_map(doc, &ids, &out);
|
||||
|
||||
@@ -255,3 +255,277 @@ fn duplicate_repeats_a_nudged_step() {
|
||||
let c2 = cmd_d(&mut s);
|
||||
assert_eq!(at(&s, c2), (80.0, 0.0), "the nudge is the step");
|
||||
}
|
||||
|
||||
fn centre(s: &Session, id: NodeId) -> (f64, f64) {
|
||||
let c = s.doc().unwrap().world_bounds(id).unwrap().center();
|
||||
(c.x, c.y)
|
||||
}
|
||||
|
||||
fn turn(s: &Session, id: NodeId) -> f64 {
|
||||
figcraft_geom::rotation_degrees(s.doc().unwrap().world_transform(id))
|
||||
}
|
||||
|
||||
fn near(a: f64, b: f64) -> bool {
|
||||
(a - b).abs() < 1e-6
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn duplicate_repeats_the_copys_move_and_rotation() {
|
||||
let mut s = Session::new();
|
||||
let a = rect(&mut s, 0.0, 0.0);
|
||||
ex(&mut s, "select.set", json!({"ids": [a]}));
|
||||
let c1 = cmd_d(&mut s);
|
||||
ex(&mut s, "node.set", json!({"ids": [c1], "props": {"x": 150}}));
|
||||
ex(&mut s, "node.set", json!({"ids": [c1], "props": {"rotation": -15}}));
|
||||
assert!(near(centre(&s, c1).0, 200.0) && near(centre(&s, c1).1, 50.0));
|
||||
for k in 1..=3 {
|
||||
let c = cmd_d(&mut s);
|
||||
let (x, y) = centre(&s, c);
|
||||
let want = 200.0 + 150.0 * f64::from(k);
|
||||
assert!(near(x, want) && near(y, 50.0), "repeat {k}: centre ({x}, {y})");
|
||||
assert!(near(turn(&s, c), -15.0 - 15.0 * f64::from(k)), "repeat {k}: rotation {}", turn(&s, c));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn duplicate_repeats_a_rotation_in_place() {
|
||||
let mut s = Session::new();
|
||||
let a = rect(&mut s, 0.0, 0.0);
|
||||
ex(&mut s, "select.set", json!({"ids": [a]}));
|
||||
let c1 = cmd_d(&mut s);
|
||||
ex(&mut s, "node.set", json!({"ids": [c1], "props": {"rotation": 30}}));
|
||||
for k in 1..=3 {
|
||||
let c = cmd_d(&mut s);
|
||||
let (x, y) = centre(&s, c);
|
||||
assert!(near(x, 50.0) && near(y, 50.0), "repeat {k}: centre ({x}, {y})");
|
||||
assert!(near(turn(&s, c), 30.0 + 30.0 * f64::from(k)), "repeat {k}: rotation {}", turn(&s, c));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn duplicate_does_not_step_the_size() {
|
||||
let mut s = Session::new();
|
||||
let a = rect(&mut s, 0.0, 0.0);
|
||||
ex(&mut s, "select.set", json!({"ids": [a]}));
|
||||
let c1 = cmd_d(&mut s);
|
||||
ex(&mut s, "node.set", json!({"ids": [c1], "props": {"x": 150}}));
|
||||
ex(&mut s, "node.set", json!({"ids": [c1], "props": {"width": 120}}));
|
||||
let c1_centre = centre(&s, c1);
|
||||
for k in 1..=2 {
|
||||
let c = cmd_d(&mut s);
|
||||
let w = s.doc().unwrap().get(c).unwrap().width;
|
||||
assert!(near(w, 120.0), "repeat {k}: width {w}");
|
||||
assert!(near(centre(&s, c).0, c1_centre.0 + 150.0 * f64::from(k)), "repeat {k}: centre {:?}", centre(&s, c));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn duplicate_turns_several_layers_about_their_selection_centre() {
|
||||
let mut s = Session::new();
|
||||
let a = rect(&mut s, 0.0, 0.0);
|
||||
let b = rect(&mut s, 150.0, 0.0);
|
||||
ex(&mut s, "select.set", json!({"ids": [a, b]}));
|
||||
let out = ex(&mut s, "edit.duplicate", json!({}));
|
||||
let copies: Vec<NodeId> = out["ids"].as_array().unwrap().iter().map(|v| id_of(v).unwrap()).collect();
|
||||
ex(&mut s, "transform.nudge", json!({"dx": 150, "dy": 0}));
|
||||
// Turn the pair -15 about its combined centre.
|
||||
ex(&mut s, "transform.rotate", json!({"ids": copies, "degrees": -15}));
|
||||
let before: Vec<(f64, f64)> = copies.iter().map(|c| centre(&s, *c)).collect();
|
||||
let pair_before = s.doc().unwrap().bounds_of(&copies).unwrap().center();
|
||||
let again = ex(&mut s, "edit.duplicate", json!({}));
|
||||
let next: Vec<NodeId> = again["ids"].as_array().unwrap().iter().map(|v| id_of(v).unwrap()).collect();
|
||||
assert_eq!(next.len(), 2);
|
||||
let after = s.doc().unwrap().bounds_of(&next).unwrap().center();
|
||||
assert!(near(after.x, pair_before.x + 150.0) && near(after.y, pair_before.y), "pair centre {after:?}");
|
||||
for (i, c) in next.iter().enumerate() {
|
||||
assert!(near(turn(&s, *c), -30.0), "layer {i}: rotation {}", turn(&s, *c));
|
||||
// Expected: the layer's centre moved +150, then turned -15 about the moved pair's centre.
|
||||
let moved = figcraft_geom::Affine::translate((before[i].0 + 150.0, before[i].1));
|
||||
let want = figcraft_geom::translation(figcraft_geom::rotate_about(moved, after, -15.0));
|
||||
let got = centre(&s, *c);
|
||||
assert!(near(got.0, want.x) && near(got.1, want.y), "layer {i}: {got:?} vs {want:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_deselect_forgets_the_duplicate_step() {
|
||||
let mut s = Session::new();
|
||||
let a = rect(&mut s, 0.0, 0.0);
|
||||
ex(&mut s, "select.set", json!({"ids": [a]}));
|
||||
let c1 = cmd_d(&mut s);
|
||||
ex(&mut s, "node.set", json!({"ids": [c1], "props": {"x": 150}}));
|
||||
ex(&mut s, "select.none", json!({}));
|
||||
ex(&mut s, "select.set", json!({"ids": [c1]}));
|
||||
let c2 = cmd_d(&mut s);
|
||||
assert_eq!(at(&s, c2), (150.0, 0.0), "no step after a deselect: the copy lands in place");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn several_uneven_layers_turned_in_place_repeat_the_turn_without_a_move() {
|
||||
let mut s = Session::new();
|
||||
let wide = id_of(&ex(&mut s, "shape.rectangle", json!({"x": 200, "y": 0, "width": 300, "height": 100}))["id"]).unwrap();
|
||||
let ids = [rect(&mut s, 0.0, 200.0), wide];
|
||||
ex(&mut s, "select.set", json!({"ids": ids}));
|
||||
let out = ex(&mut s, "edit.duplicate", json!({}));
|
||||
let copies: Vec<NodeId> = out["ids"].as_array().unwrap().iter().map(|v| id_of(v).unwrap()).collect();
|
||||
for c in &copies {
|
||||
ex(&mut s, "node.set", json!({"ids": [*c], "props": {"rotation": -45}}));
|
||||
}
|
||||
let pivot = handle_box_centre(&s, &copies);
|
||||
let before: Vec<(f64, f64)> = copies.iter().map(|c| centre(&s, *c)).collect();
|
||||
let again = ex(&mut s, "edit.duplicate", json!({}));
|
||||
let next: Vec<NodeId> = again["ids"].as_array().unwrap().iter().map(|v| id_of(v).unwrap()).collect();
|
||||
for (i, c) in next.iter().enumerate() {
|
||||
assert!(near(turn(&s, *c), -90.0), "layer {i}: rotation {}", turn(&s, *c));
|
||||
// No move: each layer's centre only turned -45 about the copies' shared centre.
|
||||
let want =
|
||||
figcraft_geom::translation(figcraft_geom::rotate_about(figcraft_geom::Affine::translate((before[i].0, before[i].1)), pivot, -45.0));
|
||||
let got = centre(&s, *c);
|
||||
assert!(near(got.0, want.x) && near(got.1, want.y), "layer {i}: {got:?} vs {want:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// The uneven pair the collective-turn tests share: a square and a wide one, selected and duplicated.
|
||||
fn uneven_pair_and_copies(s: &mut Session) -> Vec<NodeId> {
|
||||
let wide = id_of(&ex(s, "shape.rectangle", json!({"x": 200, "y": 0, "width": 300, "height": 100}))["id"]).unwrap();
|
||||
let ids = [rect(s, 0.0, 200.0), wide];
|
||||
ex(s, "select.set", json!({"ids": ids}));
|
||||
let out = ex(s, "edit.duplicate", json!({}));
|
||||
out["ids"].as_array().unwrap().iter().map(|v| id_of(v).unwrap()).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn several_uneven_layers_turned_together_repeat_the_turn_without_a_move() {
|
||||
let mut s = Session::new();
|
||||
let copies = uneven_pair_and_copies(&mut s);
|
||||
ex(&mut s, "transform.rotate", json!({"ids": copies, "degrees": 90}));
|
||||
let pivot = s.doc().unwrap().bounds_of(&copies).unwrap().center();
|
||||
let before: Vec<(f64, f64)> = copies.iter().map(|c| centre(&s, *c)).collect();
|
||||
let again = ex(&mut s, "edit.duplicate", json!({}));
|
||||
let next: Vec<NodeId> = again["ids"].as_array().unwrap().iter().map(|v| id_of(v).unwrap()).collect();
|
||||
assert_eq!(next.len(), 2);
|
||||
for (i, c) in next.iter().enumerate() {
|
||||
assert!(near(turn(&s, *c).abs(), 180.0), "layer {i}: rotation {}", turn(&s, *c));
|
||||
let want = figcraft_geom::translation(figcraft_geom::rotate_about(figcraft_geom::Affine::translate((before[i].0, before[i].1)), pivot, 90.0));
|
||||
let got = centre(&s, *c);
|
||||
assert!(near(got.0, want.x) && near(got.1, want.y), "layer {i}: {got:?} vs {want:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn several_uneven_layers_moved_and_turned_together_repeat_both() {
|
||||
let mut s = Session::new();
|
||||
let copies = uneven_pair_and_copies(&mut s);
|
||||
ex(&mut s, "transform.nudge", json!({"dx": 150, "dy": 0}));
|
||||
ex(&mut s, "transform.rotate", json!({"ids": copies, "degrees": -15}));
|
||||
let pivot = handle_box_centre(&s, &copies);
|
||||
let before: Vec<(f64, f64)> = copies.iter().map(|c| centre(&s, *c)).collect();
|
||||
let again = ex(&mut s, "edit.duplicate", json!({}));
|
||||
let next: Vec<NodeId> = again["ids"].as_array().unwrap().iter().map(|v| id_of(v).unwrap()).collect();
|
||||
assert_eq!(next.len(), 2);
|
||||
let moved_pivot = figcraft_geom::Point::new(pivot.x + 150.0, pivot.y);
|
||||
for (i, c) in next.iter().enumerate() {
|
||||
assert!(near(turn(&s, *c), -30.0), "layer {i}: rotation {}", turn(&s, *c));
|
||||
let moved = figcraft_geom::Affine::translate((before[i].0 + 150.0, before[i].1));
|
||||
let want = figcraft_geom::translation(figcraft_geom::rotate_about(moved, moved_pivot, -15.0));
|
||||
let got = centre(&s, *c);
|
||||
assert!(near(got.0, want.x) && near(got.1, want.y), "layer {i}: {got:?} vs {want:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_widened_copy_turned_in_place_repeats_the_turn_without_a_move() {
|
||||
let mut s = Session::new();
|
||||
let a = rect(&mut s, 0.0, 0.0);
|
||||
ex(&mut s, "select.set", json!({"ids": [a]}));
|
||||
let c1 = cmd_d(&mut s);
|
||||
ex(&mut s, "node.set", json!({"ids": [c1], "props": {"width": 120}}));
|
||||
ex(&mut s, "node.set", json!({"ids": [c1], "props": {"rotation": -90}}));
|
||||
let c1_centre = centre(&s, c1);
|
||||
let c2 = cmd_d(&mut s);
|
||||
let got = centre(&s, c2);
|
||||
assert!(near(got.0, c1_centre.0) && near(got.1, c1_centre.1), "centre {got:?} vs {c1_centre:?}");
|
||||
assert!(near(turn(&s, c2).abs(), 180.0), "rotation {}", turn(&s, c2));
|
||||
assert!(near(s.doc().unwrap().get(c2).unwrap().width, 120.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_copy_turned_then_widened_repeats_the_turn_without_a_move() {
|
||||
let mut s = Session::new();
|
||||
let a = rect(&mut s, 0.0, 0.0);
|
||||
ex(&mut s, "select.set", json!({"ids": [a]}));
|
||||
let c1 = cmd_d(&mut s);
|
||||
ex(&mut s, "node.set", json!({"ids": [c1], "props": {"rotation": -90}}));
|
||||
ex(&mut s, "node.set", json!({"ids": [c1], "props": {"width": 120}}));
|
||||
let c1_centre = centre(&s, c1);
|
||||
let c2 = cmd_d(&mut s);
|
||||
let got = centre(&s, c2);
|
||||
assert!(near(got.0, c1_centre.0) && near(got.1, c1_centre.1), "centre {got:?} vs {c1_centre:?}");
|
||||
assert!(near(turn(&s, c2).abs(), 180.0), "rotation {}", turn(&s, c2));
|
||||
assert!(near(s.doc().unwrap().get(c2).unwrap().width, 120.0));
|
||||
}
|
||||
|
||||
/// The centre of the selection's handle box, which is what the Rotate handle turns about.
|
||||
fn handle_box_centre(s: &Session, ids: &[NodeId]) -> figcraft_geom::Point {
|
||||
let q = crate::tools::selection_box(s.doc().unwrap(), ids).unwrap();
|
||||
figcraft_geom::Point::new(q.iter().map(|c| c.x).sum::<f64>() / 4.0, q.iter().map(|c| c.y).sum::<f64>() / 4.0)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_turned_pair_turned_again_about_its_handle_box_repeats_without_a_move() {
|
||||
let mut s = Session::new();
|
||||
let wide = id_of(&ex(&mut s, "shape.rectangle", json!({"x": 200, "y": 0, "width": 300, "height": 100}))["id"]).unwrap();
|
||||
let ids = [rect(&mut s, 0.0, 200.0), wide];
|
||||
ex(&mut s, "transform.rotate", json!({"ids": ids, "degrees": 60}));
|
||||
ex(&mut s, "select.set", json!({"ids": ids}));
|
||||
let out = ex(&mut s, "edit.duplicate", json!({}));
|
||||
let copies: Vec<NodeId> = out["ids"].as_array().unwrap().iter().map(|v| id_of(v).unwrap()).collect();
|
||||
let p = handle_box_centre(&s, &copies);
|
||||
ex(&mut s, "transform.rotate", json!({"ids": copies, "degrees": 30, "cx": p.x, "cy": p.y}));
|
||||
let before: Vec<(f64, f64)> = copies.iter().map(|c| centre(&s, *c)).collect();
|
||||
let again = ex(&mut s, "edit.duplicate", json!({}));
|
||||
let next: Vec<NodeId> = again["ids"].as_array().unwrap().iter().map(|v| id_of(v).unwrap()).collect();
|
||||
assert_eq!(next.len(), 2);
|
||||
let pivot = handle_box_centre(&s, &next);
|
||||
for (i, c) in next.iter().enumerate() {
|
||||
assert!(near(turn(&s, *c), 120.0), "layer {i}: rotation {}", turn(&s, *c));
|
||||
let want = figcraft_geom::translation(figcraft_geom::rotate_about(figcraft_geom::Affine::translate((before[i].0, before[i].1)), pivot, 30.0));
|
||||
let got = centre(&s, *c);
|
||||
assert!(near(got.0, want.x) && near(got.1, want.y), "layer {i}: {got:?} vs {want:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn several_uneven_layers_turned_together_repeat_about_one_centre_each_time() {
|
||||
let mut s = Session::new();
|
||||
let mut copies = uneven_pair_and_copies(&mut s);
|
||||
// Upright, the pair's handle box is its bounds: both centres are (250, 150), so this is also
|
||||
// the Rotate handle's turn. Turned, the box keeps that centre; the bounds don't.
|
||||
ex(&mut s, "transform.rotate", json!({"ids": copies, "degrees": 30}));
|
||||
let pivot = figcraft_geom::Point::new(250.0, 150.0);
|
||||
for k in 1..=3 {
|
||||
let before: Vec<(f64, f64)> = copies.iter().map(|c| centre(&s, *c)).collect();
|
||||
let again = ex(&mut s, "edit.duplicate", json!({}));
|
||||
let next: Vec<NodeId> = again["ids"].as_array().unwrap().iter().map(|v| id_of(v).unwrap()).collect();
|
||||
assert_eq!(next.len(), 2);
|
||||
for (i, c) in next.iter().enumerate() {
|
||||
assert!(near(turn(&s, *c), 30.0 + 30.0 * f64::from(k)), "repeat {k}, layer {i}: rotation {}", turn(&s, *c));
|
||||
let want =
|
||||
figcraft_geom::translation(figcraft_geom::rotate_about(figcraft_geom::Affine::translate((before[i].0, before[i].1)), pivot, 30.0));
|
||||
let got = centre(&s, *c);
|
||||
assert!(near(got.0, want.x) && near(got.1, want.y), "repeat {k}, layer {i}: {got:?} vs {want:?}");
|
||||
}
|
||||
copies = next;
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_flipped_copy_does_not_repeat_a_half_turn() {
|
||||
let mut s = Session::new();
|
||||
let a = rect(&mut s, 0.0, 0.0);
|
||||
ex(&mut s, "select.set", json!({"ids": [a]}));
|
||||
let c1 = cmd_d(&mut s);
|
||||
ex(&mut s, "object.flipH", json!({"ids": [c1]}));
|
||||
let c2 = cmd_d(&mut s);
|
||||
assert!(near(turn(&s, c2), turn(&s, c1)), "rotation {} vs {}", turn(&s, c2), turn(&s, c1));
|
||||
}
|
||||
+3
-2
@@ -1,6 +1,6 @@
|
||||
# UI and interaction parity
|
||||
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-10 · **Change:** minor (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's web app, 2026-11-09; `pressing_k_focuses_the_scale_field_with_its_text_selected`, `k_two_enter_scales_the_selection_by_two`, `escape_in_the_scale_field_closes_it_and_changes_nothing`); the main menu and its submenus stay inside the window, moving up to fit and scrolling when taller (#2217); locked layers ignore the arrow keys and a locked parent's children can't be locked on their own (#1560); the left rail's and tab strip's icons are larger, 20 pt (#553); pick select: Tab while the keyboard selection box shows (or the chord again) puts a pink outline on a layer and the keys walk the layer tree from it, as Accessibility at Figma says (#1836); scrubbing a fielLine truncated
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-12 · **Change:** minor (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's web app, 2026-11-09; `pressing_k_focuses_the_scale_field_with_its_text_selected`, `k_two_enter_scales_the_selection_by_two`, `escape_in_the_scale_field_closes_it_and_changes_nothing`); the main menu and its submenus stay inside the window, moving up to fit and scrolling when taller (#2217); locked layers ignore the arrow keys and a locked parent's children can't be locked on their own (#1560); the left rail's and tab strLine 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:
|
||||
@@ -71,7 +71,7 @@ interaction feel only partly compared: the interactions measured so far, case by
|
||||
| Rotation origin (Alt+R) | done | a handle at the selection's centre to drag (snaps to the box's corners, edge middles and centre), double-click puts it back, Escape or Alt+R hides it; the corner handles, the rotation field, Rotate 90°/180° and `transform.rotate` turn about it; it follows the layers and lasts as long as the selection, not saved (the documentation doesn't say; pinned) |
|
||||
| Align and Distribute (Design panel and shortcuts) | done | single and multi-layer Align and Distribute were measured in Figma's web app on 2026-11-12 and match: one layer aligns to its frame, several to their combined bounds, Distribute spaces three or more. Align is disabled for a child in an auto layout frame's flow (Alt+A and Alt+S do nothing, the frame is untouched), as measured; the panel's tip says the frame places the layer, and an absolutely positioned child still aligns to its frame (not measured, so today's behaviour is kept). Tidy up was measured to differ (Figma keeps the order and sizes and evens one gap per axis): not yet. Tests: `align_is_unavailable_for_a_child_in_an_auto_layout_flow`, `an_absolute_child_of_an_auto_layout_frame_still_aligns_to_it`, `the_align_buttons_are_off_for_a_layer_in_an_auto_layout_flow` |
|
||||
| Enter with a shape or frame tool chosen | done | places what a click makes (100×100, lines 100 long, sections 400×300) in the middle of the view, selected (`tool.place`); from the toolbar, Enter on the chosen tool. With nothing selected, the arrows first show a crosshair in the middle of the view and then move it by the nudge amounts (`tool.crosshair`; Shift the large one), and Enter places there; Escape or a tool change takes it away ("Use the arrow keys to activate the crosshair cursor. It will appear in the middle of the viewport indicating where the new object will be placed", Accessibility at Figma; #1839) |
|
||||
| Alt-drag duplicate | done | the copy snaps to the layer it came from too (edges, centres, equal spacing); Duplicate (Cmd+D) then repeats the copy's offset, also after a Duplicate whose copy was moved, as long as the copies stay selected (the documentation doesn't say; pinned from community answers); Alt going down or up mid-drag turns the move into a copy or back to the original, with Shift a copy kept to one axis (`alt_pressed_during_a_drag_turns_the_move_into_a_copy`, `alt_shift_drag_on_a_selected_layer_duplicates_it`; measured in Figma's web app, 2026-11-08) |
|
||||
| Alt-drag duplicate | done | the copy snaps to the layer it came from too (edges, centres, equal spacing); Duplicate (Cmd+D) then repeats the copy's move and rotation (the move of its centre in the page frame, then the turn about the copy's own centre, or the selection's centre for several layers; not its size), also after a Duplicate whose copy was moved, as long as the copies stay selected and the selection hasn't changed (measured in Figma's web app, 2026-11-12); Alt going down or up mid-drag turns the move into a copy or back to the original, with Shift a copy kept to one axis (`alt_pressed_during_a_drag_turns_the_move_into_a_copy`, `alt_shift_drag_on_a_selected_layer_duplicates_it`; measured in Figma's web app, 2026-11-08) |
|
||||
| Drag threshold; double-click into groups and text | done | a press moves or resizes only once the pointer has travelled 3 px on screen, so a click or double-click made with an unsteady hand drags nothing; a double-click goes one level into a group and the next one edits the text under it, wherever on the text it lands, with all of it selected (a double-click in the text being edited selects the word) (`double_click_tests`); Enter on a selected text does the same (all of it selected, typing replaces it) and Escape leaves editing with the layer still selected (`text_enter_tests`) |
|
||||
| Scale tool (K): handles about the opposite handle, live factor, panel | done | Dragging a handle ignores the origin grid and pivots on the opposite handle's point (the opposite corner, or the opposite edge's middle for an edge, which scales both ways), with Alt on the centre; the origin grid (`tool.scaleAnchor`) starts at the centre and sets only what the Scale field and the W and H fields keep fixed (W and H with a non-centre origin are unmeasured). Measured in Figma's web app, 2026-11-09. Tests: `a_scale_handle_drag_pivots_on_the_opposite_handle_whatever_the_origin`, `the_scale_origin_starts_at_the_centre`. Pressing K opens the Scale section with its factor field focused and its text selected; typing 2 (or 2x, 1.5) then Enter scales the selection by it about the panel's origin, which starts at the centre, as one undo step, then closes the section and returns to Move with the selection kept; Escape in the field closes it, back to Move, nothing changed. Measured in Figma's web app, 2026-11-09. Tests: `pressing_k_focuses_the_scale_field_with_its_text_selected`, `k_two_enter_scales_the_selection_by_two`, `escape_in_the_scale_field_closes_it_and_changes_nothing`. |
|
||||
| Nudge 1 / Shift 10 (preference), Cmd+arrows resize | done | arrows reorder auto layout children |
|
||||
@@ -341,3 +341,4 @@ This audit records candidates for subsequent fixes; their behaviour is unchanged
|
||||
| 2026-11-12 | patch | M8: Scale tool handle drags pivot on the opposite handle whatever the origin, and the origin starts at the centre, so K, 2, Enter scales about the centre (measured in Figma's web app, 2026-11-09; `a_scale_handle_drag_pivots_on_the_opposite_handle_whatever_the_origin`, `the_scale_origin_starts_at_the_centre`) |
|
||||
| 2026-11-12 | minor | M8: a selected polygon or star has a Count handle on the canvas (hover label Count N), measured in Figma's web app on 2026-11-12: it sits on the first vertex clockwise from the top (a star's first outer point, not inset), and a drag sets the count to round(360 / the pointer's clockwise angle from the top point about the centre), so 90 degrees gives 4, 72 gives 5 and 45 gives 8, with the step shrinking as the count grows; one drag is one undo step. The count is clamped to 3 to 60 (the help center's range for a star; a polygon's maximum was not read). Tests: `a_polygon_has_a_count_handle_on_its_first_vertex_clockwise_from_the_top`, `dragging_the_count_handle_sets_the_count_by_the_angle_about_the_centre`, `a_count_drag_is_one_undo_step` |
|
||||
| 2026-10-10 | major | Created from the ROADMAP's look-and-feel and interaction items, the keymap and the canvas code |
|
||||
| 2026-11-12 | minor | M8, #2293: Duplicate repeats the last copy's move and rotation, not only the shift of its bounds' corner. The step is the move of the copies' centre in the page frame (not turned by the accumulated rotation) plus the turn each copy has over its source, applied about the new copy's centre, or the selection's centre for several layers; size is not stepped; a deselect forgets the step. Measured in Figma's web app on 2026-11-12 (typed and dragged moves and turns, one layer and two). |
|
||||
Reference in new issue
Block a user