From 0009acf42d8b747d221a111feee5df22ede47408 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 12 Nov 2026 19:50:12 +0100 Subject: [PATCH] :bug: Check a switched head's kept place through its own constraints A nested copy head in a copy that is resized apart from its main keeps its place as authored geometry when its constraint changes. Switching it keeps that place and, keeping the touched groups, its constraints, but the switch compared the place with its position placed through the main's own constraints. Where the two matched it dropped the geometry override, and the next sync of its parent moved the head through the constraints it carries. When a switch keeps the touched groups and the head authored its constraints, the kept place is compared with its position placed through those constraints, as sync places it. The harness model does the same. Test: switching-a-copy-head-keeps-the-place-its-own-constraint-kept. Focused switch, swap and composable tests pass (288 tests). Benchmark (alone): | :world | :baseline | :now | :mean | :ratio | |------------------------------------+-----------+---------+---------+--------| | deepest-edit-through-three-levels | 35.215 | 23.06 | 29.353 | 0.65 | | edit-through-a-chain-of-dependents | 68.931 | 46.664 | 61.416 | 0.68 | | library-update-into-copies | 83.083 | 49.118 | 51.106 | 0.59 | | main-edit-among-many-shapes | 4.837 | 2.744 | 3.366 | 0.57 | | main-edit-into-10-copies | 1.79 | 1.306 | 2.48 | 0.73 | | main-edit-into-100-copies | 15.415 | 11.34 | 12.203 | 0.74 | | main-edit-into-1000-copies | 153.086 | 130.776 | 191.745 | 0.85 | | variant-switch-into-copies | 32.052 | 22.084 | 26.522 | 0.69 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/variants.cljc | 13 +++++++++---- .../app/common/test_helpers/composable/shadow.cljc | 7 ++++++- .../common_tests/logic/composable_gen_test.cljc | 7 +++++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/common/src/app/common/logic/variants.cljc b/common/src/app/common/logic/variants.cljc index c22c7f5a00..1a46c75e00 100644 --- a/common/src/app/common/logic/variants.cljc +++ b/common/src/app/common/logic/variants.cljc @@ -681,8 +681,10 @@ (defn- keep-moved-placement "A swap keeps the place of the copy shape `original-shape` it replaces. Inside a copy, a first corner that the position of `new-shape` would not - give it needs a geometry override to survive later sync." - [changes original-shape new-shape page libraries] + give it needs a geometry override to survive later sync. With + `keep-touched?`, the constraints `original-shape` authors carry, and + later sync places the new head through them." + [changes original-shape new-shape page libraries keep-touched?] (let [objects (pcb/get-objects changes) shape (get objects (:id new-shape)) parent (get objects (:parent-id shape)) @@ -693,8 +695,11 @@ :include-deleted? true :with-context? true)) position-objects (:objects (:container (meta position))) position-parent (get position-objects (:parent-id position)) + ;; the constraints the new head carries as its own, by its position + authored (when (and keep-touched? (ctk/touched-group? original-shape :constraints-group)) + {(:id position) (d/without-nils (select-keys shape [:constraints-h :constraints-v]))}) placed (when position-parent - (get (cll/placed-like position-objects position-parent parent {}) (:id position)))] + (get (cll/placed-like position-objects position-parent parent authored) (:id position)))] (cond-> changes (and placed (not (gpt/close? (first (:points shape)) (first (:points placed))))) (pcb/update-shapes [(:id shape)] #(update % :touched ctk/set-touched-group :geometry-group) @@ -786,7 +791,7 @@ changes (sync-restored-position changes page libraries (:id new-shape)) - changes (cond-> (keep-moved-placement changes shape new-shape page libraries) + changes (cond-> (keep-moved-placement changes shape new-shape page libraries keep-touched?) keep-touched? (keep-placement-overrides shape new-shape)) diff --git a/common/src/app/common/test_helpers/composable/shadow.cljc b/common/src/app/common/test_helpers/composable/shadow.cljc index 8478138fcd..dbb1766718 100644 --- a/common/src/app/common/test_helpers/composable/shadow.cljc +++ b/common/src/app/common/test_helpers/composable/shadow.cljc @@ -930,6 +930,11 @@ (not= (boolean (:flip-y old-root)) (flip :flip-y))) ;; a swap keeps the old head's layout item values, and their overrides layout-items (into {} (filter #(.startsWith (name (key %)) "layout-item-")) (get model root-id)) + ;; the position as the head's constraints place it, when the head + ;; carries its own + placing (cond-> after + (and position (contains? (get result root-id) :constraints-group)) + (update (:id position) merge (select-keys root [:constraints-h :constraints-v]))) ;; a swap in a copy keeps an authored place its position does not give, ;; unless a layout places the head kept-place? (and (:shape-ref parent) position @@ -938,7 +943,7 @@ (contains? (get model root-id) :geometry-group) (not (gpt/close? (first (:points root)) (first (:points (geom/child-placement position (get after (:parent-id position)) - parent after))))))] + parent placing))))))] (cond-> result retained-orientation? (assoc-in [root-id :geometry-group] diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 4832e704c0..1b03e200cd 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2443,6 +2443,13 @@ :grid-empty false :layout-copies false :text false}] :ops [[:transform 0 2 0 7] [:delete] [:switch] [:transform 1 1]]})))) +(t/deftest switching-a-copy-head-keeps-the-place-its-own-constraint-kept + (t/is (map? (cg/run {:world [3 2 {:variants true :text-styles false :layout nil :variant-diff false + :layout-item-margins false :grid-square false :rich-variants true + :layout-children false :grid-empty false :layout-copies false :text true}] + :ops [[:add-variant] [:variant-property 0 9 25] [:make-variant 11] [:resize 19] + [:add-child] [:style 19 9 1] [:switch 9]]})))) + (t/deftest settling-a-bool-in-a-grid-copy-twice-keeps-its-shapes-in-place (t/is (map? (cg/run {:world [3 0 {:variants true :rich-variants true :text true :layout :grid :layout-copies true :layout-children true}]