🐛 Push the layout child attributes a copy authored outside a layout

A copy can set the margin of a nested copy in a flex, and a switch can
carry that override under a parent that is no layout. Update-main moved
the touched layout item group to the main, but not its value: only a
layout parent pushes the layout child attributes of its children. The
main took the override without the copy's margin. Update-main now pushes
the layout child attributes the copy authored when the main's parent is
no layout, except at the copy root.

Test: updating-a-main-pushes-a-margin-a-switch-carried-out-of-a-layout
(the variant gate program of round 14, seed 371855618).
Common suite: 2436 tests, 0 failures.

Benchmark (scripts/bench-components, ms, lower 2.5% quantile):
|                             :world | :baseline |    :now |   :mean | :ratio |
|------------------------------------+-----------+---------+---------+--------|
|  deepest-edit-through-three-levels |    35.215 |  24.588 |  26.788 |    0.7 |
| edit-through-a-chain-of-dependents |    68.931 |   45.07 |  48.822 |   0.65 |
|         library-update-into-copies |    83.083 |  53.351 |  60.769 |   0.64 |
|        main-edit-among-many-shapes |     4.837 |   2.871 |    3.13 |   0.59 |
|           main-edit-into-10-copies |      1.79 |   1.153 |   1.216 |   0.64 |
|          main-edit-into-100-copies |    15.415 |  10.844 |  11.122 |    0.7 |
|         main-edit-into-1000-copies |   153.086 | 108.081 | 112.553 |   0.71 |
|         variant-switch-into-copies |    32.052 |  23.078 |  29.003 |   0.72 |

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-11 10:16:33 +01:00
parent ed24eaa1b6
commit f7627ec5e0
2 changed files with 28 additions and 2 deletions

View File

@ -113,6 +113,8 @@
(declare set-touched)
(declare change-remote-synced)
(declare update-attrs)
(declare attr-operations)
(declare add-update-attr-changes)
(declare update-grid-main-attrs)
(declare update-grid-copy-attrs)
(declare update-layout-children)
@ -983,7 +985,8 @@
pairs with: the copy's values, overrides included, go into the main, and
its touched groups move there (the copy keeps a swap). A geometry that
sync kept for the copy (`:kept?`) is not the copy's, so the main keeps
its own."
its own. A layout parent pushes the layout child attributes of its
children; under any other parent, those the copy authored go alone."
[changes {:keys [container main-container root-inst root-main remote-synced inherited-turn kept? keep-name?]} shape-inst shape-main]
(let [;; the root of a variant keeps its name, and the copy its override of it
keep-name? (and keep-name? (= (:id shape-inst) (:id root-inst)))
@ -996,13 +999,25 @@
root-main))
;; the axes a layout sized that take the pushed size, fixed as a resize fixes them
fixed (when-not kept? (pushed-size-sizing (:objects main-container) shape-main
(:objects container) shape-inst source))]
(:objects container) shape-inst source))
;; the layout child attributes the copy authored that no layout parent pushes
item-attrs (when (and (not= (:id shape-inst) (:id root-inst))
(not (ctsl/any-layout? (:objects main-container) (:parent-id shape-main))))
(into #{}
(filter #(and (ctk/touched-group? shape-inst (ctk/resolve-sync-group (:type shape-inst) %))
(not= (get shape-inst %) (get shape-main %))))
layout-child-attrs))
[item-roperations item-uoperations]
(attr-operations shape-main #(when (contains? item-attrs %) [[% (get shape-inst %)]])
item-attrs)]
(cond-> (-> changes
(update-attrs shape-main
source
root-main
(cond-> root-inst (some? inherited-turn) inherited-turn)
main-container false)
(cond-> (seq item-roperations)
(add-update-attr-changes shape-main main-container item-roperations item-uoperations))
;; the copy keeps the sizing it pushed
(cond-> (seq fixed)
(-> (set-sizing main-container shape-main fixed)

View File

@ -2219,6 +2219,17 @@
[:add-variant] [:combine] [:add-variant] [:combine] [:update-main]
[:nest 13]]}))))
(t/deftest updating-a-main-pushes-a-margin-a-switch-carried-out-of-a-layout
(t/is (map? (cg/run {:world [3 2 {:variants true :text-styles true :layout :flex :variant-diff false
:layout-item-margins false :grid-square false :rich-variants true
:layout-children false :grid-empty false :layout-copies true :text true}]
:ops [[:combine 10] [:add-variant 3] [:combine 1] [:rotate 8] [:combine 13] [:combine 8]
[:delete 3] [:restore] [:add-variant 4] [:switch 24] [:switch] [:combine 18]
[:style 17 0 15] [:remove-child] [:remove-child 22] [:make-variant] [:combine]
[:style 22 27] [:text-style 7 0 1] [:detach 20] [:transform 14 0 0 8]
[:add-variant] [:switch 22] [:duplicate 1] [:detach 20] [:text-style 23 0 1]
[:switch 6] [:update-main 22]]}))))
(t/deftest pushing-a-grid-direction-orders-the-copies-like-the-reflowed-main
(t/is (map? (cg/run {:world [3 2 {:variants true :text-styles false :layout :grid :variant-diff false
:layout-item-margins false :grid-square true :rich-variants false