🐛 Restore a reset nested copy's inherited layout item values

Layout item values (margins, sizing, alignment) sync from a layout parent to
its children, not as a shape's own attributes. A reset rooted at a nested
copy head therefore never restored the head's own values: one whose margin
type was overridden kept it while the reset cleared its touched groups.

After a reset, give the head its ref's layout child values when its parent
is the copy of the ref's layout parent, the case in which they are
inherited.

A seed 712 large gate (stale library, program 118) found this; it also
fails on earlier commits. The program regression fails before the fix and
passes after it, with undo and redo. Full common passes lint, JVM,
JavaScript and formatting: JVM 2082 tests / 33907 assertions; JavaScript
2018 / 32562. All six component properties pass 40 programs each at seed
712 in both runtimes.

Compare lower-quantile milliseconds with the saved baseline; keep that
baseline unchanged. The machine/JVM warning makes ratios rough. No world
is flagged.

World                      Baseline       Now    Ratio
Main into 10 copies           1.790     0.909     0.51
Main into 100 copies         15.415     8.804     0.57
Main into 1000 copies       153.086    88.560     0.58
Three nesting levels         35.215    18.272     0.52
Dependency chain             68.931    35.558     0.52
Library update               83.083    45.079     0.54
Many plain shapes             4.837     2.104     0.43
Variant switch               32.052    19.574     0.61

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-10-31 18:49:36 +01:00
parent 50dc444e71
commit 72fb4f8d41
2 changed files with 28 additions and 2 deletions

View File

@ -2023,13 +2023,31 @@
changes))
changes)))
(defn- reset-layout-item
"Give a reset head the layout item values it inherits: those of its ref
when its parent is the copy of the ref's layout parent. Sync passes them
from parent to children, so the reset of the head alone keeps them."
[changes file libraries container shape-id]
(let [objects (pcb/get-objects changes)
shape (get objects shape-id)
parent (get objects (:parent-id shape))
ref (when (and (:layout parent) (:shape-ref parent))
(ctf/find-ref-shape file (assoc container :objects objects) libraries shape
:include-deleted? true :with-context? true))
ref-parent (get-in (meta ref) [:container :objects (:parent-id ref)])]
(if (and ref (:layout ref-parent) (= (:id ref-parent) (:shape-ref parent)))
(pcb/update-shapes changes [shape-id] #(propagate-attrs % ref layout-child-attrs false)
{:ignore-touched true})
changes)))
(defn generate-reset-component
"Reset the copy head to its near main. A swapped head turns back into the
component of the main shape it refers to, keeping its id. A nested head
also takes its position's placement."
also takes its position's placement and inherited layout item values."
[changes file-full libraries container id]
(-> changes
(pcb/with-container container)
(pcb/with-objects (:objects container))
(generate-sync-shape-direct file-full libraries container id true)
(settle-reset-placement file-full libraries container id)))
(settle-reset-placement file-full libraries container id)
(reset-layout-item file-full libraries container id)))

View File

@ -673,3 +673,11 @@
(t/is (map? (cg/run {:world [2 0 {:library true :stale-libraries true
:library-dependency true :library-text true}]
:ops [[:library-transform 14 3 0 0] [:edit 13 1 1 :copy-head] [:reset 13]]}))))
(t/deftest reset-restores-a-nested-copys-inherited-layout-item-values
;; The nested head's margin type overrides the one its flex position inherits.
(t/is (map? (cg/run {:world [2 1 {:variants true :rich-variants true :text true :text-styles true
:library-variants true :stale-libraries true :library-depth 1
:library true :library-text true :layout :flex
:layout-children true :layout-copies true}]
:ops [[:style 11 27 1] [:reset 14 0 0 0] [:undo] [:redo]]}))))