diff --git a/common/src/app/common/logic/variants.cljc b/common/src/app/common/logic/variants.cljc index 0fe59d6074..82cb43fe06 100644 --- a/common/src/app/common/logic/variants.cljc +++ b/common/src/app/common/logic/variants.cljc @@ -445,9 +445,9 @@ (when-let [parent (get objects parent-id)] (or (d/index-of (:shapes parent) shape-id) 0))) -(defn- keep-authored-orientation - "A plain swap drops content overrides, but keeps an authored rotation or - flip as geometry so a later sync does not remove its retained placement." +(defn- keep-orientation-override + "A plain swap keeps its old orientation. When that differs from the new + component's expected placement, the swap authors a geometry override." [changes shape baseline page ldata component-id] (let [parent (get-in page [:objects (:parent-id shape)]) main (ctf/get-component-root ldata (ctkl/get-component ldata component-id)) @@ -465,7 +465,7 @@ (not= (boolean (:flip-x shape)) (flip :flip-x)) (not= (boolean (:flip-y shape)) (flip :flip-y)))] (cond-> changes - (and (ctk/touched-group? shape :geometry-group) changed?) + changed? (pcb/update-shapes [(:id shape)] #(update % :touched (fnil conj #{}) :geometry-group) {:ignore-touched true})))) @@ -494,7 +494,7 @@ [changes parents-of-swapped] (if keep-touched? (generate-keep-touched changes new-shape shape orig-shapes page libraries ldata) - [(keep-authored-orientation changes shape new-shape page ldata component-id) []]) + [(keep-orientation-override changes shape new-shape page ldata component-id) []]) ;; Replacement keeps the head id and its cell. Cleanup during the ;; temporary deletion must not change the parent's placement data. diff --git a/common/test/common_tests/logic/swap_group_test.cljc b/common/test/common_tests/logic/swap_group_test.cljc index 25debb2faf..f5e4df5d25 100644 --- a/common/test/common_tests/logic/swap_group_test.cljc +++ b/common/test/common_tests/logic/swap_group_test.cljc @@ -734,3 +734,15 @@ (t/is (mth/close? 0 (:rotation child) 0.001)) (t/is (= #{:swap-group} (:touched head))) (t/is (nil? (:touched child))))) + +(t/deftest plain-swap-keeps-the-orientation-inherited-from-its-old-component + (let [initial (-> (tm/make-situation (setup-sized)) + (r/step (n/rotate :star-main 45)) r/settle) + swapped (-> initial (r/step (n/swap-shape :card-star :heart)) r/settle) + head (tm/resolve-shape swapped :card-star) + file (tm/file swapped) + full (:file (r/sync-cascade file {} (keys (get-in file [:data :components]))))] + (t/is (nil? (:touched (tm/resolve-shape initial :card-star)))) + (t/is (ctk/touched-group? head :geometry-group)) + (t/is (mth/close? 45 (:rotation head) 0.001)) + (t/is (= (orientation file :card-star) (orientation full :card-star)))))