🐛 Find a swapped copy's own main when its grid direction changes

A direction change in a grid copy makes its cells an override when the
reflow moves items, and the copy's main has a grid. For a copy that
keeps another component than its main's slot, the main was looked up by
its reference, the slot's board, which has no grid: the reflow moved its
items without making the cells an override, and the next sync of its
own component's main gave it the main's cells back.

The main of a swapped head is the root of its own component, the one its
content and its cells follow.

Benchmark (scripts/bench-components, ms, lower 2.5% quantile):

| world                              | baseline |     now | ratio |
|------------------------------------+----------+---------+-------|
| deepest-edit-through-three-levels  |   35.215 |  19.155 |  0.54 |
| edit-through-a-chain-of-dependents |   68.931 |  43.042 |  0.62 |
| library-update-into-copies         |   83.083 |  50.796 |  0.61 |
| main-edit-among-many-shapes        |    4.837 |    2.12 |  0.44 |
| main-edit-into-10-copies           |     1.79 |   0.958 |  0.54 |
| main-edit-into-100-copies          |   15.415 |   9.406 |  0.61 |
| main-edit-into-1000-copies         |  153.086 |  93.765 |  0.61 |
| variant-switch-into-copies         |   32.052 |  22.183 |  0.69 |

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-07 03:28:58 +01:00
parent a9c31f8b5a
commit 56e315bd7a
2 changed files with 15 additions and 2 deletions

View File

@ -1947,7 +1947,9 @@
order. In a copy without cell overrides, a reflow that moves items makes
the cells an override, and one that moves none leaves the cells its
main gives it, laid out as sync lays them out in the new direction, so a
copy that changes its direction back has its main's cells again."
copy that changes its direction back has its main's cells again. The main
of a swapped head is the root of its own component, which its content
follows."
[file page libraries dir]
(let [container (ctn/make-container page :page)
objects (:objects page)]
@ -1958,7 +1960,7 @@
(let [reflowed (ctsl/reflow-grid-auto-items-for-direction shape from-dir dir)
main (when (and (:shape-ref shape)
(not (ctk/touched-group? shape :layout-grid-cells)))
(ctf/find-ref-shape file container libraries shape :include-deleted? true))]
(ctf/find-content-ref-shape file container libraries shape :include-deleted? true))]
(cond
(not= :grid (:layout main))
reflowed

View File

@ -1279,3 +1279,14 @@
[:nest 12 0 0 0] [:delete 6 0 0 0] [:detach 8 0 0 0] [:restore 0 0 0 0]
[:duplicate 0 0 0 0] [:transform 3 3 0 8] [:delete 0] [:restore 0]
[:edit 4 0 1 1] [:update-main 4] [:delete 0 0 0 0] [:transform 2 2 0 0]]}))))
(t/deftest generated-direction-change-in-a-swapped-copy-overrides-its-moved-cells
;; a copy that keeps another component than its main's slot takes its
;; cells from its own component's main; a direction change that moves its
;; items makes them an override, though the slot's board has no grid
(t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :library-variants true :stale-libraries true
:layout :grid :layout-item-margins false :grid-square true :library-depth 1
:library true :rich-variants true :layout-children true :library-text true
:grid-empty false :layout-copies true :text true}]
:ops [[:delete 9 0 0 0] [:delete 0] [:restore 0] [:delete 17] [:restore 17]
[:swap 4 0 0 0] [:grid-direction 0 0 1 1] [:grid-cell 0 0 0 1]]}))))