Merge pull request #1074 from dotCooCoo/feat/align-compound-key-stays
Align: a compound path or selected group that contains the key object stays in place
This commit is contained in:
commit
231a97dd51
File diff suppressed because one or more lines are too long
|
|
@ -976,13 +976,22 @@ fn reference_rect(s: &Session, p: &Value, ids: &[NodeId], preview: bool) -> Resu
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns the selected root (one of `ids`) that is the key object or contains it, such as the
|
||||
/// compound path or selected group the key is in. Align to the key object and Distribute Spacing
|
||||
/// with a spacing keep it in place.
|
||||
fn key_root(s: &Session, ids: &[NodeId]) -> Option<NodeId> {
|
||||
let st = s.doc().ok()?;
|
||||
let ancestry = st.doc.ancestry(st.selection.key?)?;
|
||||
ids.iter().copied().find(|id| ancestry.contains(id))
|
||||
}
|
||||
|
||||
fn align(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let ids = selected_roots(s)?;
|
||||
let preview = preview_bounds(s, p, "object.align")?;
|
||||
let r = reference_rect(s, p, &ids, preview)?;
|
||||
let h = str_param(p, "horizontal");
|
||||
let v = str_param(p, "vertical");
|
||||
let key = s.doc()?.selection.key;
|
||||
let key = key_root(s, &ids);
|
||||
let moves: Vec<(NodeId, Vec2)> = {
|
||||
let d = &s.doc()?.doc;
|
||||
items_bounds(d, &ids, preview)
|
||||
|
|
@ -1100,9 +1109,9 @@ fn distribute_spacing(s: &mut Session, p: &Value) -> Result<Value> {
|
|||
deltas.push((*id, pos - start(r)));
|
||||
pos += size(r) + gap;
|
||||
}
|
||||
// With a spacing (aligning to a key object) the key object stays where it is: the others
|
||||
// are spaced from it.
|
||||
let key = s.doc()?.selection.key;
|
||||
// With a spacing (aligning to a key object) the key object stays where it is, with the
|
||||
// compound path or selected group it is in: the others are spaced from it.
|
||||
let key = key_root(s, &ids);
|
||||
let fixed = spacing.and_then(|_| deltas.iter().find(|(id, _)| Some(*id) == key)).map_or(0.0, |k| k.1);
|
||||
let moves: Vec<(NodeId, Vec2)> =
|
||||
deltas.into_iter().map(|(id, d)| (id, if horiz { Vec2::new(d - fixed, 0.0) } else { Vec2::new(0.0, d - fixed) })).collect();
|
||||
|
|
|
|||
|
|
@ -52,6 +52,67 @@ fn group_ungroup() {
|
|||
assert_eq!(s.doc().unwrap().selection.len(), 2);
|
||||
}
|
||||
|
||||
/// Makes 10 pt squares at (0, 90) and (50, 100) into a compound path or group with the commands in
|
||||
/// `make`, each run on the selection (the last one makes `outer`), draws a 10 pt square `r` at
|
||||
/// (200, 0), selects the second square and `r`, and sets the selection's `key` to that square
|
||||
/// → (session, key, outer, r).
|
||||
fn key_inside(make: &[&str]) -> (Session, NodeId, NodeId, NodeId) {
|
||||
let mut s = session();
|
||||
let a = rect(&mut s, 0.0, 90.0, 10.0, 10.0);
|
||||
let key = rect(&mut s, 50.0, 100.0, 10.0, 10.0);
|
||||
s.execute("select.set", &json!({"ids": [a.0, key.0]})).unwrap();
|
||||
let mut outer = key;
|
||||
for cmd in make {
|
||||
outer = NodeId(s.execute(cmd, &json!({})).unwrap()["id"].as_u64().unwrap());
|
||||
}
|
||||
let r = rect(&mut s, 200.0, 0.0, 10.0, 10.0);
|
||||
s.execute("select.set", &json!({"ids": [key.0, r.0]})).unwrap();
|
||||
s.select(|_, sel| sel.key = Some(key)).unwrap();
|
||||
(s, key, outer, r)
|
||||
}
|
||||
|
||||
/// Aligns the selection left to its key object and, after Undo, spaces it 5 pt apart vertically
|
||||
/// → the top-left corners of `outer` and `r` after each.
|
||||
fn aligned_then_spaced(s: &mut Session, outer: NodeId, r: NodeId) -> [((f64, f64), (f64, f64)); 2] {
|
||||
let at = |s: &Session, id| {
|
||||
let b = s.doc().unwrap().doc.node(id).unwrap().geometric_bounds().unwrap();
|
||||
(b.x0, b.y0)
|
||||
};
|
||||
s.execute("object.align", &json!({"horizontal": "left", "bounds": "geometric"})).unwrap();
|
||||
let aligned = (at(s, outer), at(s, r));
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
s.execute("object.distributeSpacing", &json!({"axis": "vertical", "spacing": 5, "bounds": "geometric"})).unwrap();
|
||||
[aligned, (at(s, outer), at(s, r))]
|
||||
}
|
||||
|
||||
/// Align and Distribute Spacing move a compound path as one object. With one of its members as the
|
||||
/// key object, the compound path stays where it is: Align moves the others to the member's edge,
|
||||
/// and Distribute Spacing spaces them from the compound path.
|
||||
#[test]
|
||||
fn a_compound_path_that_contains_the_key_object_stays_in_place() {
|
||||
let (mut s, key, outer, r) = key_inside(&["object.compoundPath.make"]);
|
||||
assert_eq!(s.doc().unwrap().selection.key, Some(key));
|
||||
let [aligned, spaced] = aligned_then_spaced(&mut s, outer, r);
|
||||
assert_eq!(aligned, ((0.0, 90.0), (50.0, 0.0)), "it stays, the other moved to the key");
|
||||
assert_eq!(spaced, ((0.0, 90.0), (200.0, 75.0)), "5 pt apart, it stays");
|
||||
}
|
||||
|
||||
/// The key object stays the key when the group that contains it is added to the selection, by
|
||||
/// `select.add` or by the Group Selection tool's click on a selected member. Align and Distribute
|
||||
/// Spacing move that group as one object, and the group stays where it is, also when the key is in
|
||||
/// a group inside it.
|
||||
#[test]
|
||||
fn a_selected_group_that_contains_the_key_object_stays_in_place() {
|
||||
for make in [&["object.group"][..], &["object.group", "object.group"]] {
|
||||
let (mut s, key, outer, r) = key_inside(make);
|
||||
s.execute("select.add", &json!({"ids": [outer.0]})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().selection.key, Some(key), "{make:?}");
|
||||
let [aligned, spaced] = aligned_then_spaced(&mut s, outer, r);
|
||||
assert_eq!(aligned, ((0.0, 90.0), (50.0, 0.0)), "{make:?}: it stays, the other moved to the key");
|
||||
assert_eq!(spaced, ((0.0, 90.0), (200.0, 75.0)), "{make:?}: 5 pt apart, it stays");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arrange_order() {
|
||||
let mut s = session();
|
||||
|
|
|
|||
|
|
@ -396,6 +396,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
|||
- **Shaper:** uneven squares and rectangles become live rectangles even when drawing begins mid-edge. Recognition uses uniformly spaced samples and closed-loop corners, fits rectangle edges/angles rather than requiring a nearly perfect bounding-box fill, and includes the pointer-release position. Rectangles/squares and ellipses snap to 45° steps, hexagons to 90°, and triangles point up or down; lines keep their free angle even with Shift. Shaper Groups retain the live originals, merge regions with the gesture-origin fill, punch fills independently from strokes, remove boundaries on exiting scribbles and trim protruding stroke pieces. Source moves/resizes re-evaluate the result in the same undo step; double-click enters construction editing. Native save/reopen, face recoloring, Release and Expand are covered. The construction-mode widget and finer gesture heuristics remain.
|
||||
- **Selection:** Selection, Direct/Group Selection, Magic Wand, Lasso. A Shift-drag marquee toggles what it reaches: objects with the Selection tool, anchors with Direct and Group Selection (#483); the Lasso adds with Shift and subtracts with Alt. Dragging a path segment with Direct Selection bends it when it's curved (its anchors stay) and moves its two anchors when it's straight, one undo step; the fill, Shift or Alt still pick the whole path (Alt-drag copies it).
|
||||
Agent selection commands validate every object id before changing the selection and report the resulting count and ids (#784).
|
||||
Align and Distribute Spacing keep a compound path or selected group that contains the key object in place, as they keep the key object itself.
|
||||
Clear deletes individual selected compound-path members without deleting their siblings, and explicit object ids work without a selection; Cut still removes the same objects it copies (#786).
|
||||
- **Saved selections:** Select ▸ Save Selection… asks for a name and keeps the selection in the document (saved with the file, undoable, up to 25); each one is listed at the bottom of the Select menu and a click selects its objects again; Edit Selection… lists them to rename or delete, applied together on OK. A file's saved selections are capped and checked against its objects when it opens. Not yet: Update Selection and the Layers panel's saved-selection menu.
|
||||
- **Drawing:** Pen, Curvature, anchor tools, Pencil, Paintbrush, Blob Brush, Smooth, Path Eraser, Join. Direction handles dragged with Direct Selection or the Anchor Point tool snap to smart guides, and Shift keeps them at 45° steps from their anchor. The Pen continues any open path from the end clicked, and while drawing, a click on an end of another open path joins the two into one (#776). The Curvature tool edits any selected path, whatever drew it, keeping its shape except where edited (#798): a click on a point makes it current and a drag moves it, re-curving only its two segments; Alt-click or double-click toggles it smooth or corner and Delete removes it; a click on a segment adds a point without changing the shape; with an end of an open path current, clicks go on from it and its other end closes it (`path.curvatureEdit`). Every point a drawing tool places snaps to Smart Guides through one snapper (#506): the Pen's and Curvature tool's anchors, the Pencil's ends, the shape tools' start and dragged corner or radius (Rectangle, Rounded Rectangle, Ellipse, Polygon, Star, Line Segment, Arc, Spiral, the grids), the Type tool's click and frame, a new artboard's corners.
|
||||
|
|
|
|||
Loading…
Reference in New Issue