diff --git a/common/src/app/common/logic/swap.cljc b/common/src/app/common/logic/swap.cljc index d236b762ab..01a758f133 100644 --- a/common/src/app/common/logic/swap.cljc +++ b/common/src/app/common/logic/swap.cljc @@ -175,6 +175,9 @@ ;; If the attribute is not valid for the destiny, don't copy it (not (cts/is-allowed-switch-keep-attr? attr (:type current-shape))) + ;; The position is the new variant's; geometry carries only a size + (contains? #{:x :y} attr) + ;; If the values are already equal, don't copy them; geometry ;; within its precision (if (= sync-group :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 9faa793e92..4ae8249ad2 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1841,6 +1841,14 @@ :ops [[:nest 17 0 0 0] [:duplicate 9 0 0 0] [:make-variant 21 0 0 0] [:transform 6 16 0 18] [:rotate 15 0 0 0] [:switch 14 0 0 0]]})))) +(t/deftest switching-a-turned-copy-back-keeps-its-child-in-place + (t/is (map? (cg/run {:world [3 2 {:variants true :text-styles true :layout :flex :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 [[:delete 0 0 0 0] [:variant-property 0 1 0 0] [:switch 0] [:delete 4 0 0 0] + [:delete 7 0 0 0] [:make-variant 8 0 0 0] [:transform 13 3 7 0] [:combine 7] + [:switch 7] [:resize 10 0 0 0] [:combine 1] [:switch 10]]})))) + (t/deftest random-variant-compositions (let [coverage (atom {}) failure (atom nil)] diff --git a/common/test/common_tests/logic/variants_switch_test.cljc b/common/test/common_tests/logic/variants_switch_test.cljc index af97ef4764..35d142abe3 100644 --- a/common/test/common_tests/logic/variants_switch_test.cljc +++ b/common/test/common_tests/logic/variants_switch_test.cljc @@ -3715,6 +3715,25 @@ (t/is (mth/close? width (:width points))) (t/is (mth/close? height (:height points))))) +(t/deftest test-switch-places-a-moved-child-where-the-new-variant-does + ;; the copy lies where its main does, so the old main's child and the new + ;; copy's share their coordinates; a switch still carries no place + (let [file (-> (thf/sample-file :file1) + (thv/add-variant-with-child + :v01 :c01 :m01 :c02 :m02 :r01 :r02 + {:child1-params {:width 100 :height 50 :type :rect} + :child2-params {:width 100 :height 50 :type :rect}}) + (thc/instantiate-component :c01 :copy01 :children-labels [:copy-r01]) + (tho/move-shape-tree :copy01 (gpt/point -100 -100) :ignore-touched true) + (tho/move-shape-tree :copy-r01 (gpt/point 0 20))) + rect (copy-child file :copy01) + file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true}) + rect' (copy-child file' :copy02)] + (t/is (contains? (:touched rect) :geometry-group)) + (t/is (mth/close? (- (:y (ths/get-shape file' :r02)) (:y (ths/get-shape file' :m02))) + (- (:y rect') (:y (ths/get-shape file' :copy02))))) + (t/is (mth/close? (-> rect' :selrect :y) (:y rect'))))) + (t/deftest test-switch-keeps-a-resized-child-of-same-size-variants (let [file (-> (thf/sample-file :file1) (thv/add-variant-with-child