🐛 Move combined mains into the variant one at a time in combine order

Combining same-name components as variants gives each one the first
unused "Value N", in the order the mains enter the variant container.
`generate-combine-as-variants` moved all the remaining mains in one
relocation, which takes them in layer order, so the values followed the
layers and not the combine order. It now moves them one at a time, in
the order of the ids, as the frontend combine on develop does.

Test: `test-combine-as-variants-same-name-values-follow-combine-order`.

Benchmark (scripts/bench-components, ms, lower 2.5% quantile):
|                             :world | :baseline |   :now |  :mean | :ratio |
|------------------------------------+-----------+--------+--------+--------|
|  deepest-edit-through-three-levels |    35.215 | 20.749 | 21.213 |   0.59 |
| edit-through-a-chain-of-dependents |    68.931 | 40.771 | 41.457 |   0.59 |
|         library-update-into-copies |    83.083 | 50.674 | 51.835 |   0.61 |
|        main-edit-among-many-shapes |     4.837 |  1.967 |  2.133 |   0.41 |
|           main-edit-into-10-copies |      1.79 |  1.039 |  1.059 |   0.58 |
|          main-edit-into-100-copies |    15.415 |  9.153 |  9.626 |   0.59 |
|         main-edit-into-1000-copies |   153.086 | 93.347 | 99.626 |   0.61 |
|         variant-switch-into-copies |    32.052 |  21.86 |  22.36 |   0.68 |

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-10 20:27:13 +01:00
parent c544a9445d
commit 312a3ce6f0
2 changed files with 25 additions and 1 deletions

View File

@ -223,7 +223,9 @@
(- (:y rect) (:y first-shape) 30))
:prefix prefix
:wrapper? (empty? prefix)})
(generate-move-into $ (set (rest ids)) variant-id 0)
;; one move per main, in the order of `ids`, so the property values it
;; generates follow that order
(reduce #(generate-move-into %1 #{%2} variant-id 0) $ (rest ids))
;; the members in the order of `ids`: the board's children go the other
;; way, and a change of parent at index 0 reverses the shapes it takes
(let [children (set (get-in (pcb/get-objects $) [variant-id :shapes]))

View File

@ -453,6 +453,28 @@
(t/is (= "Value 3" (:variant-name (ths/get-shape file' :m03))))))
(t/deftest test-combine-as-variants-same-name-values-follow-combine-order
;; The combine order differs from the layer order of the mains
(let [file (-> (thf/sample-file :file1)
(tho/add-simple-component :c01 :m01 :r01
:root-params {:name "Tag" :x 0 :y 0 :width 100 :height 80})
(tho/add-simple-component :c02 :m02 :r02
:root-params {:name "Tag" :x 150 :y 0 :width 100 :height 80})
(tho/add-simple-component :c03 :m03 :r03
:root-params {:name "Tag" :x 300 :y 0 :width 100 :height 80}))
page (thf/current-page file)
changes (-> (pcb/empty-changes nil (:id page))
(pcb/with-objects (:objects page))
(pcb/with-library-data (:data file))
(clv/generate-combine-as-variants [(thi/id :m03) (thi/id :m01) (thi/id :m02)]
(uuid/next)))
file' (thf/apply-changes file changes)
values (mapv #(-> (thc/get-component file' %) :variant-properties first :value)
[:c03 :c01 :c02])]
(t/is (= ["Value 1" "Value 2" "Value 3"] values))))
(t/deftest test-duplicate-variant-container
(let [;; ==== Setup
file (-> (thf/sample-file :file1)