🐛 Order a main grid copy's children by its cells when updating the main

An update main pushes a copy's grid direction into its main. When that
main is itself a grid copy with its own cells, sync orders its children
as they flow in those cells, but the update ordered them as the pushing
copy lists them. The next sync of that copy then reordered them with no
edit. The update now gives such a main the order of the copy's cell
flow.

Benchmark (lower quantile, ms):

| world                              | baseline |     now |    mean | ratio |
|------------------------------------+----------+---------+---------+-------|
| deepest-edit-through-three-levels  |   35.215 |  21.632 |  22.076 |  0.61 |
| edit-through-a-chain-of-dependents |   68.931 |  42.236 |  44.386 |  0.61 |
| library-update-into-copies         |   83.083 |  48.557 |  51.934 |  0.58 |
| main-edit-among-many-shapes        |    4.837 |   2.443 |   2.556 |  0.51 |
| main-edit-into-10-copies           |    1.79  |   1.129 |   1.149 |  0.63 |
| main-edit-into-100-copies          |   15.415 |  10.085 |  10.387 |  0.65 |
| main-edit-into-1000-copies         |  153.086 | 101.224 | 103.687 |  0.66 |
| variant-switch-into-copies         |   32.052 |  20.846 |  21.588 |  0.65 |

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-13 18:24:46 +01:00
parent 6eff483b22
commit 0a69ef65c2
2 changed files with 21 additions and 4 deletions

View File

@ -1143,7 +1143,7 @@
:only-main (fn [changes child-main]
(remove-shape changes child-main main-container))
:inverse? true})
(reorder-main-children shape-main children-inst @added main-container))
(reorder-main-children shape-main shape-inst children-inst @added main-container))
(ctsl/grid-layout? shape-main)
(update-grid-main-attrs shape-main shape-inst children-inst @added main-container)))))
@ -1151,9 +1151,18 @@
(defn- reorder-main-children
"Order the children of `shape-main` as the copy's `children-inst`, each by
the main shape it pairs with or the one `added` for it, in one change that
its undo reverts."
[changes shape-main children-inst added main-container]
(let [order (into [] (keep #(get added (:id %) (:shape-ref %))) children-inst)
its undo reverts. A main that is a grid copy with its own cells, once it
takes the copy's, orders them as they flow in those cells, as sync orders
such a copy."
[changes shape-main shape-inst children-inst added main-container]
(let [own-flow? (and (:shape-ref shape-main) (ctsl/grid-layout? shape-main) (ctsl/grid-layout? shape-inst)
(or (ctk/touched-group? shape-main :layout-grid-cells)
(ctk/touched-group? shape-inst :layout-grid-cells)))
children-inst (if own-flow?
(let [by-id (d/index-by :id children-inst)]
(into [] (keep by-id) (:shapes (ctsl/reorder-grid-children shape-inst))))
children-inst)
order (into [] (keep #(get added (:id %) (:shape-ref %))) children-inst)
reorder (fn [shapes]
{:type :reorder-children
:parent-id (:id shape-main)

View File

@ -4209,3 +4209,11 @@
(t/is (map? (cg/run {:world [1 1 {:variants true :rich-variants true :text false :layout :flex
:layout-copies false :layout-children true}]
:ops [[:add-child] [:add-child] [:structure 7 8] [:transform 10 20 0 17]]}))))
(t/deftest generated-updating-a-main-grid-copy-with-its-own-cells-orders-it-by-their-flow
;; an update main that turns the direction of a nested grid copy with its
;; own cells orders that copy's children as they flow in the new direction
(t/is (map? (cg/run {:world [3 2 {:variants false :layout :grid :layout-item-margins false :grid-square true
:rich-variants false :layout-children true :grid-empty false
:layout-copies false :text false}]
:ops [[:remove-child 7] [:grid-direction 13 0 7 1] [:grid-cell 0 0 0 1] [:update-main 17]]}))))