diff --git a/common/src/app/common/test_helpers/composable/shadow.cljc b/common/src/app/common/test_helpers/composable/shadow.cljc index c197d957f5..16c061270e 100644 --- a/common/src/app/common/test_helpers/composable/shadow.cljc +++ b/common/src/app/common/test_helpers/composable/shadow.cljc @@ -447,13 +447,15 @@ main-root (get before (:shape-ref root)) root-parent (get before (:parent-id root)) main-parent (get before (:parent-id main-root) {}) + ;; the way the rotation of `shape` stores its turn + sign (geom/turn-sign shape) ;; the turn the copy root inherits places it and is not pushed geometry (cond-> (values shape :geometry-group) (and (:component-root root) (not (get-in model [root-id :geometry-group]))) - (in-orientation root main-root) + (in-orientation root main-root sign) (and (not (:component-root root)) root-parent) - (in-orientation root-parent main-parent)) + (in-orientation root-parent main-parent sign)) replaced (when (and (contains? groups :swap-group) (not= (:shape-ref shape) (:shape-ref updated))) (get before (:shape-ref shape))) @@ -638,9 +640,17 @@ ;; and authored overrides belong to its own component. (when (= root-id (:id original)) [(get objects main-id) (get model root-id)])))) + ;; the shapes below an authored swap, which belong to the swapped component + swapped-below (into #{} + (comp (filter #(and (not= root-id (:id %)) + (contains? (get model (:id %)) :swap-group))) + (mapcat #(rest (subtree-shapes before (:id %)))) + (map :id)) + (subtree-shapes before root-id)) old-copies (into {} (keep (fn [shape] - (when-let [[main groups] (source before old-paths old-main-id shape)] - [(get old-paths (:id main)) [shape main groups]]))) + (when-not (contains? swapped-below (:id shape)) + (when-let [[main groups] (source before old-paths old-main-id shape)] + [(get old-paths (:id main)) [shape main groups]])))) (subtree-shapes before root-id)) ;; the rotation a clean copy of the new main takes in the root's parent placed-rotation (let [main (get after new-main-id)] diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index ef21719acb..e1e72d19e6 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2072,6 +2072,15 @@ :ops [[:combine 8] [:transform 13 4 0 6] [:nest 8] [:make-variant] [:make-variant 7] [:make-variant] [:transform 0 9 0 2] [:combine 9] [:switch 6]]})))) +(t/deftest updating-a-main-from-a-turned-copy-unturns-a-mirrored-swap-by-its-own-turn + (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles false :layout nil :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 [[:combine] [:make-variant] [:swap 4] [:add-variant 20] [:make-variant] + [:text-style 6 0 1] [:make-variant] [:switch] [:update-main] [:make-variant] + [:switch 8] [:switch 18] [:rotate 3] [:make-variant] [:resize 14] + [:add-variant 15] [:transform 5 5 0 18] [:update-main 20] [:update-main]]})))) + (t/deftest switching-a-text-with-a-typography-file-but-no-typography-carries-no-override (t/is (map? (cg/run {:world [1 0 {:variants true :text-styles false :layout :grid :variant-diff false :layout-item-margins false :grid-square false :rich-variants true @@ -2079,6 +2088,13 @@ :ops [[:text-style 3 8 1] [:text-style 3 1] [:nest] [:switch] [:text-style 0 8 1] [:switch 1]]})))) +(t/deftest switching-a-copy-holding-a-turned-copy-of-itself-in-a-swap-carries-no-turn + (t/is (map? (cg/run {:world [1 0 {:variants true :text-styles false :layout nil :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 [[:detach 2] [:switch 8] [:text 4] [:switch] [:nest 2] [:rotate] [:switch] + [:combine] [:switch 2]]})))) + (t/deftest turning-a-flipped-copy-turns-a-child-stored-as-the-other-mirror-turn (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout nil :variant-diff false :layout-item-margins false :grid-square false :rich-variants true