🐛 Bring a swapped component's size to a copy child with its own constraint

A copy child whose copy sets a constraint that ties one of its
dimensions to its parent keeps the geometry it shows at sync, since
the constraint applies to later resizes. That rule also held when the
main swapped the child for another component, so the child kept the
old component's 100x100 while the other copies showed the new 120x140,
and update mains then pushed the old size into the main.

The child keeps its geometry only while it shows its main's component;
a swap reaching it brings the new component's size.

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

| world                              | baseline |     now | ratio |
|------------------------------------+----------+---------+-------|
| deepest-edit-through-three-levels  |   35.215 |  20.406 |  0.58 |
| edit-through-a-chain-of-dependents |   68.931 |  38.828 |  0.56 |
| library-update-into-copies         |   83.083 |  50.763 |  0.61 |
| main-edit-among-many-shapes        |    4.837 |   2.508 |  0.52 |
| main-edit-into-10-copies           |     1.79 |   1.013 |  0.57 |
| main-edit-into-100-copies          |   15.415 |   9.418 |  0.61 |
| main-edit-into-1000-copies         |  153.086 |  91.613 |  0.60 |
| variant-switch-into-copies         |   32.052 |  21.561 |  0.67 |

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-03 16:53:04 +01:00
parent 5f4ef66314
commit a3afd4cd76
2 changed files with 13 additions and 3 deletions

View File

@ -647,9 +647,11 @@
"Whether the copy shape `shape-inst` keeps the geometry it shows at sync:
its copy authors a constraint that ties one of its dimensions to its copy
parent. A constraint applies to the resizes after it, so sync does not
resize the shape through it again."
[container shape-inst]
resize the shape through it again. A swap reaching the shape from its
main (`shape-main` shows another component) brings the new size."
[container shape-inst shape-main]
(and (ctk/touched-group? shape-inst :constraints-group)
(= (:component-id shape-inst) (:component-id shape-main))
(or (contains? #{:scale :leftright} (:constraints-h shape-inst))
(contains? #{:scale :topbottom} (:constraints-v shape-inst)))
(some? (:shape-ref (ctn/get-shape container (:parent-id shape-inst))))))
@ -682,7 +684,7 @@
(ctk/touched-group? shape-inst :layout-grid-cells))
placed (cond
(and (not reset?) (or (ctk/touched-group? shape-inst :geometry-group)
(constraint-kept? container shape-inst)))
(constraint-kept? container shape-inst shape-main)))
(in-main-frame shape-inst (:root-inst ctx) (:root-main ctx))
(and (not reset?) (= (:id shape-inst) (:id (:root-inst ctx))))

View File

@ -1048,3 +1048,11 @@
(t/is (map? (cg/run {:world [2 0 {:text true :text-styles true}]
:ops [[:resize 2 0 0 0] [:detach 3 0 0 0] [:detach 11 0 0 0] [:rotate 10 0 0 0]
[:update-main 0 0 0 0] [:transform 0 0 0 12] [:update-main 7 0 0 0]]}))))
(t/deftest generated-swap-brings-its-size-to-a-copy-child-with-its-own-constraint
;; a copy child with its own scale constraint takes the size of the
;; component its main swaps it for, as the other copies do
(t/is (map? (cg/run {:world [2 1 {:variants true :text-styles true :library true
:rich-variants true :layout-copies true :text true}]
:ops [[:style 24 8 1] [:swap 2 0 0 0] [:edit 3 0 1 1] [:update-main 3]
[:update-main 0 0 0 0]]}))))