Blend: Type, Ramp and Reverse Spine count a selected key as its blend

The Blend panel dimmed Type, Ramp and Reverse Spine only when a selected
object was itself a blend without a spine. With a key of each of two
blends selected through Direct Selection, the controls stayed enabled
while the commands, which act on each key's blend, refused the edit.
The panel now checks each selected object's nearest blend, as the
commands resolve it.
This commit is contained in:
dotCooCoo
2026-11-16 16:01:47 -08:00
parent 562021f185
commit df45b7cc4b
3 changed files with 40 additions and 4 deletions
+12 -3
View File
@@ -50,10 +50,19 @@ fn available(app: &VectorcraftApp, cmd: &str) -> bool {
&& (cmd != "object.blend.reverseSpine" || !selects_blend_without_spine(app))
}
/// Is a blend made without a spine selected?
/// Is a blend made without a spine selected? Each selected object counts as its nearest blend,
/// itself or an ancestor, as the Object › Blend commands resolve it, so a key selected with Direct
/// Selection counts as its blend.
fn selects_blend_without_spine(app: &VectorcraftApp) -> bool {
let Ok(st) = app.session.doc() else { return false };
st.selection.objects.iter().any(|id| matches!(st.doc.node(*id).map(|n| &n.kind), Some(NodeKind::Blend { spec, .. }) if spec.no_spine))
let Some(st) = app.session.active().filter(|st| st.selection.symbol_part.is_none()) else { return false };
st.selection.objects.iter().any(|id| {
let ancestry = st.doc.ancestry(*id).unwrap_or_default();
let blend = ancestry.iter().rev().find_map(|a| match st.doc.node(*a).map(|n| &n.kind) {
Some(NodeKind::Blend { spec, .. }) => Some(spec.no_spine),
_ => None,
});
blend == Some(true)
})
}
/// `object.blend.options` parameters for spacing mode `mode`, with the step count and distance
+27
View File
@@ -425,6 +425,33 @@ fn ramp_is_dimmed_while_a_selected_blend_has_no_spine() {
assert!(spec(&app, a).color_shift > 0.0 && spec(&app, b).color_shift == spec(&app, a).color_shift);
}
#[test]
fn ramp_and_reverse_spine_are_dimmed_while_a_selected_key_belongs_to_a_blend_with_no_spine() {
// A key of each blend is selected, as Direct Selection does: the commands act on the keys'
// blends, and the second has no spine, so Ramp and Reverse Spine do nothing.
let mut app = app();
let a = NodeId(app.run("object.blend.make", json!({"smooth": true, "orientation": "path"})).unwrap()["id"].as_u64().unwrap());
let ids: Vec<Value> =
[0, 200].map(|x| app.run("shape.rectangle", json!({"x": x, "y": 100, "width": 20, "height": 20})).unwrap()["id"].clone()).into();
app.run("select.set", json!({"ids": ids})).unwrap();
let b = NodeId(app.run("object.blend.make", json!({"smooth": true, "createSpine": "never"})).unwrap()["id"].as_u64().unwrap());
let key = |app: &VectorcraftApp, blend: NodeId| match &app.session.active().unwrap().doc.node(blend).unwrap().kind {
NodeKind::Blend { children, .. } => children[0].id,
k => panic!("not a blend: {k:?}"),
};
let keys = [key(&app, a).0, key(&app, b).0];
app.run("select.set", json!({"ids": keys})).unwrap();
assert_eq!(app.session.execute("object.blend.info", &json!({})).unwrap()["target"], "blend");
let mut f = Frames::new();
let (left, right) = f.slider(&mut app, 0);
let (before_a, before_b, depth) = (spec(&app, a), spec(&app, b), undo_depth(&app));
let (from, to) = (left + (right - left) * 0.6, left + (right - left) * 0.9);
f.press_and_move(&mut app, from, to);
f.release(&mut app, to);
f.click_text(&mut app, "Reverse Spine");
assert_eq!((spec(&app, a), spec(&app, b), undo_depth(&app), app.ui.status.as_str()), (before_a, before_b, depth, ""), "nothing ran");
}
#[test]
fn fractional_ramp_and_shift_stay_as_they_are_while_the_panel_draws() {
let mut app = app();