🐛 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
This commit is contained in:
alonso.torres 2026-11-14 00:54:42 +01:00
parent d4471ea9fb
commit 10f573b327
2 changed files with 22 additions and 1 deletions

View File

@ -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

View File

@ -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]]}))))