feat(tools): key anchor point alignment (#1636)

This commit is contained in:
ruchirguitar
2026-11-16 03:02:45 +05:30
parent 957397e7a1
commit 081e147f57
9 changed files with 239 additions and 71 deletions
+5 -5
View File
@@ -50,10 +50,10 @@ pub struct Selection {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub key_guide: Option<NodeId>,
/// The key anchor for Align: one of two or more anchor points selected with Direct Selection,
/// the last one a Shift-click added (path, anchor in [`Self::anchors`]). Align and Distribute
/// move the other selected points relative to it, and it stays in place. Never set with `key`
/// or `key_guide`; [`Self::prune`] clears it when the point is no longer a selected anchor, or
/// fewer than two points are selected.
/// designated by clicking an already-selected anchor point without modifiers (path, anchor in
/// [`Self::anchors`]). Align and Distribute move the other selected points relative to it, and
/// it stays in place. Never set with `key` or `key_guide`; [`Self::prune`] clears it when the
/// point is no longer a selected anchor, or fewer than two points are selected.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub key_anchor: Option<(NodeId, AnchorRef)>,
/// The new art on a locked artboard that this selection keeps editable
@@ -311,7 +311,7 @@ impl Selection {
let anchor_kept = self.key_anchor.is_some_and(|(id, (si, ai))| {
self.objects.contains(&id)
&& !self.segments.contains_key(&id)
&& self.anchors.get(&id).is_some_and(|set| set.contains(&(si, ai)))
&& (self.anchors.get(&id).is_some_and(|set| set.contains(&(si, ai))) || !self.anchors.contains_key(&id))
&& found
.get(&id)
.and_then(|p| doc.node_at(p))
+1 -1
View File
@@ -260,7 +260,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Align",
["Window", "Align"],
None,
"{horizontal?: \"left\"|\"center\"|\"right\", vertical?: \"top\"|\"center\"|\"bottom\", to?: \"selection\"|\"artboard\"|\"key\" (default: the key object when the selection has one, select.key, else the selection; a key guide, select.key {guide}, stays put and the objects line up on its line: a vertical guide sets where left, center and right go and vertical alignment leaves them, a horizontal one the other way round; aligning to the key, the other selected ruler guides move too: a vertical guide to the key's left edge, center or right edge, a horizontal one to its top, center or bottom; aligning to the artboard moves selected guides to its edges too (#3463), and with only guides selected aligning to the selection moves them to their collective bounds), artboard?: index (0-based; with to: \"artboard\", the artboard to align to; the app passes the active one; default: the artboard under the center of the selection, else the first), bounds?: \"preview\"|\"geometric\" (default: the Use Preview Bounds preference; preview bounds take in strokes), patterns?: bool (Transform Patterns: pattern fills and strokes transform with the art; default: prefs transformPatternTiles)} With anchor points selected (Direct Selection), the points align instead: to their own bounds, to the artboard (#1180), or, aligning to the key with a key anchor (select.key {id, anchor}, the last point a Shift-click added), to the key anchor, which stays put",
"{horizontal?: \"left\"|\"center\"|\"right\", vertical?: \"top\"|\"center\"|\"bottom\", to?: \"selection\"|\"artboard\"|\"key\" (default: the key object when the selection has one, select.key, else the selection; a key guide, select.key {guide}, stays put and the objects line up on its line: a vertical guide sets where left, center and right go and vertical alignment leaves them, a horizontal one the other way round; aligning to the key, the other selected ruler guides move too: a vertical guide to the key's left edge, center or right edge, a horizontal one to its top, center or bottom; aligning to the artboard moves selected guides to its edges too (#3463), and with only guides selected aligning to the selection moves them to their collective bounds), artboard?: index (0-based; with to: \"artboard\", the artboard to align to; the app passes the active one; default: the artboard under the center of the selection, else the first), bounds?: \"preview\"|\"geometric\" (default: the Use Preview Bounds preference; preview bounds take in strokes), patterns?: bool (Transform Patterns: pattern fills and strokes transform with the art; default: prefs transformPatternTiles)} With anchor points selected (Direct Selection), the points align instead: to their own bounds, to the artboard (#1180), or, aligning to the key with a key anchor (select.key {id, anchor}), to the key anchor, which stays put",
has_selection_or_guides,
align
),
+21 -22
View File
@@ -82,19 +82,11 @@ pub fn specs() -> Vec<CommandSpec> {
"Cancel Key Object",
[],
None,
"{id?: a selected top-level object (not a layer, a compound-path member or an object inside another selected object); one of two or more or the only one with ruler guides selected (the Selection tool: a click on one object of a selection of several, or of one with guides; on the key again: no id), guide?: index (a selected ruler guide, guide.list, with one or more objects selected: the Selection tool's click on a selected guide; Align lines the objects up on it and the guide stays put), anchor?: [subpath, anchor] with `id` the path (an anchor point selected with Direct Selection beside at least one other point becomes the key anchor: Align and Distribute move the other points relative to it and it stays put; select.anchors add or toggle of one point makes it the key anchor, as a Shift-click does)} the key object Align aligns to and Distribute Spacing spaces from; without `id` or `guide` it cancels the key, as does a selection that holds only the key and objects inside it (one object, or a group key and its own members) and no ruler guide, or a key guide with no object selected or taken out of the selection, or a key anchor that is deselected, deleted or left as the only selected point; any other id, guide or anchor is an error that leaves the key as it was → {key, guide?, keyAnchor?} (the resulting key object, or null; guide: the key guide, left out without one; keyAnchor: {id, anchor}, left out without one)",
"{id?: a selected top-level object (not a layer, a compound-path member or an object inside another selected object); one of two or more or the only one with ruler guides selected (the Selection tool: a click on one object of a selection of several, or of one with guides; on the key again: no id), guide?: index (a selected ruler guide, guide.list, with one or more objects selected: the Selection tool's click on a selected guide; Align lines the objects up on it and the guide stays put), anchor?: [subpath, anchor] with `id` the path (an anchor point selected with Direct Selection beside at least one other point becomes the key anchor: Align and Distribute move the other points relative to it and it stays put; a click without modifiers on an already-selected anchor point makes it the key anchor)} the key object Align aligns to and Distribute Spacing spaces from; without `id` or `guide` it cancels the key, as does a selection that holds only the key and objects inside it (one object, or a group key and its own members) and no ruler guide, or a key guide with no object selected or taken out of the selection, or a key anchor that is deselected, deleted or left as the only selected point; any other id, guide or anchor is an error that leaves the key as it was → {key, guide?, keyAnchor?} (the resulting key object, or null; guide: the key guide, left out without one; keyAnchor: {id, anchor}, left out without one)",
has_doc,
key
),
cmd!(
"select.anchors",
"Select Anchors",
[],
None,
"{id, anchors: [[subpath, anchor]…], mode: \"set\"|\"add\"|\"toggle\"}; add or toggle that selects one point makes it the key anchor while another point is selected too (see select.key)",
has_doc,
anchors
),
cmd!("select.anchors", "Select Anchors", [], None, "{id, anchors: [[subpath, anchor]…], mode: \"set\"|\"add\"|\"toggle\"}", has_doc, anchors),
cmd!(
"select.segments",
"Select Segments",
@@ -734,17 +726,32 @@ fn key_anchor(s: &mut Session, id: Option<NodeId>, guide: Option<usize>, v: &Val
let st = s.doc()?;
let sel = &st.selection;
let on_path = st.doc.node(id).and_then(|n| n.path_data()).is_some_and(|p| p.subpaths.get(r.0).is_some_and(|sp| r.1 < sp.anchors.len()));
if !on_path || sel.segments.contains_key(&id) || !sel.anchors.get(&id).is_some_and(|set| set.contains(&r)) {
let is_selected_anchor = on_path
&& !sel.segments.contains_key(&id)
&& (sel.anchors.get(&id).is_some_and(|set| set.contains(&r)) || (!sel.anchors.contains_key(&id) && sel.contains(id)));
if !is_selected_anchor {
return Err(bad(C, format!("anchor [{}, {}] of object {id} is not a selected anchor point", r.0, r.1)));
}
// Check the new key on a copy first, so a request that fails leaves the key as it was.
let mut trial = sel.clone();
if !trial.anchors.contains_key(&id)
&& let Some(p) = st.doc.node(id).and_then(|n| n.path_data())
{
trial.anchors.insert(id, p.anchors().map(|(s, a, _)| (s, a)).collect());
}
trial.key_anchor = Some((id, r));
trial.prune(&st.doc);
if trial.key_anchor.is_none() {
return Err(bad(C, "select another anchor point to align to the key anchor"));
}
s.select(|_, sel| sel.key_anchor = Some((id, r)))?;
s.select(|d, sel| {
if !sel.anchors.contains_key(&id)
&& let Some(p) = d.node(id).and_then(|n| n.path_data())
{
sel.anchors.insert(id, p.anchors().map(|(s, a, _)| (s, a)).collect());
}
sel.key_anchor = Some((id, r));
})?;
key_result(s)
}
@@ -891,23 +898,15 @@ fn anchors(s: &mut Session, p: &Value) -> Result<Value> {
if whole && let Some(path) = d.node(id).and_then(|n| n.path_data()) {
e.extend(path.anchors().map(|(s, i, _)| (s, i)));
}
// One point that add or toggle selects becomes the key anchor (a Shift-click with Direct
// Selection); `prune` drops it unless another point is selected too.
let single = refs.len() == 1;
let mut newest = None;
for r in refs {
if mode == "toggle" && e.contains(&r) {
e.remove(&r);
} else if e.insert(r) && single {
newest = Some(r);
} else {
e.insert(r);
}
}
if e.is_empty() {
sel.remove(id);
} else if mode != "set"
&& let Some(r) = newest
{
sel.key_anchor = Some((id, r));
}
})?;
ok()
+116 -20
View File
@@ -1,6 +1,7 @@
//! #1636: the key anchor. With Direct Selection, the point a Shift-click adds to two or more
//! selected anchor points is the key anchor; Align moves the other points to it, Distribute with a
//! spacing places them from it, and it stays in place.
//! #1636: the key anchor. When multiple anchors are selected with Direct Selection,
//! clicking an already-selected anchor point without modifiers designates it as the key anchor;
//! Align moves the other points to it, Distribute with a spacing places them from it, and it stays in place.
//! Deselecting, pressing Escape, or clicking canvas clears the key anchor designation.
use serde_json::json;
use vectorcraft_tools::{Mods, PointerEvent, PointerKind};
@@ -34,56 +35,148 @@ fn click(s: &mut Session, x: f64, y: f64, shift: bool) {
}
#[test]
fn a_shift_click_makes_the_key_anchor_and_a_plain_click_narrows_the_selection() {
fn clicking_an_already_selected_anchor_makes_it_the_key_anchor() {
let mut s = session();
let id = path(&mut s, "M100 40 L200 60 L150 160 Z");
s.select_tool("directSelection", ViewInfo::default()).unwrap();
// 1st click selects point (0, 0) alone.
click(&mut s, 100.0, 40.0, false);
assert_eq!(key_anchor(&s), None, "one point: no key anchor");
// Shift-click adds point (0, 2) to selection. No key anchor yet.
click(&mut s, 150.0, 160.0, true);
assert_eq!(key_anchor(&s), Some((id, (0, 2))), "the point the Shift-click added");
assert_eq!(key_anchor(&s), None, "Shift-click only adds to selection");
// Shift-click adds point (0, 1) to selection. No key anchor yet.
click(&mut s, 200.0, 60.0, true);
assert_eq!(key_anchor(&s), Some((id, (0, 1))), "the last point added");
assert_eq!(key_anchor(&s), None, "Shift-click only adds to selection");
// Clicking an already-selected anchor without modifiers designates it as the Key Anchor.
click(&mut s, 200.0, 60.0, false);
assert_eq!(key_anchor(&s), Some((id, (0, 1))), "clicking selected anchor designates key anchor");
let inspect = s.execute("document.inspect", &json!({})).unwrap();
assert_eq!(inspect["keyAnchor"], json!({"id": id.0, "anchor": [0, 1]}));
// A Shift-click on the key anchor deselects it, and there is no key anchor.
click(&mut s, 200.0, 60.0, true);
assert_eq!(key_anchor(&s), None);
click(&mut s, 200.0, 60.0, true);
// A plain click on one of the selected points selects that point alone.
click(&mut s, 100.0, 40.0, false);
// Clicking the key anchor again cancels the key anchor.
click(&mut s, 200.0, 60.0, false);
assert_eq!(key_anchor(&s), None, "clicking key anchor again cancels it");
let inspect = s.execute("document.inspect", &json!({})).unwrap();
assert!(inspect["keyAnchor"].is_null());
// Clicking another selected anchor designates that one as the key anchor.
click(&mut s, 150.0, 160.0, false);
assert_eq!(key_anchor(&s), Some((id, (0, 2))));
// Pressing Escape cancels the key anchor designation while keeping points selected.
s.tool_key(vectorcraft_tools::ToolKey::Escape, Mods::default(), ViewInfo::default()).unwrap();
assert_eq!(key_anchor(&s), None, "Escape cancels key anchor");
let sel = &s.doc().unwrap().selection;
assert_eq!(sel.anchors.get(&id).map(|a| a.iter().copied().collect::<Vec<_>>()), Some(vec![(0, 0)]));
assert_eq!(sel.key_anchor, None);
assert_eq!(sel.anchors.get(&id).map(|a| a.len()), Some(3), "points remain selected");
// Designate key anchor:
click(&mut s, 150.0, 160.0, false);
assert_eq!(key_anchor(&s), Some((id, (0, 2))));
// Canvas click clears selection and key anchor.
click(&mut s, 500.0, 500.0, false); // canvas click
assert_eq!(key_anchor(&s), None, "canvas click clears key anchor");
assert!(s.doc().unwrap().selection.is_empty(), "canvas click clears selection");
// Re-select multiple anchors:
click(&mut s, 100.0, 40.0, false); // select (0, 0)
click(&mut s, 200.0, 60.0, true); // add (0, 1)
assert_eq!(key_anchor(&s), None);
click(&mut s, 200.0, 60.0, false); // make (0, 1) key anchor
assert_eq!(key_anchor(&s), Some((id, (0, 1))));
// Shift-click on the key anchor deselects it, clearing the key anchor.
click(&mut s, 200.0, 60.0, true);
assert_eq!(key_anchor(&s), None, "deselecting key anchor clears it");
}
#[test]
fn align_moves_the_other_points_to_the_key_anchor() {
let mut s = session();
let id = path(&mut s, "M100 40 L200 60 L150 160 L60 120 Z");
s.execute("select.anchors", &json!({"id": id.0, "anchors": [[0, 0], [0, 1]], "mode": "set"})).unwrap();
assert_eq!(key_anchor(&s), None, "a set selects no key anchor");
s.execute("select.anchors", &json!({"id": id.0, "anchors": [[0, 2]], "mode": "add"})).unwrap();
s.execute("select.anchors", &json!({"id": id.0, "anchors": [[0, 0], [0, 1], [0, 2]], "mode": "set"})).unwrap();
assert_eq!(key_anchor(&s), None, "set selects no key anchor");
s.execute("select.key", &json!({"id": id.0, "anchor": [0, 2]})).unwrap();
assert_eq!(key_anchor(&s), Some((id, (0, 2))));
// Horizontal Left aligns other selected points to key anchor's x (150).
s.execute("object.align", &json!({"horizontal": "left"})).unwrap();
assert_eq!(pts(&s, id), [(150.0, 40.0), (150.0, 60.0), (150.0, 160.0), (60.0, 120.0)], "to the key anchor's x");
// Vertical Bottom aligns other selected points to key anchor's y (160).
s.execute("object.align", &json!({"vertical": "bottom"})).unwrap();
assert_eq!(pts(&s, id), [(150.0, 160.0), (150.0, 160.0), (150.0, 160.0), (60.0, 120.0)], "the key anchor stays");
let steps = super::history(&s);
s.execute("object.align", &json!({"vertical": "top"})).unwrap();
assert_eq!(super::history(&s), steps, "nothing moved: no undo step");
// `to: "selection"` aligns to the points' bounds instead.
// `to: "selection"` aligns to the points' collective bounds instead.
s.execute("select.anchors", &json!({"id": id.0, "anchors": [[0, 3]], "mode": "add"})).unwrap();
s.execute("object.align", &json!({"horizontal": "left", "to": "selection"})).unwrap();
assert_eq!(pts(&s, id).iter().map(|p| p.0).collect::<Vec<_>>(), [60.0; 4]);
}
#[test]
fn align_commands_across_paths_without_moving_key_anchor() {
let mut s = session();
let a = path(&mut s, "M100 100 L200 100 L200 200 Z");
let b = path(&mut s, "M300 300 L400 350 Z");
// Select point (0, 1) on path a (at 200, 100) and point (0, 0) on path b (at 300, 300).
s.execute("select.anchors", &json!({"id": a.0, "anchors": [[0, 1]], "mode": "set"})).unwrap();
s.execute("select.anchors", &json!({"id": b.0, "anchors": [[0, 0]], "mode": "add"})).unwrap();
// Set point (0, 1) of a as the key anchor.
s.execute("select.key", &json!({"id": a.0, "anchor": [0, 1]})).unwrap();
assert_eq!(key_anchor(&s), Some((a, (0, 1))));
// Align Horizontal Center: point (0, 0) of b moves to x=200, while point on a does not move!
s.execute("object.align", &json!({"horizontal": "center"})).unwrap();
assert_eq!(pts(&s, a)[1], (200.0, 100.0), "key anchor on a does not move");
assert_eq!(pts(&s, b)[0].0, 200.0, "survivor point on b aligned to key anchor x");
assert_eq!(pts(&s, b)[1], (400.0, 350.0), "unselected point on b was not moved");
// Align Vertical Center / Middle: point (0, 0) of b moves to y=100.
s.execute("object.align", &json!({"vertical": "center"})).unwrap();
assert_eq!(pts(&s, a)[1], (200.0, 100.0), "key anchor on a still did not move");
assert_eq!(pts(&s, b)[0].1, 100.0, "survivor point on b aligned to key anchor y");
}
#[test]
fn single_step_undo_redo_for_key_anchor_alignment() {
let mut s = session();
let a = path(&mut s, "M100 100 L200 150 Z");
let b = path(&mut s, "M300 300 L400 350 Z");
s.execute("select.anchors", &json!({"id": a.0, "anchors": [[0, 0]], "mode": "set"})).unwrap();
s.execute("select.anchors", &json!({"id": b.0, "anchors": [[0, 0]], "mode": "add"})).unwrap();
s.execute("select.key", &json!({"id": a.0, "anchor": [0, 0]})).unwrap();
let initial_a = pts(&s, a);
let initial_b = pts(&s, b);
// Run align:
s.execute("object.align", &json!({"horizontal": "right"})).unwrap();
assert_eq!(pts(&s, a)[0], (100.0, 100.0), "key anchor did not move");
assert_eq!(pts(&s, b)[0].0, 100.0, "survivor moved to key anchor x");
// Undo reverts to initial in one step:
s.execute("edit.undo", &json!({})).unwrap();
assert_eq!(pts(&s, a), initial_a, "undo restored a");
assert_eq!(pts(&s, b), initial_b, "undo restored b");
// Redo re-aligns in one step:
s.execute("edit.redo", &json!({})).unwrap();
assert_eq!(pts(&s, a)[0], (100.0, 100.0));
assert_eq!(pts(&s, b)[0].0, 100.0);
}
#[test]
fn distribute_with_a_spacing_places_the_points_from_the_key_anchor() {
let mut s = session();
let id = path(&mut s, "M10 10 L20 50 L100 30 L60 90");
s.execute("select.anchors", &json!({"id": id.0, "anchors": [[0, 0], [0, 1]], "mode": "set"})).unwrap();
s.execute("select.anchors", &json!({"id": id.0, "anchors": [[0, 2]], "mode": "toggle"})).unwrap();
s.execute("select.anchors", &json!({"id": id.0, "anchors": [[0, 0], [0, 1], [0, 2]], "mode": "set"})).unwrap();
s.execute("select.key", &json!({"id": id.0, "anchor": [0, 2]})).unwrap();
s.execute("object.distributeSpacing", &json!({"axis": "horizontal", "spacing": 20})).unwrap();
assert_eq!(pts(&s, id), [(60.0, 10.0), (80.0, 50.0), (100.0, 30.0), (60.0, 90.0)], "20 apart, outward from the key anchor");
s.execute("object.distribute", &json!({"vertical": "center", "spacing": 5})).unwrap();
@@ -100,6 +193,7 @@ fn the_key_anchor_goes_when_it_can_no_longer_be_one() {
let b = path(&mut s, "M300 300 L400 300");
s.execute("select.anchors", &json!({"id": a.0, "anchors": [[0, 0]], "mode": "set"})).unwrap();
s.execute("select.anchors", &json!({"id": b.0, "anchors": [[0, 1]], "mode": "add"})).unwrap();
s.execute("select.key", &json!({"id": b.0, "anchor": [0, 1]})).unwrap();
assert_eq!(key_anchor(&s), Some((b, (0, 1))), "a point of another path");
assert!(s.doc().unwrap().selection.has_key());
let r = s.execute("select.key", &json!({})).unwrap();
@@ -114,6 +208,7 @@ fn the_key_anchor_goes_when_it_can_no_longer_be_one() {
let c = path(&mut s, "M500 500 L600 500");
s.execute("select.set", &json!({"ids": [c.0]})).unwrap();
s.execute("select.anchors", &json!({"id": a.0, "anchors": [[0, 1]], "mode": "add"})).unwrap();
s.execute("select.key", &json!({"id": a.0, "anchor": [0, 1]})).unwrap();
assert_eq!(key_anchor(&s), Some((a, (0, 1))), "beside a path selected whole");
s.execute("select.key", &json!({"id": c.0})).unwrap();
let sel = &s.doc().unwrap().selection;
@@ -154,6 +249,7 @@ fn a_rejected_select_key_keeps_the_key_anchor() {
let a = path(&mut s, "M100 40 L200 60 L150 160 Z");
s.execute("select.anchors", &json!({"id": a.0, "anchors": [[0, 0], [0, 9]], "mode": "set"})).unwrap();
s.execute("select.anchors", &json!({"id": a.0, "anchors": [[0, 1]], "mode": "add"})).unwrap();
s.execute("select.key", &json!({"id": a.0, "anchor": [0, 1]})).unwrap();
assert_eq!(key_anchor(&s), Some((a, (0, 1))));
// [0, 9] is in the selection but not on the path.
let err = s.execute("select.key", &json!({"id": a.0, "anchor": [0, 9]})).expect_err("a point the path does not have").to_string();
+30 -1
View File
@@ -713,6 +713,23 @@ fn part_picked(cx: &ToolContext, id: NodeId) -> bool {
cx.selection.symbol_part.as_ref().is_some_and(|sp| sp.instance == id)
}
/// Whether multiple anchor points are selected (across one or more paths) with Direct Selection.
fn has_multiple_selected_anchors(cx: &ToolContext) -> bool {
let direct_count: usize = cx.selection.anchors.values().map(|s| s.len()).sum();
if direct_count >= 2 {
return true;
}
if direct_count >= 1 {
let has_whole_path = cx.selection.objects.iter().any(|id| {
!cx.selection.anchors.contains_key(id) && cx.doc.node(*id).and_then(|n| n.path_data()).is_some_and(|p| p.anchors().next().is_some())
});
if has_whole_path {
return true;
}
}
false
}
/// The segment of path `id` nearest to `p`, where the hit test found its stroke.
fn segment_at(cx: &ToolContext, id: NodeId, p: Point) -> Option<SegmentHit> {
let pd = cx.doc.node(id)?.path_data()?;
@@ -769,6 +786,9 @@ impl Tool for DirectSelectionTool {
if key == ToolKey::Escape && self.guide.busy() {
return self.guide.cancel();
}
if key == ToolKey::Escape && matches!(self.state, State::Idle) && cx.selection.key_anchor.is_some() {
return vec![Action::Exec("select.key".into(), json!({}))];
}
if key != ToolKey::Escape || matches!(self.state, State::Idle) {
return vec![];
}
@@ -788,6 +808,7 @@ impl Tool for DirectSelectionTool {
|| self.claims_letter(key)
|| self.mesh_nudge(cx, key, Mods::default()).is_some()
|| self.frame_nudge(cx, key, Mods::default()).is_some()
|| (key == ToolKey::Escape && (cx.selection.key_anchor.is_some() || !matches!(self.state, State::Idle)))
}
fn notify(&mut self, cx: &ToolContext, what: &str) {
if what == FRAME_PICKED {
@@ -1596,7 +1617,15 @@ impl DirectSelectionTool {
(true, ..) => vec![Action::Commit],
(false, Some(id), _, _) => vec![Action::Exec("select.toggle".into(), json!({"id": id.0}))],
(false, None, Some((id, si, ai)), _) => {
vec![Action::Exec("select.anchors".into(), json!({"id": id.0, "anchors": [[si, ai]], "mode": "set"}))]
if has_multiple_selected_anchors(cx) {
if cx.selection.key_anchor == Some((id, (si, ai))) {
vec![Action::Exec("select.key".into(), json!({}))]
} else {
vec![Action::Exec("select.key".into(), json!({"id": id.0, "anchor": [si, ai]}))]
}
} else {
vec![Action::Exec("select.anchors".into(), json!({"id": id.0, "anchors": [[si, ai]], "mode": "set"}))]
}
}
(false, None, None, Some((id, si, seg))) => {
vec![Action::Exec("select.segments".into(), json!({"id": id.0, "segments": [[si, seg]]}))]
+59 -17
View File
@@ -661,10 +661,9 @@ fn an_anchor_drag_follows_the_while_moving_option() {
assert!((m - Vec2::new(5.7, 4.6)).hypot() < 1e-9, "{m:?}");
}
/// A click (no drag) on an anchor that is selected with others, whether the whole path is or
/// some of its anchors, selects that anchor alone, as in Illustrator: a press keeps the
/// selection so a drag moves it all, the release without a drag narrows it. Shift still
/// toggles, and a click on a path's only selected anchor changes nothing visible.
/// A click (no drag) on an anchor of a path selected whole selects that anchor alone, as in
/// Illustrator: a press keeps the selection so a drag moves it all, the release without a drag
/// narrows it. An anchor not yet selected is selected on the press.
#[test]
fn a_click_on_a_selected_anchor_selects_it_alone() {
let (d, id) = doc_with_rect();
@@ -672,22 +671,65 @@ fn a_click_on_a_selected_anchor_selects_it_alone() {
let alone = vec![Action::Exec("select.anchors".into(), json!({"id": id.0, "anchors": [[0, 0]], "mode": "set"}))];
let mut whole = Selection::default();
whole.set([id]);
for s in [whole, anchors_of(id, &[(0, 0), (0, 1)])] {
let cx = cx(&d, &s, &p);
let mut t = DirectSelectionTool::new(false);
assert!(t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 100.0, 100.0)).is_empty(), "{s:?}");
assert_eq!(t.pointer(&cx, &PointerEvent::new(PointerKind::Up, 100.0, 100.0)), alone, "{s:?}");
// Dragged instead: moved, selection kept.
assert!(t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 100.0, 100.0)).is_empty());
t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, 120.0, 100.0));
assert_eq!(t.pointer(&cx, &PointerEvent::new(PointerKind::Up, 120.0, 100.0)), vec![Action::Commit], "{s:?}");
}
let cx_whole = cx(&d, &whole, &p);
let mut t = DirectSelectionTool::new(false);
assert!(t.pointer(&cx_whole, &PointerEvent::new(PointerKind::Down, 100.0, 100.0)).is_empty());
assert_eq!(t.pointer(&cx_whole, &PointerEvent::new(PointerKind::Up, 100.0, 100.0)), alone);
// Dragged instead: moved, selection kept.
assert!(t.pointer(&cx_whole, &PointerEvent::new(PointerKind::Down, 100.0, 100.0)).is_empty());
t.pointer(&cx_whole, &PointerEvent::new(PointerKind::Drag, 120.0, 100.0));
assert_eq!(t.pointer(&cx_whole, &PointerEvent::new(PointerKind::Up, 120.0, 100.0)), vec![Action::Commit]);
// An anchor not yet selected is selected on the press, and the release adds nothing.
let none = Selection::default();
let cx = cx(&d, &none, &p);
let cx_none = cx(&d, &none, &p);
let mut t = DirectSelectionTool::new(false);
assert_eq!(t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 100.0, 100.0)), alone);
assert!(t.pointer(&cx, &PointerEvent::new(PointerKind::Up, 100.0, 100.0)).is_empty());
assert_eq!(t.pointer(&cx_none, &PointerEvent::new(PointerKind::Down, 100.0, 100.0)), alone);
assert!(t.pointer(&cx_none, &PointerEvent::new(PointerKind::Up, 100.0, 100.0)).is_empty());
}
/// #1636: when multiple anchors are selected with Direct Selection, clicking an already-selected
/// anchor without modifiers designates it as the key anchor. Clicking it again, or pressing Escape,
/// clears the key anchor designation.
#[test]
fn clicking_selected_anchor_designates_and_clears_key_anchor() {
let (d, id) = doc_with_rect();
let p = paint();
let s = anchors_of(id, &[(0, 0), (0, 1)]);
let cx_base = cx(&d, &s, &p);
// Clicking already-selected anchor (0, 0) designates it as Key Anchor.
let mut t = DirectSelectionTool::new(false);
assert!(t.pointer(&cx_base, &PointerEvent::new(PointerKind::Down, 100.0, 100.0)).is_empty());
assert_eq!(
t.pointer(&cx_base, &PointerEvent::new(PointerKind::Up, 100.0, 100.0)),
vec![Action::Exec("select.key".into(), json!({"id": id.0, "anchor": [0, 0]}))]
);
// Dragging instead moves anchors, committing the move.
assert!(t.pointer(&cx_base, &PointerEvent::new(PointerKind::Down, 100.0, 100.0)).is_empty());
t.pointer(&cx_base, &PointerEvent::new(PointerKind::Drag, 120.0, 100.0));
assert_eq!(t.pointer(&cx_base, &PointerEvent::new(PointerKind::Up, 120.0, 100.0)), vec![Action::Commit]);
// When the anchor is already designated as the key anchor:
let mut with_key = s.clone();
with_key.key_anchor = Some((id, (0, 0)));
let cx_key = cx(&d, &with_key, &p);
// Clicking it again cancels the key anchor.
let mut t2 = DirectSelectionTool::new(false);
assert!(t2.pointer(&cx_key, &PointerEvent::new(PointerKind::Down, 100.0, 100.0)).is_empty());
assert_eq!(t2.pointer(&cx_key, &PointerEvent::new(PointerKind::Up, 100.0, 100.0)), vec![Action::Exec("select.key".into(), json!({}))]);
// Pressing Escape cancels the key anchor.
let mut t3 = DirectSelectionTool::new(false);
assert!(t3.claims_key(&cx_key, ToolKey::Escape));
assert_eq!(t3.key(&cx_key, ToolKey::Escape, Mods::default()), vec![Action::Exec("select.key".into(), json!({}))]);
// Clicking canvas clears selection and key anchor.
let mut t4 = DirectSelectionTool::new(false);
assert!(t4.pointer(&cx_key, &PointerEvent::new(PointerKind::Down, 500.0, 500.0)).is_empty());
assert_eq!(t4.pointer(&cx_key, &PointerEvent::new(PointerKind::Up, 500.0, 500.0)), vec![Action::Exec("select.none".into(), json!({}))]);
}
/// Alt-pressing an anchor picks the whole path, as Alt on a segment does, and the drag copies
+2 -2
View File
@@ -684,8 +684,8 @@ fn a_key_anchor_is_chosen_named_and_aligned_to() {
let node = app.session.active().unwrap().doc.node(vectorcraft_doc::NodeId(id)).unwrap();
node.path_data().unwrap().anchors().map(|(_, _, a)| a.p.x).collect()
};
app.run("select.anchors", json!({"id": id, "anchors": [[0, 0]], "mode": "set"})).unwrap();
app.run("select.anchors", json!({"id": id, "anchors": [[0, 2]], "mode": "toggle"})).unwrap();
app.run("select.anchors", json!({"id": id, "anchors": [[0, 0], [0, 2]], "mode": "set"})).unwrap();
app.run("select.key", json!({"id": id, "anchor": [0, 2]})).unwrap();
let ctx = egui::Context::default();
let ([selection, key, _], left) = panel_buttons(&mut app, &ctx);
assert_eq!((align_to(&app), chosen_align_to(&mut app, &ctx)), (AlignTo::Key, vec![key]), "chosen automatically");
+2 -1
View File
@@ -34,6 +34,7 @@ Artboard Options forwards the active Artboard tool's Scale Artwork with Artboard
| Date | Change | Summary |
|---|---|---|
| 2026-11-16 | minor | G1: Recolor Artwork - native Lab entry in Color Picker, swatch libraries access in Color Picker, and row right-click context menu ("Pick from Swatches", "Limit to Library") (#4028); scores and estimates unchanged. |
| 2026-11-15 | minor | G4 type: modal Check Spelling dialog (Edit › Spelling › Check Spelling…, `ui.checkSpelling`, #4936) with Not in Dictionary sentence context, suggestions, Ignore, Ignore All, Change, Change All, Add to Dictionary, Done/Cancel, keyboard navigation, and one-step Undo/Redo; spell check complete; scores and estimates unchanged. |
| 2026-11-15 | minor | G5: Neon & Glow joins Shadows and Glows, Outlines and Rules, Hand-Drawn, Textures, Painted and Sketched, Gradient Finishes, Shape Effects, Blends and Transparency, Game HUD and Status Effects as an eleventh built-in graphic style library (Cyan Neon, Magenta Laser, Amber Tube, Electric Lime, Pulse Violet, Cobalt Phosphor; original procedural styles generated in code); estimate unchanged (3–13 h). |
| 2026-11-14 | minor | G12: Symbols panel context menu: right-click on a symbol in thumbnail or list view displays a context menu (Place Symbol Instance, Edit Symbol, Duplicate Symbol, Delete Symbol, Break Link to Symbol, Select All Instances), selecting the symbol first if unselected; scores and estimates unchanged. |
@@ -122,7 +123,7 @@ macOS cursor delivery (#2292) is narrowed to a native host adapter using the exi
- **Done:** Distance Guides ([public page](https://helpx.adobe.com/illustrator/desktop/measure-and-align/grids-and-guides/use-distance-guides-for-accurate-placement.html)): with Smart Guides on and something selected, the Selection tool with Alt/Option held over another object shows the horizontal and vertical distances between them, and over an empty part of an artboard the selection's distances from its four edges, labelled in the General unit; Preferences › Smart Guides › Invoke Distance Guides turns them off. Hover only, as documented: not while moving or nudging. No entry closed; estimates unchanged.
- **Done (part of #4028):** Recolor Artwork › Assign: double-clicking a row's new color opens the Color Picker, as the [public page](https://helpx.adobe.com/illustrator/desktop/manage-colors/modify-colors/assign-new-colors-to-selected-artwork.html) describes. OK sets the row's new color in the model it was picked in, so a CMYK mix is no longer a hex value converted back; Cancel leaves the row. A Lab new color is kept, but can't be typed yet: the picker's Lab fields work in RGB, as for fill and stroke. **Missing:** Lab entry in the picker, swatch libraries in the picker and the row's right-click menu (Pick from Swatches, Limit to Library).
- **Done (#4028):** Recolor Artwork › Assign: double-clicking a row's new color opens the Color Picker, as the [public page](https://helpx.adobe.com/illustrator/desktop/manage-colors/modify-colors/assign-new-colors-to-selected-artwork.html) describes. OK sets the row's new color in the model it was picked in, so a CMYK mix is no longer a hex value converted back; Cancel leaves the row. Lab color values can be typed directly in the Color Picker's Lab fields without converting to RGB. Swatch libraries are accessible in the picker via a library dropdown. Rows in the Recolor Artwork Assign tab feature a right-click context menu with "Pick from Swatches" (opening Color Picker in swatches view) and "Limit to Library" (with library submenu).
- **Done (#3416):** Recolor Artwork Edit chips scroll to the last color while the heading, color wheel and actions stay visible. Screen resize and UI scaling, Preview, Confirm, Cancel, Undo and #1733 wheel drags are covered in `tests/recolor.rs`. No gap entry closed; estimates unchanged.
+3 -2
View File
@@ -203,7 +203,7 @@ tools, never checked side by side) isn't captured row by row.
| Deleting segments or anchors that disconnect an ordinary path creates independent selected objects | done | #3380, deletion only: first piece retains its ID, styles and transforms carry over in sibling order, bounds-fitted gradients keep their original placement, and one Undo restores the original. Existing multi-subpath paths and compound members stay intact. `delete_path_pieces` covers transformed/styled rectangles, cubic handles and Undo/Redo. Endpoint highlighting remains open. |
| Click/Shift-click anchors; marquee toggles with Shift | done | #483 |
| Align selected anchors to their bounds or the artboard; repeating an alignment that moves nothing keeps Undo, Redo and saved state | done | #1180 follow-up; engine regressions include rounding-only moves and unchanged handles; #1641 (fixes #1636): Align and Distribute act on the anchors selected with Direct Selection, the points of one path aligning to each other and Distribute spacing them |
| Align selected anchors to a key anchor | done | #1636; a Shift-click with Direct Selection makes the point it adds the key anchor, drawn as a larger filled square in a frame, and Align To shows Align to Key Anchor; Align moves the other points to it and Distribute with a spacing places them from it; `select.key {id, anchor}` |
| Align selected anchors to a key anchor | done | #1636; with multiple anchors selected via Direct Selection, clicking an already-selected anchor without modifiers designates it as the key anchor (or clears it if clicked again); drawn as a filled square with a distinct double outline; pressing Escape, clicking the canvas, or deselecting clears the key anchor; Align moves the other points to it and Distribute with a spacing places them from it; `select.key {id, anchor}` |
| A ruler guide as the key object: a click on a guide selected with objects (or Align to Key Object with one object and a guide) makes it the key, drawn thicker; Align lines the objects (or selected anchors) up on it and the guide stays put | done | #2143; `select.key {guide}`; a vertical guide sets x only, a horizontal one y |
| Distribute Objects and Distribute Spacing with a spacing from a key guide: the guide stays put and the other items are spaced the Distribute Spacing value from it, as from a key object with no size | done | Key guide from #3165; a vertical guide spaces the horizontal options, a horizontal one the vertical ones, and a guide along the axis leaves everything |
| Distribute ruler guides: the Distribute Objects and Distribute Spacing buttons space the selected guides across the axis with the selected objects, as items with no size; two or more guides selected alone are enough | done | #1597 in part; guides alone: select them, choose Align to Artboard and click Horizontal (Vertical) Distribute Center for equal columns (rows) ([public forum answer, 2017](https://community.adobe.com/questions-652/illustrator-equal-guides-822924)); with objects: a guide on each artboard edge, included in the selection, keeps the outermost lines there ([public forum answer, 2025](https://www.signs101.com/threads/is-there-a-way-to-distribute-shapes-like-this-in-illustrator.179556/)); a guide has no width, so the three options of an axis are the same for it; guides along the axis stay |
@@ -498,7 +498,7 @@ next unit in the order a right-click on a ruler lists them, from Feet back to Po
- [x] Home screen (part of #4684, shared UI with PhotoCraft): the welcome, New / Open buttons and Community block are centred, and the large Discord button takes the theme's accent instead of Discord's colour; the layout and wording of the preset cards and Recent Files are unchanged. Still open from #4684: shortcut hints on the buttons, PhotoCraft's PRO and STUDIO themes, the Preferences layout (search box, theme swatches, Apply) and the title bar.
- [x] Recolor Artwork › Assign: double-click a row's new color to pick it in the Color Picker, in the model it was picked in (part of #4028); a Lab new color is kept but can't be typed yet (the picker's Lab fields work in RGB); Lab entry, swatch libraries and the row menu remain.
- [x] Recolor Artwork › Assign: double-click a row's new color to pick it in the Color Picker, in the model it was picked in, with native Lab entry, swatch libraries access in the picker, and row context menu options (Pick from Swatches, Limit to Library) (#4028).
- [x] Recolor Artwork › Color Theme Picker: with the button beside the tabs on, a click on the canvas takes the color palette of an object or image, a drag takes the palette of the art inside its marquee, and Shift adds more picks; the rows that aren't excluded take the palette as their new colors and the art previews them ([Recolor artwork](https://helpx.adobe.com/illustrator/desktop/manage-colors/modify-colors/recolor-artwork.html)). The number and order of the picked colors are VectorCraft's own rule (`recolor.pickTheme`). Tests: `theme_picks_give_the_rows_the_palette_of_the_art_picked` and `the_theme_picker_takes_clicks_and_shift_drags_on_the_canvas` in `crates/ui-egui/src/dialogs/recolor.rs`, `theme_picker_*` in `crates/engine/src/tests/recolor.rs`.
@@ -657,6 +657,7 @@ before release (#6373). [Paint faces and edges](https://helpx.adobe.com/illustra
| 2026-10-25 | minor | Selection tool: a double-click on a threaded port breaks the thread there (`text.thread.break`); scores and estimates unchanged |
| 2026-10-25 | minor | A selected Grid Repeat shows handles: the one below the grid adds or removes rows, the one right of it columns, the one past its bottom-right corner both, and the sliders between the first two columns and rows set the horizontal and vertical spacing; each drag is one undo step and Escape cancels it (#2691); headless canvas and tool regressions; scores and estimates unchanged. |
| 2026-10-25 | minor | Floating panels open in OS windows of their own on the desktop (inside the window on the web and on Wayland); saved layouts from earlier versions convert to the shared docking layout (#4135); scores and estimates unchanged (estimated) |
| 2026-10-25 | minor | Recolor Artwork › Assign: native Lab entry in the Color Picker, swatch libraries access in the picker, and row context menu options (Pick from Swatches, Limit to Library) (#4028). Scores and estimates unchanged. |
| 2026-10-25 | minor | Object › Expand… is dimmed for a selection with appearance attributes, with a tooltip to use Object › Expand Appearance first, so a stroked line with an effect expands to a stroked line before its stroke is outlined (#3089). Scores and estimates unchanged. |
| 2026-10-25 | minor | Transform Each opens on the values it was last confirmed with (Copy aside) and has a Copy button left of Cancel instead of a Copy checkbox (#1732). Scores and estimates unchanged. |
| 2026-10-25 | minor | Pathfinder panel › Pathfinder Options… opens a dialog with Precision, Remove Redundant Points and Divide and Outline Will Remove Unpainted Artwork, which the panel's operations use (#3426); scores unchanged |