diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index c4cc9d37e1..cc91a5a61a 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -1459,6 +1459,17 @@ (and main (some #(not= (get shape %) (get main %)) [:constraints-h :constraints-v :fixed-scroll])) (update :touched ctk/set-touched-group :constraints-group)))) +(defn- author-pushed-constraints + "A shape pushed below a swap keeps the constraints the copy showed, + authored when they differ from those of its new `reference`." + [shape reference] + (cond-> shape + (and reference + (some #(not= (cond-> (get shape %) (= % :fixed-scroll) boolean) + (cond-> (get reference %) (= % :fixed-scroll) boolean)) + [:constraints-h :constraints-v :fixed-scroll])) + (update :touched ctk/set-touched-group :constraints-group))) + (defn- same-pushed-value? "Whether a pushed shape's `value` of `attr` shows as its reference's `other`: no fills or strokes and an empty list of them look the same." @@ -1615,7 +1626,9 @@ (let [shape (cond-> (follow-position shape) (and (= (:id shape) (:id new-head)) (seq placement)) (update :touched (fnil into #{}) placement))] - (author-pushed-content shape (get position-objects (:shape-ref shape))))) + (cond-> (author-pushed-content shape (get position-objects (:shape-ref shape))) + (not= (:id shape) (:id new-head)) + (author-pushed-constraints (get position-objects (:shape-ref shape)))))) positioned)) new-shapes) diff --git a/common/src/app/common/test_helpers/composable/shadow.cljc b/common/src/app/common/test_helpers/composable/shadow.cljc index 511ae15054..2f6bcbda75 100644 --- a/common/src/app/common/test_helpers/composable/shadow.cljc +++ b/common/src/app/common/test_helpers/composable/shadow.cljc @@ -572,6 +572,12 @@ (not (same-value? shape :constraints-group (values content-main :constraints-group)))) (assoc :constraints-group (values shape :constraints-group)) + ;; a shape below a pushed swap keeps the constraints the copy showed + (and content? (not pushed-swap?) content-main + (= (:component-id ref) (:component-id content-main)) + (not (same-value? shape :constraints-group (values content-main :constraints-group)))) + (assoc :constraints-group (values shape :constraints-group)) + (seq placement) (merge (into {} (map (fn [group] [group (if (= :geometry-group group) geometry (values shape group))])) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 8454196a6f..bd79c04745 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2469,6 +2469,16 @@ :layout-copies false}] :ops [[:transform 0 10 0 8] [:apply-token 12 11] [:style 12 3 0 1] [:token-value 0 2]]})))) +(t/deftest an-update-main-of-a-swap-keeps-the-constraints-its-children-showed + ;; a swap pushed inside a copy of the main takes the place of a board whose + ;; icon scrolls fixed; the pushed icon keeps the copy's constraints as an + ;; override of its new reference + (t/is (map? (cg/run {:world [3 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 [[:variant-property 0 9 3 0] [:switch 4] [:combine 2] [:switch 8] [:style 11 7 1] + [:update-main 2 0 0 0]]})))) + (t/deftest a-token-edit-keeps-the-square-corner-of-a-mirrored-copy ;; a copy mirrored horizontally takes its main's radius tokens on the ;; corners it shows them on, so a token edit leaves the corner its main