From 66c254fbc6d91003432e4e0d164490c61aa39455 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 23 Oct 2026 19:38:52 +0200 Subject: [PATCH] :bug: Keep a plain swap's inherited orientation through sync A plain swap also retains orientation inherited from its old component. Record that retained orientation as geometry when it differs from the new component's expected placement. Parent-derived orientation stays untouched and size-only overrides still clear. The regression fails before the fix. The swap suite passes 41 tests / 162 assertions; the seeded MVP property also passes 100 scenarios. Benchmark vs Phase 1e: main 10/100/1000 0.54/0.57/0.66; levels 0.60; chain 0.62; library 0.67; many shapes 0.83; switch 0.77. No flags. AI-assisted-by: GPT-6 --- common/src/app/common/logic/variants.cljc | 10 +++++----- common/test/common_tests/logic/swap_group_test.cljc | 12 ++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) 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)))))