diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index f35f051b44..5f4db5890c 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -657,7 +657,8 @@ "A parent turned or moved by sync carries its whole subtree, including geometry overrides. Resize remains the job of constraints, not matrix scale: a parent turned and resized at once resizes its subtree through - their constraints first, then turns and moves it as one piece." + their constraints first, then turns and moves it as one piece. A swapped + head the resize gives another size authors that size." [changes container before] (let [after (get (pcb/get-objects changes) (:id before)) resized? (and after @@ -684,10 +685,23 @@ (let [objects (pcb/get-objects changes) parent (cond-> (merge after (select-keys before placement-geometry-attrs)) (ctsl/grid-layout? after) (ctsl/assign-cells objects))] - (placed-like (assoc objects (:id before) parent) before after {})))] + (placed-like (assoc objects (:id before) parent) before after {}))) + ;; untouched swapped heads the resize gives another size + scaled (when resized? + (into #{} + (filter #(let [shape (get (:objects container) %) + moved (get placed %)] + (and (ctk/swapped? shape) + (not (ctk/touched-group? shape :geometry-group)) + (some? moved) + (not (and (mth/close? (:width shape) (:width moved)) + (mth/close? (:height shape) (:height moved))))))) + ids))] (pcb/update-shapes changes ids (if resized? - #(get placed (:id %) %) + #(cond-> (get placed (:id %) %) + (contains? scaled (:id %)) + (update :touched ctk/set-touched-group :geometry-group)) #(cond-> % (some? turn) turn :always (gsh/move delta))) {:ignore-touched true})) changes))) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 03b336725a..9245da8789 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2282,6 +2282,13 @@ [:transform 3 9 7 13] [:switch] [:undo] [:update-main 1] [:duplicate 2] [:update-main 15] [:switch]]})))) +(t/deftest syncing-a-resized-copy-parent-authors-the-size-it-gives-a-swapped-head + (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles false :layout :grid :variant-diff false + :layout-item-margins false :grid-square false :rich-variants true + :layout-children false :grid-empty false :layout-copies false :text false}] + :ops [[:add-variant 15] [:duplicate 10] [:make-variant 8] [:switch 15] [:style 21 9 1] + [:update-main] [:duplicate 16] [:resize 16]]})))) + (t/deftest pushing-a-grid-direction-orders-the-copies-like-the-reflowed-main (t/is (map? (cg/run {:world [3 2 {:variants true :text-styles false :layout :grid :variant-diff false :layout-item-margins false :grid-square true :rich-variants false