🐛 Give a pushed swap that copies its position the position's size

When update-main pushes a swap into a nested copy in the main, and the
position there holds the same component, the pushed head becomes a plain
copy of that position, and its children already follow the position. The
head itself kept the size of the pushed copy with no geometry override, so
a later sync would resize it. It now takes the position's size about its
first corner, unless the child it replaces authored its geometry, as a
switch back to the position already does.

Test: updating-a-main-with-a-swap-to-its-position-component-gives-the-head-
the-positions-size, the variant gate program of round 11 (seed 371855618).
Common suite: 2419 tests, 0 failures.

Benchmark (scripts/bench-components, ms, lower 2.5% quantile):
|                             :world | :baseline |    :now |  :mean | :ratio |
|------------------------------------+-----------+---------+--------+--------|
|  deepest-edit-through-three-levels |    35.215 |  21.869 | 23.349 |   0.62 |
| edit-through-a-chain-of-dependents |    68.931 |  43.052 | 43.454 |   0.62 |
|         library-update-into-copies |    83.083 |  50.967 | 52.007 |   0.61 |
|        main-edit-among-many-shapes |     4.837 |   2.149 |  2.267 |   0.44 |
|           main-edit-into-10-copies |      1.79 |   1.067 |  1.097 |    0.6 |
|          main-edit-into-100-copies |    15.415 |  10.265 | 10.455 |   0.67 |
|         main-edit-into-1000-copies |   153.086 | 102.631 | 107.51 |   0.67 |
|         variant-switch-into-copies |    32.052 |  22.374 | 23.098 |    0.7 |

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-10 23:51:52 +01:00
parent 1c83d8123f
commit 6970d5c935
2 changed files with 26 additions and 1 deletions

View File

@ -567,6 +567,16 @@
[(:shape-ref shape) (d/without-nils (select-keys shape [:constraints-h :constraints-v]))]))))
ids))
(defn- sized-like
"`shape` resized to the size of `source` about its first corner."
[shape source]
(let [width (-> source :selrect :width)
height (-> source :selrect :height)]
(if (and (mth/close? width (-> shape :selrect :width))
(mth/close? height (-> shape :selrect :height)))
shape
(gsh/transform-shape shape (ctm/change-size shape width height)))))
(defn placed-like
"The main `objects` with the subtree of `shape-main` placed like `placed`,
a copy shape expressed in the main's frame: resized to its size, its
@ -1313,7 +1323,15 @@
position-objects (get-in (meta position) [:container :objects])
;; the head takes the place the replaced child authored
placement (set/intersection (set (:touched replaced)) placement-groups)
positioned (mapv take-position new-shapes)
;; a plain copy of the position has its size, unless the replaced child authored its geometry
sized? (fn [shape]
(and (= (:id shape) (:id new-head)) position
(not (ctk/swapped? shape))
(not (contains? placement :geometry-group))))
positioned (mapv (fn [shape]
(let [shape (take-position shape)]
(cond-> shape (sized? shape) (sized-like position))))
new-shapes)
by-id (d/index-by :id positioned)
head (get by-id (:id new-head))
;; the position's subtree placed like a head that is a plain copy of it

View File

@ -2109,6 +2109,13 @@
[:add-variant] [:add-variant] [:add-variant] [:switch 4] [:transform 0 0 0 7]
[:update-main 22]]}))))
(t/deftest updating-a-main-with-a-swap-to-its-position-component-gives-the-head-the-positions-size
(t/is (map? (cg/run {:world [2 2 {:variants true :text-styles false :layout :grid :variant-diff false
:layout-item-margins false :grid-square false :rich-variants true
:layout-children false :grid-empty false :layout-copies false :text true}]
:ops [[:variant-property] [:switch 3] [:combine 11] [:combine 12] [:resize 10]
[:variant-property 8 9] [:add-variant] [:switch 2] [:update-main]]}))))
(t/deftest moving-a-flex-copy-child-after-a-switch-resized-its-sibling-authors-no-geometry
(t/is (map? (cg/run {:world [1 2 {:variants true :text-styles false :layout :flex :variant-diff false
:layout-item-margins false :grid-square false :rich-variants true