diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 21c374e3e8..ed562ca3f9 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -613,7 +613,7 @@ (grc/rect->center (:selrect (get objects (:id shape-main)))))] (reduce #(update %1 %2 gsh/move delta) objects ids))) -(defn- axes-matrix +(defn axes-matrix "The directions of the axes of the transform of `shape`, without their lengths: the transform of a tiny shape scales them by its rounding." [shape] diff --git a/common/src/app/common/logic/swap.cljc b/common/src/app/common/logic/swap.cljc index 005a5121ce..eb1a009b6d 100644 --- a/common/src/app/common/logic/swap.cljc +++ b/common/src/app/common/logic/swap.cljc @@ -170,6 +170,11 @@ (contains? carried :text-content-typography) (into (filter agreed) txt/typography-units)))) +(defn- mirrored? + "Whether `shape` has exactly one flip." + [shape] + (not= (boolean (:flip-x shape)) (boolean (:flip-y shape)))) + (defn- switch-attr-operations "The `[attr value]` pairs that carry `attr` over a variant switch, from `previous-shape`, the copy shape before the switch placed like @@ -217,10 +222,17 @@ ;; 3. We set Copy’s bg to green (so it it has an override on the bg). ;; 4. We switch Copy to use C2 as base. ;; 5. The bg of Copy now is blue (we ignore the override) + ;; A mirror stores its turn either way, so the turns of two + ;; mirrors also agree where both point their axes alike. (and (not (contains? #{:points :selrect :content} attr)) (not (if (= sync-group :geometry-group) - (gsh/close-attrs? attr (get origin-ref-shape attr) (get current-shape attr)) + (or (gsh/close-attrs? attr (get origin-ref-shape attr) (get current-shape attr)) + (and (= attr :rotation) + (mirrored? origin-ref-shape) + (mirrored? current-shape) + (gmt/close? (cll/axes-matrix origin-ref-shape) + (cll/axes-matrix current-shape)))) (= (get origin-ref-shape attr) (get current-shape attr))))) ;; The :content attr cant't be copied to elements of different type diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 3430c7e0f8..5bf8d32722 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -20,6 +20,7 @@ [app.common.test-helpers.composable.comp.setups :as setup] [app.common.test-helpers.composable.core :as tm] [app.common.test-helpers.composable.gen :as cg] + [app.common.test-helpers.composable.geometry :as geom] [app.common.test-helpers.composable.grid :as grid] [app.common.test-helpers.composable.oracle :as oracle] [app.common.test-helpers.composable.shadow :as shadow] @@ -2166,6 +2167,21 @@ :ops [[:swap] [:make-variant 12] [:rotate] [:delete] [:transform 6 5] [:transform 3 9 0 13] [:switch]]})))) +(t/deftest switching-a-copy-carries-the-turn-of-a-mirrored-child-with-its-transform + (let [situation (:situation + (cg/run {:world [2 2 {:variants true :text-styles false :layout :grid :variant-diff false + :layout-item-margins false :grid-square false :rich-variants true + :layout-children false :grid-empty false :layout-copies false :text true}] + :ops [[:swap] [:make-variant 12] [:rotate] [:delete] [:transform 6 5] + [:transform 3 9 0 13] [:switch]]})) + turned (for [file (vals (cf/all-files situation)) + objects (cf/object-trees file) + shape (vals objects) + :when (and (ctk/touched-group? shape :geometry-group) (:flip-y shape))] + shape)] + (t/is (seq turned)) + (t/is (every? geom/decomposes? turned)))) + (t/deftest moving-a-flex-copy-child-after-a-switch-resized-its-sibling-authors-no-geometry (t/is (map? (cg/run {:world [1 2 {:variants true :text-styles false :layout :flex :variant-diff false :layout-item-margins false :grid-square false :rich-variants true