diff --git a/common/src/app/common/logic/variants.cljc b/common/src/app/common/logic/variants.cljc index 44a7d9e0e7..deffb5c805 100644 --- a/common/src/app/common/logic/variants.cljc +++ b/common/src/app/common/logic/variants.cljc @@ -552,13 +552,11 @@ ;; A swapped child is kept as it is, and the others carry their ;; touched attributes into their new child - new-head (get objects (:id new-shape)) - new-base-ref-shape (ctf/find-remote-shape (assoc container :objects objects) libraries new-head) - ;; the old main's shapes turned as the copy turns its new main, so - ;; the switch compares them with the new copy's in one frame - orient-ref (or (when new-base-ref-shape - (cll/orient-like new-base-ref-shape new-head - (gsh/shape->center new-base-ref-shape))) + ;; the old main's shapes turned as the old copy turns them, so the + ;; switch compares them with the new copy's in one frame + orient-ref (or (when orig-base-ref-shape + (cll/orient-like orig-base-ref-shape original-shape + (gsh/shape->center orig-base-ref-shape))) identity) ;; `ref-shape` turned too as the copy turns the parent of `old` below ;; its root, so a turn a nested copy authors is not the child's own diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index efd754dea3..74f7892634 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2044,6 +2044,14 @@ [:edit 6 0 1 1] [:update-main 6] [:add-variant 0] [:switch 3] [:edit 0 0 1 1] [:update-main 0]]})))) +(t/deftest switching-to-a-flipped-variant-carries-no-flip-the-variants-do-not-share + (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 + :layout-children false :grid-empty false :layout-copies true :text true}] + :ops [[:nest 1 0 0 0] [:combine 0 0 0 0] [:combine 2] [:switch 0] [:rotate 7 0 5 0] + [:make-variant 0] [:switch 0] [:make-variant 8 0 0 0] [:make-variant 0] [:switch 2] + [:transform 10 4 0 0] [:make-variant 0] [:switch 17]]})))) + (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 diff --git a/common/test/common_tests/logic/variants_switch_test.cljc b/common/test/common_tests/logic/variants_switch_test.cljc index f3843f3e22..39b5b4837e 100644 --- a/common/test/common_tests/logic/variants_switch_test.cljc +++ b/common/test/common_tests/logic/variants_switch_test.cljc @@ -126,6 +126,25 @@ (t/is (gsh/close-attrs? :points (:points child) (:points (ths/get-shape-by-id full (:id child))) 0.001)))) +(t/deftest switching-to-a-turned-variant-compares-the-old-child-in-its-own-copy-frame + (let [file (-> (thf/sample-file :file) + (thv/add-variant :variant :c01 :m01 :c02 :m02 + :variant1-params {:width 100 :height 100} + :variant2-params {:width 100 :height 100}) + (ths/add-sample-shape :child1 :parent-label :m01 :width 50 :height 50) + (ths/add-sample-shape :child2 :parent-label :m02 :width 50 :height 50) + (thc/instantiate-component :c01 :copy01 :children-labels [:copy-child])) + initial (-> (tm/make-situation file) + (r/step (n/rotate :m02 45)) r/settle + (r/step (n/rotate :child2 -45)) r/settle + (r/step (n/rotate :copy-child 30)) r/settle) + switched (-> initial (r/step (n/switch-variant :copy01 "Value2")) r/settle) + head (tm/resolve-shape switched :copy01) + child (tm/shape-by-id switched (first (:shapes head)))] + (t/is (mth/close? 0 (:rotation head) 0.001)) + (t/is (mth/close? 315 (:rotation child) 0.001)) + (t/is (not (ctk/touched-group? child :geometry-group))))) + (t/deftest switch-keeps-a-resize-override-after-rotating-the-copy (doseq [sizing [nil :fix]] (let [params {:width 100 :height 100 :layout-item-v-sizing sizing}