From 3beb329bc79eaa16137249ae37f8fdfabcc06d41 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Mon, 2 Nov 2026 22:53:04 +0100 Subject: [PATCH] :bug: Carry a copy child's flip over a variant switch A switch carries the geometry overrides that both variants agree on, but the flip flags were not among the attributes it may keep, and the carried points were built with the new copy's transform. A copy child flipped horizontally kept its flipped transform after a switch while losing its flip flag and the flipped corner order. The flags now carry like the rotation, and the carried points follow the transform the switch carries. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 21.073 | 0.60 | | edit-through-a-chain-of-dependents | 68.931 | 38.55 | 0.56 | | library-update-into-copies | 83.083 | 46.597 | 0.56 | | main-edit-among-many-shapes | 4.837 | 2.177 | 0.45 | | main-edit-into-10-copies | 1.79 | 0.924 | 0.52 | | main-edit-into-100-copies | 15.415 | 10.188 | 0.66 | | main-edit-into-1000-copies | 153.086 | 93.214 | 0.61 | | variant-switch-into-copies | 32.052 | 20.662 | 0.64 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/swap.cljc | 8 ++++-- common/src/app/common/types/shape.cljc | 2 +- .../logic/composable_gen_test.cljc | 7 +++++ .../logic/variants_switch_test.cljc | 26 +++++++++++++++++++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/common/src/app/common/logic/swap.cljc b/common/src/app/common/logic/swap.cljc index 2c64dfceb3..ec3c8fff9a 100644 --- a/common/src/app/common/logic/swap.cljc +++ b/common/src/app/common/logic/swap.cljc @@ -102,11 +102,15 @@ origin (get origin-shape dimension)] (if (mth/close? origin current) prev current))) width (size :width) - height (size :height)] + height (size :height) + ;; the turn and flips the switch carries, when both variants agree on them + shape (cond-> current-shape + (gsh/close-attrs? :transform (:transform origin-shape) (:transform current-shape)) + (assoc :transform (:transform prev-shape)))] (case attr :width width :height height - (sized-geometry-value current-shape width height attr)))) + (sized-geometry-value shape width height attr)))) (defn- equal-geometry? diff --git a/common/src/app/common/types/shape.cljc b/common/src/app/common/types/shape.cljc index e48c32bdb8..cc8ce31674 100644 --- a/common/src/app/common/types/shape.cljc +++ b/common/src/app/common/types/shape.cljc @@ -596,7 +596,7 @@ :hidden :masked-group :fills :proportion :proportion-lock :constraints-h :constraints-v :fixed-scroll :r1 :r2 :r3 :r4 :rotation :opacity :grids :exports :strokes :blend-mode :interactions :shadow :blur :background-blur :grow-type :applied-tokens - :plugin-data}) + :plugin-data :flip-x :flip-y}) (def ^:private allowed-shape-geom-attrs #{:x :y :width :height}) (def ^:private allowed-shape-base-attrs #{:id :name :type :selrect :points :transform diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 9573d89976..b2e91c8c5c 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1012,3 +1012,10 @@ :layout-copies true :text true}] :ops [[:rotate 15 0 0 0] [:detach 15 0 0 0] [:delete 5] [:restore 5] [:resize 14 0 0 0] [:edit 3 0 1 1] [:update-main 3]]})))) + +(t/deftest generated-switched-copy-keeps-its-childs-flip + ;; a copy child flipped horizontally keeps its flip over a variant switch + (t/is (map? (cg/run {:world [2 0 {:variants true :text-styles true :library-variants true :stale-libraries true + :library-depth 1 :library true :rich-variants true :library-text true + :layout-copies true :text true}] + :ops [[:transform 0 4 0 2] [:switch 0 0 0 0]]})))) diff --git a/common/test/common_tests/logic/variants_switch_test.cljc b/common/test/common_tests/logic/variants_switch_test.cljc index 1537260392..12fb3a0dd5 100644 --- a/common/test/common_tests/logic/variants_switch_test.cljc +++ b/common/test/common_tests/logic/variants_switch_test.cljc @@ -2326,6 +2326,32 @@ ;; The transform matrix should also be preserved (t/is (some? (:transform rect02'))))) +(t/deftest test-switch-with-flip-override + ;; a flip of the copy's child is a geometry override that both variants + ;; agree on, so it carries like a rotation + (let [file (-> (thf/sample-file :file1) + (thv/add-variant-with-child + :v01 :c01 :m01 :c02 :m02 :r01 :r02 + {:child1-params {:width 100 :height 50} + :child2-params {:width 100 :height 50}}) + (thc/instantiate-component :c01 :copy01 :children-labels [:copy-r01])) + page (thf/current-page file) + rect01 (ths/get-shape file :copy-r01) + changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(:id rect01)} + #(gsh/transform-shape % (ctm/resize-modifiers (gpt/point -1 1) (gsh/shape->center %))) + (:objects page) + {}) + file (thf/apply-changes file changes) + flipped (ths/get-shape file :copy-r01) + file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true}) + page' (thf/current-page file') + rect02' (get-in page' [:objects (-> (ths/get-shape file' :copy02) :shapes first)])] + (t/is (true? (:flip-x flipped))) + (t/is (true? (:flip-x rect02'))) + (t/is (= (:transform flipped) (:transform rect02'))) + (t/is (gsh/close-attrs? :points (:points flipped) (:points rect02'))))) + (t/deftest test-switch-with-rotation-different-variants (let [;; ==== Setup file (-> (thf/sample-file :file1)