From 0e812b1f5e5ec949335edd743c2f4917e539147f Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 4 Nov 2026 05:15:29 +0100 Subject: [PATCH] :bug: Keep the inherited turn of a switched copy child without an override A switch keeps an orientation that the copy, or a shape along its reference chain, authored when both variants share it, and compares it with the new copy's own orientation instead of the place its position gives it. Any geometry override along the chain counted as authoring it, so a copy child whose position main was only resized carried the turn it inherits from its turned copy parent, and the switch marked that inherited turn as a geometry override. The orientation is carried only when it differs from its component's orientation turned and flipped with its parent; an inherited one is compared with the place its position gives it. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 19.316 | 0.55 | | edit-through-a-chain-of-dependents | 68.931 | 39.369 | 0.57 | | library-update-into-copies | 83.083 | 45.503 | 0.55 | | main-edit-among-many-shapes | 4.837 | 2.125 | 0.44 | | main-edit-into-10-copies | 1.79 | 0.933 | 0.52 | | main-edit-into-100-copies | 15.415 | 9.092 | 0.59 | | main-edit-into-1000-copies | 153.086 | 92.629 | 0.61 | | variant-switch-into-copies | 32.052 | 20.538 | 0.64 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/variants.cljc | 16 +++++++++++++++- .../common_tests/logic/composable_gen_test.cljc | 7 +++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/common/src/app/common/logic/variants.cljc b/common/src/app/common/logic/variants.cljc index 487bfb6962..e11f0cb5cc 100644 --- a/common/src/app/common/logic/variants.cljc +++ b/common/src/app/common/logic/variants.cljc @@ -534,10 +534,24 @@ new-ldata (or (get-in libraries [(:component-file new-shape) :data]) ldata) new-main (ctf/get-component-root new-ldata (ctkl/get-component new-ldata (:component-id new-shape))) ;; An authored orientation carries only where both variants share it + parent (get page-objects (:parent-id original-shape)) + ref-parent (get orig-ref-objects (:parent-id orig-base-ref-shape)) + ;; Whether the switched copy's orientation is authored along its + ;; reference chain, not just its component's turned with its parent + authored-orientation? (let [flip (fn [key] + (odd? (count (filter identity [(get orig-base-ref-shape key) (get parent key) + (get ref-parent key)]))))] + (or (not (mth/close? (mod (or (:rotation original-shape) 0) 360) + (mod (+ (or (:rotation orig-base-ref-shape) 0) + (- (or (:rotation parent) 0) (or (:rotation ref-parent) 0))) + 360) + 0.01)) + (not= (boolean (:flip-x original-shape)) (flip :flip-x)) + (not= (boolean (:flip-y original-shape)) (flip :flip-y)))) carried-orientation? (and (some #(and (= (:id %) (:id original-shape)) (ctk/touched-group? % :geometry-group)) orig-touched) + authored-orientation? (same-orientation? orig-base-ref-shape new-main)) - parent (get page-objects (:parent-id original-shape)) ;; A switch keeps orientation even when the old main supplied it. ;; If no orientation was carried, placement from an enclosing copy is ;; still inherited rather than authored by this switch. diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 6b0550c543..92a277349e 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1070,3 +1070,10 @@ (t/is (map? (cg/run {:world [2 0 {:variants true :text-styles true :library true :rich-variants true :layout-copies true :text true}] :ops [[:nest 4 0 0 0] [:transform 1 0 0 3] [:switch 3 0 0 0]]})))) + +(t/deftest generated-switch-keeps-the-inherited-turn-of-a-copy-child + ;; a copy child of a turned copy, whose position main is resized, keeps + ;; the turn it inherits through a switch without an override + (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :variant-diff false :rich-variants true + :layout-copies true :text true}] + :ops [[:resize 0 0 0 0] [:rotate 1 0 0 0] [:switch 4 0 0 0]]}))))