diff --git a/common/src/app/common/logic/variants.cljc b/common/src/app/common/logic/variants.cljc index 260985de52..42982a1301 100644 --- a/common/src/app/common/logic/variants.cljc +++ b/common/src/app/common/logic/variants.cljc @@ -507,9 +507,18 @@ orig-base-ref-shape (find-shape-ref-child-of container libraries old (:id orig-base-ref-shape))) new (get new-shapes-map (get o-ref-shapes-p-map (:id old-ref))) - swapped? (and (not root?) (ctk/swapped? old))] + swapped? (and (not root?) (ctk/swapped? old)) + ;; a main between the shape and the variant swapped it, so its + ;; content and overrides belong to another component + swapped-in-chain? + (and (not root?) (not swapped?) + (some #(and (ctk/swapped? %) (not= (:id %) (:id old-ref))) + (rest (ctf/get-ref-chain-until-target-ref container libraries old + (:id old-ref)))))] ;; a swap is kept only where the new variant holds a copy - (when (and new (or (not swapped?) (ctk/instance-head? new))) + (when (and new + (not swapped-in-chain?) + (or (not swapped?) (ctk/instance-head? new))) {:old old :old-ref old-ref :new new :swapped? swapped?}))) orig-touched) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index ab4b12f498..2adba1681f 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1857,6 +1857,13 @@ [:make-variant 0 0 0 0] [:detach 0 0 0 0] [:variant-property 0 0 0 0] [:switch 12]]})))) +(t/deftest switching-a-copy-carries-no-override-of-a-swap-its-main-makes + (t/is (map? (cg/run {:world [3 2 {:variants true :text-styles true :layout nil :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 [[:edit 3 0 0 1] [:variant-property 0 6 0 0] [:switch 0] [:make-variant 5] + [:switch 13] [:make-variant 13 0 0 0] [:add-variant 0] [: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 cfe7b932dd..e8c84a6763 100644 --- a/common/test/common_tests/logic/variants_switch_test.cljc +++ b/common/test/common_tests/logic/variants_switch_test.cljc @@ -3573,6 +3573,32 @@ (t/is (gpt/close? (offset-in-root file :m02 :m02-icon) (offset-in-root file' :copy02 :copy-icon-b))))) +(t/deftest test-switch-carries-no-override-of-a-swap-its-main-makes + (let [;; ==== Setup: a main nests a copy of the first variant, swaps its icon + ;; for icon B and fills it; a copy of that main holds the nested copy + red [{:fill-color "#ff0000" :fill-opacity 1}] + file (-> (thf/sample-file :file1) + (tho/add-simple-component :icon-a :icon-a-root :icon-a-child) + (tho/add-simple-component :icon-b :icon-b-root :icon-b-child) + (thv/add-variant-with-copy :v01 :c01 :m01 :c02 :m02 :m01-icon :m02-icon :icon-a) + (tho/add-frame :outer-root) + (thc/instantiate-component :c01 :nested :parent-label :outer-root + :children-labels [:nested-icon]) + (thc/component-swap :nested-icon :icon-b :nested-icon-b) + (tho/change-shape :nested-icon-b #(assoc % :fills red)) + (thc/make-component :outer :outer-root) + (thc/instantiate-component :outer :copy-outer :children-labels [:copy-nested])) + + ;; ==== Action + file' (tho/swap-component-in-shape file :copy-nested :c02 {:new-shape-label :copy-nested-2 + :keep-touched? true}) + icon' (ths/get-shape-by-id file' (-> (ths/get-shape file' :copy-nested-2) :shapes first))] + + ;; ==== Check: the fill is icon B's override, which icon A does not take + (t/is (contains? (:touched (ths/get-shape file :nested-icon-b)) :fill-group)) + (t/is (not (contains? (:touched icon') :fill-group))) + (t/is (= (:fills (ths/get-shape file' :m02-icon)) (:fills icon'))))) + (t/deftest test-switch-drops-a-swap-the-new-variant-holds-no-copy-for (let [;; ==== Setup: the second variant's icon is detached into a plain board file (setup-variant-with-swapped-icon)