Direct Selection: setBounds and guide.move check the interpolate param

object.setBounds and guide.move move direct-selected anchors through the
same path as object.move, so they already followed the Interpolate
Control Points preference. They now list `interpolate` in their params
text and reject a value that is not true or false, also when the change
only scales the anchors or only guides are selected. A test covers both
commands with the preference on and off and with the param.
This commit is contained in:
dotCooCoo
2026-11-17 06:25:45 -08:00
parent 33defecb66
commit 1b3a1a3eef
5 changed files with 63 additions and 4 deletions
+2 -1
View File
@@ -238,7 +238,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Move Guide",
[],
None,
"{index, pos: pt} | {dx?, dy?: pt, copy?: bool} put ruler guide `index` at `pos`, or move the selected guides (vertical ones by dx, horizontal ones by dy); copy leaves them and selects the moved copies",
"{index, pos: pt} | {dx?, dy?: pt, copy?: bool, interpolate?: bool (with art selected too: as object.move's)} put ruler guide `index` at `pos`, or move the selected guides (vertical ones by dx, horizontal ones by dy); copy leaves them and selects the moved copies",
guides_unlocked,
guide_move
),
@@ -989,6 +989,7 @@ pub(crate) fn guide_move(s: &mut Session, p: &Value) -> Result<Value> {
let dx = number_or(p, "dx", 0.0, "guide.move")?;
let dy = number_or(p, "dy", 0.0, "guide.move")?;
let copy = switch_or(p, "copy", false, "guide.move")?;
switch_or(p, "interpolate", false, "guide.move")?;
if !s.doc()?.selection.is_empty() {
let ids = super::edit::selected_roots(s)?;
return super::object::apply_transform(
+1 -1
View File
@@ -58,7 +58,7 @@ fn bounds_transform(s: &Session, p: &Value, ids: Vec<NodeId>, least: f64, anchor
check_numbers(p, &["x", "y", "width", "height", "reference"], "object.setBounds")?;
let st = s.doc()?;
check_switches(p, &TRANSFORM_SWITCHES, "object.setBounds")?;
check_switches(p, &["proportional"], "object.setBounds")?;
check_switches(p, &["proportional", "interpolate"], "object.setBounds")?;
let how = s.bounds_measure();
if anchors
&& transforms_objects(p)
+1 -1
View File
@@ -287,7 +287,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Set Bounds",
[],
None,
"{x?, y?, width?, height?, reference?: 0..8 (9-point grid; a number past 8 is read as 8), proportional?, strokes?, corners?, copy?: bool, patterns?: bool (Transform Patterns), typeAreas?: bool (area type: the frame is reshaped and the text reflows at its size), objects?: bool (Transform Objects, as object.move)} (Transform panel; width/height and the reference point follow the bounding box, rotated with rotated objects; x, y are page coordinates; with Use Preview Bounds the values measure the visual bounds; with the typeGlyphBounds preference, each point type object selected as an object (not inside a selected group) is measured by its glyphs' ink (underline and strikethrough included), which the scale gives the size asked for; strokes/corners as object.scale; with anchor points selected (Direct Selection) and no copy, the values are the box around those points, square to the page, and only they move or scale, as with object.move (#1824))",
"{x?, y?, width?, height?, reference?: 0..8 (9-point grid; a number past 8 is read as 8), proportional?, strokes?, corners?, copy?: bool, patterns?: bool (Transform Patterns), typeAreas?: bool (area type: the frame is reshaped and the text reflows at its size), objects?: bool (Transform Objects, as object.move), interpolate?: bool (with anchor points selected and only x or y changed: as path.moveAnchors's; default: prefs interpolateControlPoints)} (Transform panel; width/height and the reference point follow the bounding box, rotated with rotated objects; x, y are page coordinates; with Use Preview Bounds the values measure the visual bounds; with the typeGlyphBounds preference, each point type object selected as an object (not inside a selected group) is measured by its glyphs' ink (underline and strikethrough included), which the scale gives the size asked for; strokes/corners as object.scale; with anchor points selected (Direct Selection) and no copy, the values are the box around those points, square to the page, and only they move or scale, as with object.move (#1824))",
has_selection,
set_bounds
),
@@ -216,6 +216,63 @@ fn move_and_transform_of_anchors_re_map_the_handles_in_one_undo_step() {
}
}
#[test]
fn set_bounds_and_guide_move_of_anchors_follow_the_preference_and_the_param() {
for (pref, param, re_mapped) in [(false, None, false), (true, None, true), (true, Some(false), false), (false, Some(true), true)] {
for cmd in ["object.setBounds", "guide.move"] {
let mut s = session();
interpolate(&mut s, pref);
let id = curve(&mut s);
select(&mut s, id, json!([[0, 0]]));
let mut params = if cmd == "object.setBounds" {
json!({"x": 120, "y": 108})
} else {
let g = s.execute("guide.add", &json!({"vertical": true, "pos": 50})).unwrap()["index"].as_u64().unwrap();
s.execute("guide.select", &json!({"indexes": [g], "toggle": true})).unwrap();
json!({"dx": 20, "dy": 8})
};
if let Some(on) = param {
params["interpolate"] = json!(on);
}
let (before, original) = (history(&s).0, path_of(&s, id));
s.execute(cmd, &params).unwrap();
assert_eq!(history(&s).0, before + 1, "{cmd}: one undo step");
let (a, b) = (anchor(&s, id, 0), anchor(&s, id, 1));
assert_eq!(a.p, Point::new(120.0, 108.0), "{cmd}");
if re_mapped {
close(a.h_out, Point::new(165.0, 106.0));
close(b.h_in, Point::new(255.0, 102.0));
} else {
assert_eq!((a.h_out, b.h_in), (Point::new(170.0, 108.0), Point::new(250.0, 100.0)), "{cmd}, pref {pref}, param {param:?}");
}
s.execute("edit.undo", &json!({})).unwrap();
assert_eq!(path_of(&s, id), original, "{cmd}: undone");
}
}
let mut s = session();
let id = curve(&mut s);
// Both anchors, so that a new width scales them and does not only move them.
select(&mut s, id, json!([[0, 0], [0, 1]]));
s.execute("guide.add", &json!({"vertical": true, "pos": 50})).unwrap();
s.execute("guide.select", &json!({"indexes": [0], "toggle": true})).unwrap();
let original = path_of(&s, id);
for (cmd, params) in [
("object.setBounds", json!({"x": 120, "interpolate": "yes"})),
("object.setBounds", json!({"width": 50, "interpolate": 1})),
("guide.move", json!({"dx": 1, "interpolate": "yes"})),
] {
let e = s.execute(cmd, &params).unwrap_err().to_string();
assert!(e.contains("`interpolate` must be true or false"), "{cmd}: {e}");
}
assert_eq!(path_of(&s, id), original);
// With only guides selected, guide.move rejects the value too and leaves the guide.
s.execute("select.none", &json!({})).unwrap();
s.execute("guide.select", &json!({"indexes": [0]})).unwrap();
let e = s.execute("guide.move", &json!({"dx": 1, "interpolate": "yes"})).unwrap_err().to_string();
assert!(e.contains("`interpolate` must be true or false"), "guide.move: {e}");
assert_eq!(s.doc().unwrap().doc.ruler_guides()[0].pos, 50.0);
}
#[test]
fn the_interpolate_param_overrides_the_preference_and_rejects_other_values() {
for (pref, param, re_mapped) in [(true, false, false), (false, true, true)] {
+2 -1
View File
@@ -6823,7 +6823,8 @@ The Selection & Anchor Display and General preferences apply to `pointer_gesture
- `interpolateControlPoints` (General › Interpolate Control Points When Moving Anchors, off by default): the default of
the `interpolate` param of `path.moveAnchors` (a Direct Selection drag), `object.nudge` (the arrow keys),
`object.move`, `object.transform` and `object.transformAgain`. It applies when they move direct-selected anchors
without turning or scaling them; `object.setBounds` and `guide.move` follow the preference when they move anchors.
without turning or scaling them. `object.setBounds` (only `x` or `y` changed) and `guide.move` (with art selected
too) take the same param and follow the preference when they move direct-selected anchors.
On, both handles of each segment with one moved end are re-mapped by the turn, uniform scale and move that take the
segment's old ends to its new ends, so a segment between two corner anchors keeps its shape relative to its ends. A
segment with both ends moved, or with its ends at the same place before or after the move, moves as it does with the