diff --git a/common/src/app/common/logic/groups.cljc b/common/src/app/common/logic/groups.cljc index 5a48a7eb23..fb822de52c 100644 --- a/common/src/app/common/logic/groups.cljc +++ b/common/src/app/common/logic/groups.cljc @@ -212,6 +212,19 @@ (recur (concat (rest pending) (map second hits)) (into result hits))) result)))) +(defn- assign-ungrouped-cells + "`grid` with the cells of the children an ungroup brings into it assigned. + A copy with its own cells gives its free cells to them in the layer + order of its main, as sync does, which is the reverse of the order the + main's grid flows them in." + [grid objects] + (if (ctk/touched-group? grid :layout-grid-cells) + (-> grid + (update :shapes (comp vec reverse)) + (ctl/assign-cells objects) + (assoc :shapes (:shapes grid))) + (ctl/assign-cells grid objects))) + (defn- ungroup-shape-changes "The changes that ungroup the group, bool or board `shape-id` of the page `page-id`, whose shapes are `objects`; `options` of the moves and @@ -228,7 +241,7 @@ (cond-> changes (and changes (ctl/grid-layout? objects (:parent-id shape))) - (pcb/update-shapes [(:parent-id shape)] ctl/assign-cells + (pcb/update-shapes [(:parent-id shape)] assign-ungrouped-cells (merge {:with-objects? true} (select-keys options [:ignore-touched])))))) (defn generate-ungroup-changes diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 55c97d8240..75b80b7c9b 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -4307,3 +4307,11 @@ :grid-square false :library true :rich-variants true :layout-children false :grid-empty false :layout-copies false :text true}] :ops [[:switch 11] [:switch 5] [:nest 17] [:add-child 15] [:rotate 15] [:style 12 9 1] [:paste 12]]})))) + +(t/deftest generated-an-ungroup-fills-a-grid-copy-with-its-own-cells-in-main-layer-order + ;; shapes an ungroup in a grid main brings into a copy with its own cells + ;; take its free cells in the main's layer order, as sync gives them + (t/is (map? (cg/run {:world [2 2 {:variants true :rich-variants true :text true :layout :grid + :layout-copies true :layout-children true}] + :ops [[:add-child 8] [:structure 2 4 15] [:grid-direction 0 0 0 1] [:grid-cell 0 0 0 1] + [:add-child 0] [:structure 0 2 0]]}))))