diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 571483f47c..f356856d98 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -647,9 +647,11 @@ "Whether the copy shape `shape-inst` keeps the geometry it shows at sync: its copy authors a constraint that ties one of its dimensions to its copy parent. A constraint applies to the resizes after it, so sync does not - resize the shape through it again." - [container shape-inst] + resize the shape through it again. A swap reaching the shape from its + main (`shape-main` shows another component) brings the new size." + [container shape-inst shape-main] (and (ctk/touched-group? shape-inst :constraints-group) + (= (:component-id shape-inst) (:component-id shape-main)) (or (contains? #{:scale :leftright} (:constraints-h shape-inst)) (contains? #{:scale :topbottom} (:constraints-v shape-inst))) (some? (:shape-ref (ctn/get-shape container (:parent-id shape-inst)))))) @@ -682,7 +684,7 @@ (ctk/touched-group? shape-inst :layout-grid-cells)) placed (cond (and (not reset?) (or (ctk/touched-group? shape-inst :geometry-group) - (constraint-kept? container shape-inst))) + (constraint-kept? container shape-inst shape-main))) (in-main-frame shape-inst (:root-inst ctx) (:root-main ctx)) (and (not reset?) (= (:id shape-inst) (:id (:root-inst ctx)))) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 92d4c82776..e63dbb35c8 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1048,3 +1048,11 @@ (t/is (map? (cg/run {:world [2 0 {:text true :text-styles true}] :ops [[:resize 2 0 0 0] [:detach 3 0 0 0] [:detach 11 0 0 0] [:rotate 10 0 0 0] [:update-main 0 0 0 0] [:transform 0 0 0 12] [:update-main 7 0 0 0]]})))) + +(t/deftest generated-swap-brings-its-size-to-a-copy-child-with-its-own-constraint + ;; a copy child with its own scale constraint takes the size of the + ;; component its main swaps it for, as the other copies do + (t/is (map? (cg/run {:world [2 1 {:variants true :text-styles true :library true + :rich-variants true :layout-copies true :text true}] + :ops [[:style 24 8 1] [:swap 2 0 0 0] [:edit 3 0 1 1] [:update-main 3] + [:update-main 0 0 0 0]]}))))