🐛 Keep the moved place of a copy child a pushed switch replaces

A copy in a main can move one of its nested children, which marks the
child's geometry as its own. When a copy of that main switches the child
to another variant and the switch is pushed into the main, the new
nested copy replaces the moved child at the same place, but nothing
marked that place as its own. The next sync brought it back to its
component's place and the main's nested copy no longer matched.

The pushed head now takes the placement groups the replaced child had
touched, so it keeps the place it inherits. The model expects them with
the head's geometry in the main.

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

| world                              | baseline |     now | ratio |
|------------------------------------+----------+---------+-------|
| deepest-edit-through-three-levels  |   35.215 |  21.215 |  0.60 |
| edit-through-a-chain-of-dependents |   68.931 |  41.146 |  0.60 |
| library-update-into-copies         |   83.083 |  48.017 |  0.58 |
| main-edit-among-many-shapes        |    4.837 |   2.678 |  0.55 |
| main-edit-into-10-copies           |     1.79 |   1.023 |  0.57 |
| main-edit-into-100-copies          |   15.415 |   9.272 |  0.60 |
| main-edit-into-1000-copies         |  153.086 |  94.933 |  0.62 |
| variant-switch-into-copies         |   32.052 |  24.787 |  0.77 |

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-03 23:37:36 +01:00
parent a3afd4cd76
commit 0436156e27
2 changed files with 13 additions and 2 deletions

View File

@ -1203,9 +1203,13 @@
:include-deleted? true
:with-context? true)
take-position (ctf/take-position nil libraries objects new-head (:shape-ref replaced) position)
position-objects (get-in (meta position) [:container :objects])]
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)]
(mapv (fn [shape]
(let [shape (take-position shape)]
(let [shape (cond-> (take-position shape)
(and (= (:id shape) (:id new-head)) (seq placement))
(update :touched (fnil into #{}) placement))]
(author-pushed-content shape (get position-objects (:shape-ref shape)))))
new-shapes))
new-shapes)

View File

@ -1056,3 +1056,10 @@
: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]]}))))
(t/deftest generated-pushed-switch-takes-the-place-its-copy-authored
;; a switched head pushed into a copy in a main takes the place the copy
;; child it replaces had moved to, as its own geometry
(t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :variant-diff false :rich-variants true
:layout-copies true :text true}]
:ops [[:delete 5 0 0 0] [:switch 3 0 0 0] [:transform 0 0 0 3] [:update-main 0 0 0 0]]}))))