diff --git a/common/src/app/common/logic/variants.cljc b/common/src/app/common/logic/variants.cljc index e11f0cb5cc..0c3d1bd394 100644 --- a/common/src/app/common/logic/variants.cljc +++ b/common/src/app/common/logic/variants.cljc @@ -617,6 +617,20 @@ (pcb/update-shapes [(:id shape)] #(update % :touched ctk/set-touched-group :geometry-group) {:ignore-touched true})))) +(defn- keep-placement-overrides + "A switch gives the new head the `swap-keep-attrs` of the copy head + `original-shape` it replaces, and with them the overrides that authored + them." + [changes original-shape new-shape] + (let [groups (into #{} + (comp (keep #(ctk/resolve-sync-group (:type original-shape) %)) + (filter #(ctk/touched-group? original-shape %))) + ctk/swap-keep-attrs)] + (cond-> changes + (seq groups) + (pcb/update-shapes [(:id new-shape)] #(update % :touched (fnil into #{}) groups) + {:ignore-touched true})))) + (defn generate-component-swap-in-place "Swap the copy head `shape` of `page` for a copy of the component `component-id` of library data `ldata`. The new head takes the old one's @@ -650,7 +664,8 @@ changes (cond-> changes keep-touched? - (keep-moved-placement shape new-shape page libraries)) + (-> (keep-moved-placement shape new-shape page libraries) + (keep-placement-overrides shape new-shape))) ;; Replacement keeps the head id and its cell. Cleanup during the ;; temporary deletion must not change the parent's placement data. diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 7ddbe1763d..87feb781f1 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1093,3 +1093,10 @@ :ops [[:edit 18 0 0 0] [:delete 0 0 0 0] [:edit 3 0 1 1] [:update-main 3] [:update-main 0 0 0 0] [:resize 6 0 0 0] [:nest 16 0 0 0] [:swap 16 0 0 0] [:detach 2 0 0 0] [:style 8 20 2 0] [:reset 13 0 0 0]]})))) + +(t/deftest generated-switch-keeps-the-layout-item-override-it-carries + ;; a nested copy in a main with its own layout item margin keeps the + ;; margin through a switch, and the override that authors it + (t/is (map? (cg/run {:world [3 2 {:variants true :text-styles true :layout :flex :variant-diff false :rich-variants true + :layout-children true :layout-copies true :text true}] + :ops [[:delete 6 0 0 0] [:swap 20 0 0 0] [:nest 7 0 0 0] [:style 13 27 1] [:switch 0 0 0 0]]}))))