diff --git a/common/src/app/common/logic/swap.cljc b/common/src/app/common/logic/swap.cljc index 2c64dfceb3..ec3c8fff9a 100644 --- a/common/src/app/common/logic/swap.cljc +++ b/common/src/app/common/logic/swap.cljc @@ -102,11 +102,15 @@ origin (get origin-shape dimension)] (if (mth/close? origin current) prev current))) width (size :width) - height (size :height)] + height (size :height) + ;; the turn and flips the switch carries, when both variants agree on them + shape (cond-> current-shape + (gsh/close-attrs? :transform (:transform origin-shape) (:transform current-shape)) + (assoc :transform (:transform prev-shape)))] (case attr :width width :height height - (sized-geometry-value current-shape width height attr)))) + (sized-geometry-value shape width height attr)))) (defn- equal-geometry? diff --git a/common/src/app/common/types/shape.cljc b/common/src/app/common/types/shape.cljc index e48c32bdb8..cc8ce31674 100644 --- a/common/src/app/common/types/shape.cljc +++ b/common/src/app/common/types/shape.cljc @@ -596,7 +596,7 @@ :hidden :masked-group :fills :proportion :proportion-lock :constraints-h :constraints-v :fixed-scroll :r1 :r2 :r3 :r4 :rotation :opacity :grids :exports :strokes :blend-mode :interactions :shadow :blur :background-blur :grow-type :applied-tokens - :plugin-data}) + :plugin-data :flip-x :flip-y}) (def ^:private allowed-shape-geom-attrs #{:x :y :width :height}) (def ^:private allowed-shape-base-attrs #{:id :name :type :selrect :points :transform diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 9573d89976..b2e91c8c5c 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1012,3 +1012,10 @@ :layout-copies true :text true}] :ops [[:rotate 15 0 0 0] [:detach 15 0 0 0] [:delete 5] [:restore 5] [:resize 14 0 0 0] [:edit 3 0 1 1] [:update-main 3]]})))) + +(t/deftest generated-switched-copy-keeps-its-childs-flip + ;; a copy child flipped horizontally keeps its flip over a variant switch + (t/is (map? (cg/run {:world [2 0 {:variants true :text-styles true :library-variants true :stale-libraries true + :library-depth 1 :library true :rich-variants true :library-text true + :layout-copies true :text true}] + :ops [[:transform 0 4 0 2] [:switch 0 0 0 0]]})))) diff --git a/common/test/common_tests/logic/variants_switch_test.cljc b/common/test/common_tests/logic/variants_switch_test.cljc index 1537260392..12fb3a0dd5 100644 --- a/common/test/common_tests/logic/variants_switch_test.cljc +++ b/common/test/common_tests/logic/variants_switch_test.cljc @@ -2326,6 +2326,32 @@ ;; The transform matrix should also be preserved (t/is (some? (:transform rect02'))))) +(t/deftest test-switch-with-flip-override + ;; a flip of the copy's child is a geometry override that both variants + ;; agree on, so it carries like a rotation + (let [file (-> (thf/sample-file :file1) + (thv/add-variant-with-child + :v01 :c01 :m01 :c02 :m02 :r01 :r02 + {:child1-params {:width 100 :height 50} + :child2-params {:width 100 :height 50}}) + (thc/instantiate-component :c01 :copy01 :children-labels [:copy-r01])) + page (thf/current-page file) + rect01 (ths/get-shape file :copy-r01) + changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(:id rect01)} + #(gsh/transform-shape % (ctm/resize-modifiers (gpt/point -1 1) (gsh/shape->center %))) + (:objects page) + {}) + file (thf/apply-changes file changes) + flipped (ths/get-shape file :copy-r01) + file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true}) + page' (thf/current-page file') + rect02' (get-in page' [:objects (-> (ths/get-shape file' :copy02) :shapes first)])] + (t/is (true? (:flip-x flipped))) + (t/is (true? (:flip-x rect02'))) + (t/is (= (:transform flipped) (:transform rect02'))) + (t/is (gsh/close-attrs? :points (:points flipped) (:points rect02'))))) + (t/deftest test-switch-with-rotation-different-variants (let [;; ==== Setup file (-> (thf/sample-file :file1)