diff --git a/crates/ui-egui/src/dialogs/width_point.rs b/crates/ui-egui/src/dialogs/width_point.rs index 653f76a0be..1165d68845 100644 --- a/crates/ui-egui/src/dialogs/width_point.rs +++ b/crates/ui-egui/src/dialogs/width_point.rs @@ -33,7 +33,8 @@ //! `outSide2`, `outTotalWidth` and `outLinked`. //! //! OK and Delete on existing points, one or several, are refused when those points changed since -//! the dialog opened or another document is active; the dialog stays open and says why. +//! the dialog opened (their place, their widths, or which of them pair as a discontinuous point) or +//! another document is active; the dialog stays open and says why. // PLAN: the app's manifest depends on `craft-ui`, not on the `craft` facade, so the `craft::` paths below need hub-w2's manifest change. use craft::behavior::Mixed; @@ -208,6 +209,14 @@ fn pairs(points: &[(f64, f64, f64)]) -> Vec> { .collect() } +/// The sets of side widths that edit width point `i`, `[incoming, outgoing]`, with the points +/// paired as `pairs` pairs them: an outgoing half is not edited by the incoming set, and an +/// incoming half not by the outgoing set. +fn sets(pairs: &[Option], i: usize) -> [bool; 2] { + let outgoing = i.checked_sub(1).is_some_and(|a| pairs[a] == Some(i)); + [!outgoing, pairs[i].is_none()] +} + /// The width points `indices` of `id` names, each discontinuous point's two halves together. fn target(app: &VectorcraftApp, id: u64, indices: &Value) -> Result { const NONE: &str = "no such width point"; @@ -238,7 +247,7 @@ fn target(app: &VectorcraftApp, id: u64, indices: &Value) -> Result Result<(Widt return Err(NONE.into()); } } + // Each point is still a continuous point or the same half of a discontinuous one: a point added + // at the place of one would leave it changing only one half. + let pairs = pairs(&profile.points); + if open.iter().any(|o| o.sets != sets(&pairs, o.index)) { + return Err(NONE.into()); + } Ok((profile, half)) } diff --git a/crates/ui-egui/src/dialogs/width_point/tests.rs b/crates/ui-egui/src/dialogs/width_point/tests.rs index 9e9d404ab8..1c9522319a 100644 --- a/crates/ui-egui/src/dialogs/width_point/tests.rs +++ b/crates/ui-egui/src/dialogs/width_point/tests.rs @@ -904,3 +904,30 @@ fn one_point_refuses_a_change_since_the_dialog_opened() { assert_eq!(app.session.doc().unwrap().doc, paired, "{field}"); } } + +#[test] +fn several_points_refuse_a_change_in_which_points_pair() { + // A point added at a selected point's place, after it, pairs with it; a third point at a + // discontinuous point's place unpairs its halves. The selected points keep their index, place + // and widths. + let cases = [ + ( + three_app as fn() -> (VectorcraftApp, u64), + json!([1, 3]), + json!([[0, 1, 1], [0.25, 0.8, 0.4], [0.5, 0.8, 0.8], [0.75, 0.4, 1.2], [0.75, 0.3, 0.3], [1, 1, 1]]), + ), + (pair_app, json!([0, 1]), json!([[0, 1, 1], [0.5, 0.8, 0.8], [0.5, 0.4, 1.2], [0.5, 0.3, 0.3], [1, 1, 1]])), + ]; + for (make, indices, points) in cases { + for field in ["side2", "delete"] { + let (mut app, id) = make(); + app.run("ui.widthPointEdit", json!({"id": id, "indices": indices})).unwrap(); + assert!(fields(&app).get("indices").is_some(), "{indices}: the several-point dialog opened"); + app.run("stroke.widthProfile.set", json!({"ids": [id], "points": points})).unwrap(); + let changed = app.session.doc().unwrap().doc.clone(); + assert!(press_field(&mut app, field).is_err(), "{indices} {field}"); + assert!(is_open(&app), "a refused press keeps the dialog open: {indices} {field}"); + assert_eq!(app.session.doc().unwrap().doc, changed, "{indices} {field}"); + } + } +} diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 48273a94a6..3ed99fd94b 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -657,7 +657,8 @@ as it was; `totalWidth` scales each point's own two sides to that total; a null `stroke.widthPoint.remove {id, indices}`. With `adjustAdjoining`, each changed point changes the nearest unselected point at another place before and after it in proportion to its change since the dialog opened; a point next to two changed points takes both changes. These rules for several points are VectorCraft's own. Confirm and Delete on existing -points, one or several, are refused when those points changed since the dialog opened or another document is active. +points, one or several, are refused when those points changed since the dialog opened (their place, their widths, or +which of them pair as a discontinuous point) or another document is active. Corners: double-clicking a Live Corners widget with the Selection or Direct Selection tool, or `ui.corners {id?, corners?}`, opens the `corners` dialog for a path's corners (the Direct-Selected ones, else every corner; fields `id`, diff --git a/docs/mcp.md b/docs/mcp.md index d199314d07..c50fbbecf7 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -8934,8 +8934,8 @@ turn it off to keep each point's other side), and Total Width scales each point' one `stroke.widthProfile.set` (one undo step, none when nothing changed), and Delete removes them all; with a discontinuous point among them, Incoming and Outgoing edit its two halves and both edit the continuous points. Malformed or out-of-range `indices`, or more than one of `index`, `indices` and `t`, are errors that open no dialog. OK -and Delete on existing points are refused when those points changed since the dialog opened or another document is -active. +and Delete on existing points are refused when those points changed since the dialog opened (their place, their widths, +or which of them pair as a discontinuous point) or another document is active. `document.inspect` reports a path's `strokeOptions.widthPoints` (`[t, left, right]`, factors of half the weight; null for a uniform stroke). `stroke.widthPoint.remove {id, index | indices}` deletes points; `stroke.widthProfile.set {ids, points}` replaces them all, as dragging several Shift-selected points with the Width tool does in one undo step.