diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 76bf10af2a..c5212ea541 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -1373,18 +1373,32 @@ (assoc :id (:id parent-main) :shape-ref (:shape-ref parent-main))))) + ;; the layout child groups the copy authored under a parent with no + ;; layout, which stay with the copy as an update of a pair keeps them + kept-items (fn [shape] + (let [layout? (if (= (:id shape) (:id child-inst)) + (ctsl/any-layout? parent-main) + (ctsl/any-layout? (:objects container) (:parent-id shape)))] + (when-not (or layout? (= (:id shape) (:id root-inst))) + (set/intersection (set (:touched shape)) + (into #{} (map #(ctk/resolve-sync-group (:type shape) %)) + layout-child-attrs))))) + update-new-shape (fn [new-shape original-shape] (cond-> (in-main new-shape) (and (= (:id original-shape) (:id child-inst)) (ctk/swapped? child-inst) (not swap-in-copy?)) - (rehead-pushed-swap content-main placement-container))) + (rehead-pushed-swap content-main placement-container) + + (seq (kept-items original-shape)) + (update :touched #(not-empty (set/difference % (kept-items original-shape)))))) ;; the copy now follows the main, swap included update-original-shape (fn [original-shape new-shape] (-> original-shape (assoc :shape-ref (:id new-shape)) - (dissoc :touched))) + (assoc :touched (not-empty (kept-items original-shape))))) [new-head new-shapes updated-shapes] (ctst/clone-shape child-inst diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index cb885f591a..c0f87fb10d 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2393,6 +2393,15 @@ :grid-empty false :layout-copies true :text false}] :ops [[:style 8 35 1] [:style 0 29 1] [:update-main]]})))) +(t/deftest updating-a-main-keeps-the-max-width-override-a-switched-copy-holds + (t/is (map? (cg/run {:world [3 2 {:variants true :text-styles false :layout :grid :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 [[:nest 1 0 0 6] [:text 2] [:combine 3 0 0 16] [:style 14 32] [:delete] [:restore] + [:add-variant 20 0] [:add-variant 20] [:update-main 3 0 0] [:grid-cell 11 6] + [:add-variant 0 0 0 16] [:variant-property 0 19 12] [:switch 20] [:edit 6 0 0 1] + [:update-main 6]]})))) + (t/deftest updating-a-main-pushes-a-swapped-shape-nested-in-a-swap-with-its-children (t/is (map? (cg/run {:world [3 3 {:variants true :text-styles true :scale true :layout :flex :variant-diff true :grid-square false :copies 5 :rich-variants true :layout-children true