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}]