diff --git a/common/src/app/common/logic/variants.cljc b/common/src/app/common/logic/variants.cljc index e3d28f7c8e..d5bd2b1298 100644 --- a/common/src/app/common/logic/variants.cljc +++ b/common/src/app/common/logic/variants.cljc @@ -568,10 +568,14 @@ :include-deleted? true :with-context? true)) changes (keep-orientation-override changes original-shape new-shape page new-ldata (:component-id new-shape) position) - ;; A carried size changes the frame its untouched children follow. - ;; Place them through the same constraints as an ordinary copy sync. + ;; A kept child whose swap ended is a plain copy of its new position + ended-swap? (some (fn [{:keys [old swapped?]}] + (and swapped? (not (ctk/swapped? (get (pcb/get-objects changes) (:id old)))))) + pairs) + ;; A carried size changes the frame its untouched children follow, + ;; and an ended swap shows its position: both sync as an ordinary copy. changes (cond-> changes - (some #(ctk/touched-group? % :geometry-group) orig-touched) + (or ended-swap? (some #(ctk/touched-group? % :geometry-group) orig-touched)) (cll/generate-sync-shape-direct nil libraries (assoc container :objects (pcb/get-objects changes)) (:id new-shape) false)) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 1c14c77c94..c215f96249 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1792,6 +1792,14 @@ :ops [[:grid-cell 1 0 0 0] [:delete 5 0 0 0] [:make-variant 4 0 0 0] [:variant-property 0 0 0 0] [:switch 9]]})))) +(t/deftest a-swap-a-switch-ends-shows-its-new-position + (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout nil :variant-diff false + :layout-item-margins false :grid-square false :rich-variants true + :layout-children false :grid-empty false :layout-copies true :text true}] + :ops [[:swap 8 0 0 0] [:resize 0 0 0 0] [:make-variant 7] [:switch 6] + [:combine 13 0 0 0] [:variant-property 0 0 0 0] [:switch 13] [:make-variant 0] + [:switch 0] [:make-variant 2 0 0 0] [:make-variant 0] [:switch 16]]})))) + (t/deftest random-variant-compositions (let [coverage (atom {}) failure (atom nil)] diff --git a/common/test/common_tests/logic/swap_group_test.cljc b/common/test/common_tests/logic/swap_group_test.cljc index 7dd6d90214..3686e0ea97 100644 --- a/common/test/common_tests/logic/swap_group_test.cljc +++ b/common/test/common_tests/logic/swap_group_test.cljc @@ -431,6 +431,18 @@ (t/is (not (ctk/swapped? head))) (t/is (= (:id (thc/get-component file :heart)) (:component-id head))))) +(t/deftest switch-to-a-variant-with-the-same-component-takes-its-values + ;; the ended swap makes the head a plain copy of its new position, so it + ;; shows what the main authored there + (let [file (-> (setup-variants) + (tho/swap-component-in-shape :child2 :heart) + (set-opacity :child2 0.3) + (tho/swap-component-in-shape :copy01 :c02 {:keep-touched? true})) + head (ths/get-shape file :copy-child)] + (t/is (= (thi/id :child2) (:shape-ref head))) + (t/is (= 0.3 (:opacity head))) + (t/is (not (ctk/touched-group? head :layer-effects-group))))) + (t/deftest switch-to-a-variant-with-the-same-component-refers-to-its-children (let [file (-> (setup-variants) (tho/swap-component-in-shape :child2 :heart)