From d4f466dfab188c0605c334546f1a9b9876bdbbc0 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 23 Oct 2026 19:11:24 +0200 Subject: [PATCH] :bug: Keep authored rotation through a plain component swap Retain geometry touched when a plain swap keeps authored orientation, so a later sync preserves it. Size-only and content overrides still clear. Red regression reproduced; swap suite passes 39 tests / 154 assertions. Benchmark vs Phase 1e: main 10/100/1000 0.51/0.64/0.65; levels 0.50; chain 0.57; library 0.53; many shapes 0.47; switch 0.59. No flags. AI-assisted-by: GPT-6 --- common/src/app/common/logic/variants.cljc | 28 ++++++++++++++++++- .../common_tests/logic/swap_group_test.cljc | 23 +++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/common/src/app/common/logic/variants.cljc b/common/src/app/common/logic/variants.cljc index 7ffb64d163..0fe59d6074 100644 --- a/common/src/app/common/logic/variants.cljc +++ b/common/src/app/common/logic/variants.cljc @@ -12,6 +12,7 @@ [app.common.logic.shapes :as cls] [app.common.logic.swap :as clsw] [app.common.logic.variant-properties :as clvp] + [app.common.math :as mth] [app.common.path-names :as cpn] [app.common.types.component :as ctk] [app.common.types.components-list :as ctkl] @@ -444,6 +445,31 @@ (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." + [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)) + main-parent (get-in (ctf/get-component-container ldata (ctkl/get-component ldata component-id)) + [:objects (:parent-id main)]) + parent-delta (if (:shape-ref parent) 0 + (- (or (:rotation parent) 0) (or (:rotation main-parent) 0))) + rotation (mod (+ (or (:rotation baseline) 0) parent-delta) 360) + flip (fn [key] + (if (:shape-ref parent) + (boolean (get baseline key)) + (odd? (count (filter identity [(get baseline key) (get parent key) + (get main-parent key)]))))) + changed? (or (not (mth/close? (mod (or (:rotation shape) 0) 360) rotation 0.01)) + (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?) + (pcb/update-shapes [(:id shape)] + #(update % :touched (fnil conj #{}) :geometry-group) + {:ignore-touched true})))) + (defn generate-component-swap-in-place "Swap the copy head `shape` of `page` for a copy of the component `component-id` of library data `ldata`. The new head takes the old one's @@ -468,7 +494,7 @@ [changes parents-of-swapped] (if keep-touched? (generate-keep-touched changes new-shape shape orig-shapes page libraries ldata) - [changes []]) + [(keep-authored-orientation 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 d6df6d007d..2f1a5942b4 100644 --- a/common/test/common_tests/logic/swap_group_test.cljc +++ b/common/test/common_tests/logic/swap_group_test.cljc @@ -698,3 +698,26 @@ (propagate :card) (thf/validate-file!))] (t/is (== 10 (:rotation (orientation file' :copy-star)))))) + +(t/deftest plain-swap-keeps-authored-rotation-as-a-geometry-override + (doseq [target [:plain-star :card-star :copy-star]] + (let [initial (tm/make-situation (setup-sized)) + rotated (-> initial (r/step (n/rotate target 45)) r/settle + (r/step (n/change-property target :opacity 0.4)) r/settle) + swapped (-> rotated (r/step (n/swap-shape target :heart)) r/settle) + head (tm/resolve-shape swapped target) + file (tm/file swapped) + full (:file (r/sync-cascade file {} (keys (get-in file [:data :components]))))] + (t/is (ctk/touched-group? head :geometry-group)) + (t/is (== 45 (:rotation head))) + (t/is (not (ctk/touched-group? head :layer-effects-group))) + (t/is (= 1 (:opacity head 1))) + (t/is (= (orientation file target) (orientation full target)))))) + +(t/deftest plain-swap-drops-a-size-only-override + (let [situation (-> (tm/make-situation (setup-sized)) + (r/step (n/change-height :plain-star 80)) r/settle + (r/step (n/swap-shape :plain-star :heart)) r/settle) + head (tm/resolve-shape situation :plain-star)] + (t/is (== 40 (:height head))) + (t/is (not (ctk/touched-group? head :geometry-group)))))