From 10f573b327672adeb206ec471070f0e848ec6cd5 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Sat, 14 Nov 2026 00:54:42 +0100 Subject: [PATCH] :bug: Fill a grid copy's own cells in main layer order on ungroup Ungrouping in a grid main brings the group's shapes into each copy as well. A copy with its own cells gave them its free cells in the order the main's grid flows them, while sync gives such a copy's new children its free cells in the main's layer order, so the result depended on the path. The ungroup now uses the main's layer order too. Benchmark (lower quantile, ms): | world | baseline | now | mean | ratio | |------------------------------------+----------+---------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 22.979 | 26.978 | 0.65 | | edit-through-a-chain-of-dependents | 68.931 | 43.948 | 50.432 | 0.64 | | library-update-into-copies | 83.083 | 51.875 | 58.852 | 0.62 | | main-edit-among-many-shapes | 4.837 | 2.911 | 3.140 | 0.60 | | main-edit-into-10-copies | 1.79 | 1.160 | 1.245 | 0.65 | | main-edit-into-100-copies | 15.415 | 11.340 | 11.833 | 0.74 | | main-edit-into-1000-copies | 153.086 | 110.971 | 121.066 | 0.72 | | variant-switch-into-copies | 32.052 | 24.935 | 29.875 | 0.78 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/groups.cljc | 15 ++++++++++++++- .../common_tests/logic/composable_gen_test.cljc | 8 ++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) 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]]}))))