From bce5a2c5b8470939fa77d07f98df19708ec5f0d8 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 23 Oct 2026 20:46:32 +0200 Subject: [PATCH] :bug: Keep inherited placement untouched during a plain swap Compare retained orientation with the position source in copy-parent coordinates, including cached deleted mains. A rotation inherited from that source does not author a geometry override (F154). The focused regression fails before the change. Swap and variant suites pass 100 tests and 510 assertions; common lint and format pass. Benchmark ratios: mains 0.47/0.53/0.55; levels 0.51; chain 0.64; library 0.64; many shapes 0.96; switch 0.68, with no regression flags. AI-assisted-by: GPT-6 --- common/src/app/common/logic/variants.cljc | 17 ++++++++++++----- .../common_tests/logic/swap_group_test.cljc | 8 ++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/common/src/app/common/logic/variants.cljc b/common/src/app/common/logic/variants.cljc index 63409921b7..33e2351c63 100644 --- a/common/src/app/common/logic/variants.cljc +++ b/common/src/app/common/logic/variants.cljc @@ -364,16 +364,20 @@ (defn- keep-orientation-override "Retained orientation that differs from the new component's expected placement needs a geometry override to survive later sync." - [changes shape baseline page ldata component-id] + [changes shape baseline page ldata component-id position] (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 + baseline (or position baseline) + main-parent (if position + (get-in (meta position) [:container :objects (:parent-id position)]) + main-parent) + parent-delta (if (and (:shape-ref parent) (nil? position)) 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) + (if (and (:shape-ref parent) (nil? position)) (boolean (get baseline key)) (odd? (count (filter identity [(get baseline key) (get parent key) (get main-parent key)]))))) @@ -466,7 +470,7 @@ (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)))] + (:component-id new-shape) nil))] [changes (mapv (comp :parent-id :new) pairs)])) (defn- shape-index @@ -500,7 +504,10 @@ [changes parents-of-swapped] (if keep-touched? (generate-keep-touched changes new-shape shape orig-shapes page libraries ldata) - [(keep-orientation-override changes shape new-shape page ldata component-id) []]) + [(keep-orientation-override changes shape new-shape page ldata component-id + (when (:shape-ref parent) + (ctf/find-ref-shape nil page libraries shape + :include-deleted? true :with-context? true))) []]) ;; 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 5414bddf4e..66b0557dc8 100644 --- a/common/test/common_tests/logic/swap_group_test.cljc +++ b/common/test/common_tests/logic/swap_group_test.cljc @@ -797,3 +797,11 @@ (t/is (= (:shapes main) (mapv #(get-in objects [% :shape-ref]) (:shapes head)))) (t/is (= (thn/normalize-file (tm/file initial)) (thn/normalize-file (tm/file (r/step detached (n/undo)))))))) + +(t/deftest plain-swap-does-not-author-the-positions-inherited-orientation + (let [rotated (-> (tm/make-situation (setup-sized)) + (r/step (n/rotate :card-star 45)) r/settle) + swapped (-> rotated (r/step (n/swap-shape :copy-star :heart)) r/settle) + head (tm/resolve-shape swapped :copy-star)] + (t/is (mth/close? 45 (:rotation head) 0.001)) + (t/is (= #{:swap-group} (:touched head)))))