diff --git a/common/src/app/common/logic/variants.cljc b/common/src/app/common/logic/variants.cljc index 474e525800..e3d28f7c8e 100644 --- a/common/src/app/common/logic/variants.cljc +++ b/common/src/app/common/logic/variants.cljc @@ -413,8 +413,9 @@ "Carry the cell overrides of the switched grid `old` into `new`, its clean copy of the new variant, when the old main `old-ref` and `new` have identical grids: the same tracks and the same cells holding - corresponding children. Otherwise the new variant's cells win. - `counterpart` gives the child of `new` that relates to a child of `old`." + corresponding children, and they differ from the cells `new` shows. + Otherwise the new variant's cells win. `counterpart` gives the child of + `new` that relates to a child of `old`." [changes old old-ref new old-path new-path counterpart] (let [identical? (and (= (:layout-grid-rows old-ref) (:layout-grid-rows new)) (= (:layout-grid-columns old-ref) (:layout-grid-columns new)) @@ -431,8 +432,12 @@ (reduced nil) (assoc cells id (assoc cell :id id :shapes shapes))))) {} - (vals (:layout-grid-cells old))))] - (if cells + (vals (:layout-grid-cells old)))) + ;; cells the new copy already shows are no override + shown? (fn [cells] + (= (set (map #(dissoc % :id) (vals cells))) + (set (map #(dissoc % :id) (vals (:layout-grid-cells new))))))] + (if (and cells (not (shown? cells))) (pcb/update-shapes changes [(:id new)] #(-> % (assoc :layout-grid-cells cells) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 24540824e4..1c14c77c94 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1785,6 +1785,13 @@ [:variant-property 0 0 0 0] [:switch 1] [:make-variant 13 0 0 0] [:variant-property 0 0 0 0] [:switch 6]]})))) +(t/deftest switching-a-copy-to-an-identical-grid-it-already-shows-adds-no-override + (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout :grid :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 [[:grid-cell 1 0 0 0] [:delete 5 0 0 0] [:make-variant 4 0 0 0] + [:variant-property 0 0 0 0] [:switch 9]]})))) + (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 e8f8181113..9a3dca2fa5 100644 --- a/common/test/common_tests/logic/variants_switch_test.cljc +++ b/common/test/common_tests/logic/variants_switch_test.cljc @@ -3905,3 +3905,18 @@ (t/is (= [1 3] (item-cell file' copy' "Item 3"))) (t/is (= [1 1] (item-cell file' copy' "Item 1"))) (t/is (not (ctk/touched-group? copy' :layout-grid-cells))))) + +(t/deftest a-switch-between-identical-grids-carries-no-cells-the-new-copy-shows + ;; the copy's cells are marked as an override but equal its main's, so a + ;; switch to an identical grid has nothing to carry + (let [file (-> (thf/sample-file :file1) + (ths/add-sample-shape :v01 :type :frame :is-variant-container true) + (add-grid-member :v01 :blue :blue-root "Blue" 2 [[1 1] [1 2] [2 1]]) + (add-grid-member :v01 :green :green-root "Green" 2 [[1 1] [1 2] [2 1]]) + (thc/instantiate-component :blue :copy01) + (ths/update-shape :copy01 :touched #{:layout-grid-cells})) + file' (tho/swap-component-in-shape file :copy01 :green {:new-shape-label :copy02 :keep-touched? true}) + copy' (ths/get-shape file' :copy02)] + (t/is (= [1 1] (item-cell file' copy' "Item 1"))) + (t/is (= [2 1] (item-cell file' copy' "Item 3"))) + (t/is (not (ctk/touched-group? copy' :layout-grid-cells)))))