From ef028ce1168b219f806952525644be8a1680539a Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Mon, 9 Nov 2026 10:09:16 +0100 Subject: [PATCH] :paperclip: Re-anchor an authored position when its shape's constraints change A copy shape's authored geometry is checked where it sits in the parent it was authored in, resized through its constraints as that parent resizes. A constraint edit after a resize of that parent replayed the resize through the new constraint, though the edit moves nothing and applies only to later resizes. A constraint edit now anchors the authored position where the shape sits. Harness only; the benchmark is not run. AI-assisted-by: claude-opus-5-5 --- common/src/app/common/test_helpers/composable/gen.cljc | 7 ++++++- .../src/app/common/test_helpers/composable/shadow.cljc | 9 +++++++++ common/test/common_tests/logic/composable_gen_test.cljc | 8 ++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/common/src/app/common/test_helpers/composable/gen.cljc b/common/src/app/common/test_helpers/composable/gen.cljc index d7970007e1..5d1882e89f 100644 --- a/common/src/app/common/test_helpers/composable/gen.cljc +++ b/common/src/app/common/test_helpers/composable/gen.cljc @@ -913,7 +913,12 @@ ;; layout gave it, which no parent placement authored (and (= property :layout-item-absolute) (true? value) (:shape-ref shape) (not (:layout-item-absolute shape))) - (assoc-in [id :geometry-group] (shadow/author-geometry (get (all-objects after) id shape) nil))) + (assoc-in [id :geometry-group] (shadow/author-geometry (get (all-objects after) id shape) nil)) + + ;; a constraint resizes the shape only with its parent's later resizes + (and (#{:constraints-h :constraints-v} property) (get-in model [id :geometry-group])) + (update-in [id :geometry-group] shadow/anchor-position (get (all-objects after) id shape) + (get (all-objects after) (:parent-id shape)))) (:grid-cell :grid-direction) (grid/edit model shape (:action op) (:value op)) :reset (shadow/clear-subtree model objects id) :update-main (shadow/update-main model objects (all-objects after) id) diff --git a/common/src/app/common/test_helpers/composable/shadow.cljc b/common/src/app/common/test_helpers/composable/shadow.cljc index da48658bc1..6a5ef7a71b 100644 --- a/common/src/app/common/test_helpers/composable/shadow.cljc +++ b/common/src/app/common/test_helpers/composable/shadow.cljc @@ -124,6 +124,15 @@ (cond-> (values shape :geometry-group) parent (with-meta {::position {:shape shape :parent parent :sized? sized?}})))) +(defn anchor-position + "The authored geometry `value` placed from where `shape` sits now in + `parent`: a constraint change moves nothing and applies only to the + resizes after it." + [value shape parent] + (cond-> value + (::position (meta value)) + (vary-meta update ::position assoc :shape shape :parent parent))) + (defn- authored-placement "Where the shape `expected` records it authored sits in `parent`, resized through the constraints of `current` when given (they apply to the diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index bef6a64809..1ccbe53e5e 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1928,6 +1928,14 @@ [:reset 0 0 0 0] [:nest 14 0 0 0] [:switch 6 0 0 0] [:style 11 29 1] [:reset 2]]})))) +(t/deftest constraining-a-shape-after-its-parent-resized-keeps-it-in-place + (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout nil :variant-diff false + :layout-item-margins false :grid-square false :rich-variants true + :layout-children false :grid-empty false :layout-copies true :text true}] + :ops [[:detach 7 0 0 0] [:combine 21 0 0 0] [:detach 9 0 0 0] [:add-variant 9 0 0 0] + [:transform 12 0 0 18] [:add-variant 8] [:switch 0] [:add-variant 11 0 0 0] + [:resize 25 0 0 0] [:style 22 9 1]]})))) + (t/deftest random-variant-compositions (let [coverage (atom {}) failure (atom nil)]