mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 02:35:37 +01:00
Selection Tools: Edit Points Only keeps explicit anchor picks inside selected groups
A path's own anchor pick now wins over its group's whole-path expansion in either selection order, a segmentEnds of null is rejected, and OK in the dialog runs the command outside the preview so dropping Puppet Warp pins adds no undo step. The docs say whole paths still take object transforms.
This commit is contained in:
1 parent
7574374bc0
commit
c1bfae38c2
6 files changed
+105
-13
No files matched your search
@@ -54,7 +54,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Edit Points Only",
|
||||
["Object", "Plug-ins", "Selection Tools"],
|
||||
None,
|
||||
"{segmentEnds?: false (true: the points at the ends of each selected segment stay selected, as anchor points)} narrow the selection to the anchor points selected in it, so that a move or transform that follows acts on those points alone: a path with selected anchor points keeps them; a path with selected segments drops the segments and keeps its other selected anchor points, and the points at the segments' ends leave the selection unless segmentEnds is true; a path selected whole keeps all its points; a group or compound path selected whole gives way to the paths inside it, each selected whole, leaving out hidden and locked ones, a Shaper Group's original shapes and, while guides are locked, paths made into guides; type, images, symbols, meshes and other objects without anchor points, and ruler guides, leave the selection. With nothing selected, or no anchor point left to keep, it is an error that leaves the selection as it was. Only the selection changes, not the document, so there is nothing to undo → {changed (false when the selection already held only anchor points), count (the paths left selected), points (the anchor points selected on them)}",
|
||||
"{segmentEnds?: false (true: the points at the ends of each selected segment stay selected, as anchor points; any non-boolean value, including null, is an error)} narrow the selection to paths and their selected anchor points: a path with selected anchor points keeps them; a path with selected segments drops the segments and keeps its other selected anchor points, and the points at the segments' ends leave the selection unless segmentEnds is true; a path selected whole stays selected whole and still receives object transforms, including stroke and effect scaling when enabled; a group or compound path selected whole gives way to the paths inside it, each selected whole unless it has an explicit anchor pick, leaving out hidden and locked ones, a Shaper Group's original shapes and, while guides are locked, paths made into guides; explicit anchor picks take precedence regardless of selection order; type, images, symbols, meshes and other objects without anchor points, and ruler guides, leave the selection. With nothing selected, or no anchor point left to keep, it is an error that leaves the selection as it was. The command does not add an undo step → {changed (false when the selection already held only anchor points), count (the paths left selected), points (the anchor points selected on them)}",
|
||||
has_doc,
|
||||
edit_points_only
|
||||
),
|
||||
@@ -242,7 +242,10 @@ fn paths_inside<'a>(n: &'a Node, guides_locked: bool, out: &mut Vec<&'a Node>) {
|
||||
/// `addon.select.editPointsOnly`: narrow the selection to the anchor points selected in it.
|
||||
fn edit_points_only(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
const C: &str = "addon.select.editPointsOnly";
|
||||
let keep_ends = switch_or(p, "segmentEnds", false, C)?;
|
||||
let keep_ends = match p.get("segmentEnds") {
|
||||
None => false,
|
||||
Some(value) => value.as_bool().ok_or_else(|| bad(C, "`segmentEnds` must be true or false"))?,
|
||||
};
|
||||
let guides_locked = s.menu.guides_locked;
|
||||
let st = s.doc()?;
|
||||
let (doc, sel) = (&st.doc, &st.selection);
|
||||
@@ -278,6 +281,9 @@ fn edit_points_only(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let mut inside = vec![];
|
||||
paths_inside(n, guides_locked, &mut inside);
|
||||
for c in inside {
|
||||
if sel.objects.contains(&c.id) && sel.anchors.contains_key(&c.id) {
|
||||
continue;
|
||||
}
|
||||
if seen.insert(c.id) {
|
||||
kept.push((c.id, c.path_data().map_or(0, |path| path.anchors().count()), None));
|
||||
}
|
||||
|
||||
@@ -426,6 +426,44 @@ mod edit_points_only {
|
||||
assert_eq!(picked(&s), (vec![a, b], BTreeMap::new()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explicit_anchor_picks_override_group_expansion_in_either_order() {
|
||||
for group_first in [true, false] {
|
||||
let (mut s, a, b) = two();
|
||||
s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap();
|
||||
let group = NodeId(s.execute("object.group", &json!({})).unwrap()["id"].as_u64().unwrap());
|
||||
s.select(|_, sel| {
|
||||
sel.set(if group_first { vec![group, a] } else { vec![a, group] });
|
||||
sel.anchors.insert(a, refs(&[(0, 0)]));
|
||||
})
|
||||
.unwrap();
|
||||
let before = s.doc().unwrap().doc.node(a).unwrap().path_data().unwrap().clone();
|
||||
assert_eq!(s.execute(C, &json!({})).unwrap(), json!({"changed": true, "count": 2, "points": 5}));
|
||||
assert_eq!(s.doc().unwrap().selection.anchors[&a], refs(&[(0, 0)]));
|
||||
s.execute("object.move", &json!({"dx": 10, "dy": 20})).unwrap();
|
||||
let after = s.doc().unwrap().doc.node(a).unwrap().path_data().unwrap();
|
||||
for ((_, i, old), (_, _, new)) in before.anchors().zip(after.anchors()) {
|
||||
if i == 0 {
|
||||
assert_ne!(new.p, old.p);
|
||||
} else {
|
||||
assert_eq!(new.p, old.p, "unselected anchors stay in place");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn whole_paths_keep_object_transforms_and_stroke_scaling() {
|
||||
let (mut s, a, _) = two();
|
||||
s.execute("select.set", &json!({"ids": [a.0]})).unwrap();
|
||||
s.execute("stroke.set", &json!({"weight": 4})).unwrap();
|
||||
let before = s.doc().unwrap().doc.node(a).unwrap().appearance.stroke_width();
|
||||
s.execute(C, &json!({})).unwrap();
|
||||
assert!(!s.doc().unwrap().selection.anchors.contains_key(&a));
|
||||
s.execute("object.transform", &json!({"matrix": [2, 0, 0, 2, 0, 0], "strokes": true})).unwrap();
|
||||
assert!(s.doc().unwrap().doc.node(a).unwrap().appearance.stroke_width() > before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn groups_and_compound_paths_give_way_to_their_paths_and_other_objects_leave() {
|
||||
let (mut s, a, b) = two();
|
||||
@@ -487,7 +525,13 @@ mod edit_points_only {
|
||||
let e = s.execute(C, &json!({})).unwrap_err().to_string();
|
||||
assert!(e.contains("no anchor points are selected"), "{e}");
|
||||
assert_eq!(s.doc().unwrap().selection, before);
|
||||
for p in [json!({"segmentEnds": "yes"}), json!({"segmentEnds": 1}), json!({"segmentEnds": [true]}), json!({"segmentEnd": true})] {
|
||||
for p in [
|
||||
json!({"segmentEnds": null}),
|
||||
json!({"segmentEnds": "yes"}),
|
||||
json!({"segmentEnds": 1}),
|
||||
json!({"segmentEnds": [true]}),
|
||||
json!({"segmentEnd": true}),
|
||||
] {
|
||||
s.execute("select.anchors", &json!({"id": b.0, "anchors": [[0, 0]]})).unwrap();
|
||||
s.execute("select.segments", &json!({"id": a.0, "segments": [[0, 0]], "mode": "add"})).unwrap();
|
||||
let before = s.doc().unwrap().selection.clone();
|
||||
|
||||
@@ -157,8 +157,16 @@ fn pump_commit(app: &mut VectorcraftApp) {
|
||||
app.status("The document was reverted. Reopen this dialog to continue.");
|
||||
} else if !on_document {
|
||||
app.status("The add-on settings apply only to the drawing where the dialog opened.");
|
||||
} else if let Err(error) = preview.commit(app, spec.command, (spec.params)(&result.fields)) {
|
||||
app.status(error);
|
||||
} else {
|
||||
let params = (spec.params)(&result.fields);
|
||||
let answer = if spec.command == super::select::points_only::COMMAND {
|
||||
preview.commit_selection(app, spec.command, params)
|
||||
} else {
|
||||
preview.commit(app, spec.command, params)
|
||||
};
|
||||
if let Err(error) = answer {
|
||||
app.status(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(None) => {
|
||||
|
||||
@@ -55,6 +55,32 @@ fn the_dialog_previews_keeps_on_ok_and_takes_the_segment_ends_from_the_keyboard(
|
||||
assert_eq!(app.session.doc().unwrap().history.undo.len(), undo, "a selection change is not an undo step");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ok_drops_puppet_pins_without_an_undo_step() {
|
||||
for previewing in [true, false] {
|
||||
let (mut app, a, b) = app();
|
||||
app.run("select.set", json!({"ids": [a.0, b.0]})).unwrap();
|
||||
app.run("object.group", json!({})).unwrap();
|
||||
app.run("object.puppetWarp", json!({"pins": [[35, 35]], "moved": [[35, 35]], "rest": true})).unwrap();
|
||||
assert!(app.session.doc().unwrap().doc.puppet.is_some());
|
||||
let undo = app.session.doc().unwrap().history.undo.len();
|
||||
host::open_item(&mut app, "Selection Tools", "Edit Points Only…");
|
||||
let id = host::dialog_id(&app);
|
||||
if previewing {
|
||||
host::frame(&mut app);
|
||||
assert!(app.session.doc().unwrap().doc.puppet.is_none());
|
||||
}
|
||||
assert!(host::confirm(&app, id));
|
||||
host::frame(&mut app);
|
||||
assert!(!app.any_dialog_open());
|
||||
let st = app.session.doc().unwrap();
|
||||
assert!(st.doc.puppet.is_none());
|
||||
assert_eq!(st.selection.objects, vec![a, b]);
|
||||
assert!(!app.session.in_interaction());
|
||||
assert_eq!(st.history.undo.len(), undo, "pin cleanup does not add an undo step");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cancel_puts_the_selection_back() {
|
||||
let (app, _, b) = app();
|
||||
|
||||
@@ -125,6 +125,12 @@ impl LivePreview {
|
||||
Ok(Value::Null)
|
||||
}
|
||||
|
||||
/// OK for a selection command: rolls its preview back and runs the command without an interaction.
|
||||
pub(crate) fn commit_selection(self, app: &mut VectorcraftApp, cmd: &str, params: Value) -> Result<Value, String> {
|
||||
self.cancel(app);
|
||||
Self::default().commit(app, cmd, params)
|
||||
}
|
||||
|
||||
/// Cancel: rolls a shown preview back, and leaves any other edit in progress as it is.
|
||||
pub(crate) fn cancel(self, app: &mut VectorcraftApp) {
|
||||
if self.previewed.is_some() && self.owns(app) {
|
||||
|
||||
+10
-8
@@ -17313,18 +17313,20 @@ locked". Select by Link Status… lists every image and placed document with its
|
||||
name and filters by status (Show), chooses rows with checkboxes (All / None act on the rows shown), and on Select
|
||||
selects the rows chosen, zooming to them when Zoom to Selection is on (the default).
|
||||
|
||||
`addon.select.editPointsOnly {segmentEnds?}` (Edit Points Only…) narrows the selection to the anchor points selected in
|
||||
it, so that a move or transform that follows acts on those points alone. A path with selected anchor points keeps them.
|
||||
`addon.select.editPointsOnly {segmentEnds?}` (Edit Points Only…) narrows the selection to paths and their selected
|
||||
anchor points. A path with selected anchor points keeps them.
|
||||
A path with selected segments drops the segments and keeps its other selected anchor points; the points at the ends of
|
||||
the segments leave the selection unless `segmentEnds` is `true` (default `false`), which keeps them as selected anchor
|
||||
points. A path selected whole keeps all its points. A group or compound path selected whole is replaced by the paths
|
||||
inside it, each selected whole, without hidden and locked ones, without a Shaper Group's original shapes and, while
|
||||
guides are locked, without paths made into guides. Type,
|
||||
images, symbols, meshes and other objects without anchor points, and ruler guides, leave the selection. Only the
|
||||
selection changes, so there is nothing to undo. It returns `{changed, count, points}`: `changed` is `false` when the
|
||||
points. A path selected whole stays selected whole and still receives object transforms, including stroke and effect
|
||||
scaling when enabled. A group or compound path selected whole is replaced by the paths
|
||||
inside it, each selected whole unless it has an explicit anchor pick. Explicit anchor picks take precedence regardless
|
||||
of selection order. The command leaves out hidden and locked paths, a Shaper Group's original shapes and, while
|
||||
guides are locked, paths made into guides. Type,
|
||||
images, symbols, meshes and other objects without anchor points, and ruler guides, leave the selection. The command
|
||||
does not add an undo step. It returns `{changed, count, points}`: `changed` is `false` when the
|
||||
selection already held only anchor points, `count` is the number of paths left selected and `points` the number of
|
||||
anchor points selected on them. Nothing selected, no anchor point left to keep ("no anchor points are selected"), or a
|
||||
`segmentEnds` that is not `true` or `false` is an error, and the selection is left as it was.
|
||||
`segmentEnds` that is not `true` or `false` (including `null`) is an error, and the selection is left as it was.
|
||||
|
||||
```json
|
||||
{"name":"run_command","arguments":{"command":"addon.select.editPointsOnly","params":{"segmentEnds":false}}}
|
||||
|
||||
Reference in new issue
Block a user