🐛 Leave no override when a shape moved out of a layout loses its margins

A copy in a flex main kept its margin type through a reset, since its
placement belongs to its position. Nesting it out of the layout cleared
its layout-item data, and the relocation marked a margin override,
although the copy now matched its main.

Clearing layout-item data when a shape leaves a layout is a consequence
of the move, not an edit of those attributes, so it marks no override.

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

| world                              | baseline |    now | ratio |
|------------------------------------+----------+--------+-------|
| deepest-edit-through-three-levels  |   35.215 | 18.992 |  0.54 |
| edit-through-a-chain-of-dependents |   68.931 | 39.094 |  0.57 |
| library-update-into-copies         |   83.083 | 46.864 |  0.56 |
| main-edit-among-many-shapes        |    4.837 |  2.236 |  0.46 |
| main-edit-into-10-copies           |     1.79 |  0.941 |  0.53 |
| main-edit-into-100-copies          |   15.415 |  9.524 |  0.62 |
| main-edit-into-1000-copies         |  153.086 | 95.507 |  0.62 |
| variant-switch-into-copies         |   32.052 | 22.002 |  0.69 |

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-01 22:39:42 +01:00
parent a59fcb8b26
commit fcd9128575
2 changed files with 8 additions and 1 deletions

View File

@ -566,7 +566,7 @@
(-> changes
;; Remove layout-item properties and tokens when moving a shape outside a layout
(cond-> (not (ctl/any-layout? parent))
(-> (pcb/update-shapes ids ctl/remove-layout-item-data)
(-> (pcb/update-shapes ids ctl/remove-layout-item-data {:ignore-touched true})
(pcb/update-shapes ids cto/unapply-layout-item-tokens)))
;; Hide in the viewer the boards moved into a board

View File

@ -958,3 +958,10 @@
:library-depth 1 :library true :rich-variants true :library-text true
:layout-copies true :text true}]
:ops [[:rotate 1 0 0 0] [:switch 3 0 0 0]]}))))
(t/deftest generated-copy-moved-out-of-a-layout-loses-its-margins-without-an-override
;; a copy whose margin type a reset kept is nested out of its flex parent;
;; leaving the layout clears its margins, which is no override
(t/is (map? (cg/run {:world [2 1 {:text true :text-styles true :layout :flex :layout-children true}]
:ops [[:remove-child 0 0 0 0] [:nest 0 0 0 0] [:style 2 27 1]
[:edit 0 1 1 :copy-head] [:reset 0] [:nest 0 0 0 0]]}))))