diff --git a/common/src/app/common/logic/variants.cljc b/common/src/app/common/logic/variants.cljc index 204e8978b0..666a97329d 100644 --- a/common/src/app/common/logic/variants.cljc +++ b/common/src/app/common/logic/variants.cljc @@ -465,19 +465,25 @@ (clsw/update-attrs-on-switch changes new old new-shape original-shape old-ref container))) changes pairs) - changes (cond-> changes - (some #(and (= (:id %) (:id original-shape)) - (ctk/touched-group? % :geometry-group)) orig-touched) - (keep-orientation-override original-shape new-shape page - (or (get-in libraries [(:component-file new-shape) :data]) ldata) - (:component-id new-shape) nil)) + root-geometry? (some #(and (= (:id %) (:id original-shape)) + (ctk/touched-group? % :geometry-group)) orig-touched) + parent (get page-objects (:parent-id original-shape)) + ;; A switch keeps orientation even when the old main supplied it. + ;; If no geometry was carried, placement from an enclosing copy is + ;; still inherited rather than authored by this switch. + position (when (and (not root-geometry?) (:shape-ref parent)) + (ctf/find-ref-shape nil page libraries original-shape + :include-deleted? true :with-context? true)) + changes (keep-orientation-override changes original-shape new-shape page + (or (get-in libraries [(:component-file new-shape) :data]) ldata) + (:component-id new-shape) position) ;; A carried size changes the frame its untouched children follow. ;; Place them through the same constraints as an ordinary copy sync. - changes (cond-> changes - (some #(ctk/touched-group? % :geometry-group) orig-touched) - (cll/generate-sync-shape-direct - nil libraries (assoc container :objects (pcb/get-objects changes)) - (:id new-shape) false))] + changes (cond-> changes + (some #(ctk/touched-group? % :geometry-group) orig-touched) + (cll/generate-sync-shape-direct + nil libraries (assoc container :objects (pcb/get-objects changes)) + (:id new-shape) false))] [changes (mapv (comp :parent-id :new) pairs)])) (defn- shape-index diff --git a/common/test/common_tests/logic/variants_switch_test.cljc b/common/test/common_tests/logic/variants_switch_test.cljc index 57cb460738..8d93bae933 100644 --- a/common/test/common_tests/logic/variants_switch_test.cljc +++ b/common/test/common_tests/logic/variants_switch_test.cljc @@ -16,6 +16,8 @@ [app.common.math :as mth] [app.common.test-helpers.components :as thc] [app.common.test-helpers.composable.comp.nodes :as n] + [app.common.test-helpers.composable.comp.runner :as r] + [app.common.test-helpers.composable.core :as tm] [app.common.test-helpers.compositions :as tho] [app.common.test-helpers.files :as thf] [app.common.test-helpers.ids-map :as thi] @@ -31,6 +33,31 @@ (t/use-fixtures :each thi/test-fixture) +(t/deftest switching-an-untouched-rotated-copy-authors-its-retained-orientation + (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 :m01 45)) r/settle) + before (tm/resolve-shape initial :copy01) + 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))) + file (tm/file switched) + full (:file (r/sync-cascade file {} (keys (get-in file [:data :components]))))] + (t/is (empty? (:touched before))) + (t/is (mth/close? 45 (:rotation before) 0.001)) + (t/is (= #{:geometry-group} (:touched head))) + (t/is (mth/close? 45 (:rotation head) 0.001)) + (t/is (gsh/close-attrs? :points (:points head) + (:points (ths/get-shape-by-id full (:id head))) 0.001)) + (t/is (gsh/close-attrs? :points (:points child) + (:points (ths/get-shape-by-id full (:id child))) 0.001)))) + (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}