From 3a1b0e3d759036bab4d4b892ea0d87371ef0c136 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Sat, 14 Nov 2026 08:42:30 +0100 Subject: [PATCH] :bug: Author the size a resize gives an untouched swapped head Resizing a copy board scales a swapped head in it through its constraints. The next sync of the head, as the root of its own component, gave it its component's size back. As a sync that resizes a board already does, a transform that resizes one now marks the geometry of each untouched swapped head it gives another size, unless a layout sizes it, so later syncs keep that size. The harness model authors the same size. Benchmark (lower quantile, ms): | world | baseline | now | mean | ratio | |------------------------------------+----------+---------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 23.800 | 28.893 | 0.68 | | edit-through-a-chain-of-dependents | 68.931 | 48.458 | 60.725 | 0.70 | | library-update-into-copies | 83.083 | 61.325 | 63.038 | 0.74 | | main-edit-among-many-shapes | 4.837 | 2.523 | 2.669 | 0.52 | | main-edit-into-10-copies | 1.79 | 1.180 | 1.214 | 0.66 | | main-edit-into-100-copies | 15.415 | 11.228 | 11.628 | 0.73 | | main-edit-into-1000-copies | 153.086 | 110.756 | 120.456 | 0.72 | | variant-switch-into-copies | 32.052 | 24.565 | 28.627 | 0.77 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/libraries.cljc | 32 ++++++++++++++++++- .../logic/composable_gen_test.cljc | 13 ++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 5b18e448c1..d6cc6c57e1 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -512,6 +512,35 @@ (pcb/update-shapes authored #(update % :touched ctk/set-touched-group :geometry-group) {:ignore-touched true})))) +(defn- author-resized-swapped-heads + "Make authored the geometry of the untouched swapped heads below the + copy shapes `ids` that a transform resized through their constraints: + sync would give them their own component's size again, which only a + change of the head itself may do. A layout sizes its children itself." + [changes before ids] + (let [objects (pcb/get-objects changes) + resized? (fn [id] + (let [old (get before id) shape (get objects id)] + (and old shape + (not (and (mth/close? (-> old :selrect :width) (-> shape :selrect :width)) + (mth/close? (-> old :selrect :height) (-> shape :selrect :height))))))) + heads (into [] + (comp (filter #(and (:shape-ref (get objects %)) (resized? %))) + (mapcat #(cfh/get-children-ids objects %)) + (distinct) + (filter (fn [id] + (let [shape (get objects id)] + (and (ctk/swapped? shape) + (not (ctk/touched-group? shape :geometry-group)) + (resized? id) + (not (and (ctsl/any-layout-immediate-child? objects shape) + (not (ctsl/position-absolute? shape))))))))) + ids)] + (cond-> changes + (seq heads) + (pcb/update-shapes heads #(update % :touched ctk/set-touched-group :geometry-group) + {:ignore-touched true})))) + (defn generate-sync-transformed-placement "Settle copy descendants after a reflection and untouched swapped heads after a parent turn, in the transform's change group. Reflection can @@ -569,7 +598,8 @@ shape))) {:ignore-touched true}))) changes roots) - (author-laid-group-arrangement before ids)))) + (author-laid-group-arrangement before ids) + (author-resized-swapped-heads before ids)))) (defn- sync-copy-shape "Sync the copy shape `shape-inst` from `shape-main`, the main shape it diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 75b80b7c9b..1ab6b782c8 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -4315,3 +4315,16 @@ :layout-copies true :layout-children true}] :ops [[:add-child 8] [:structure 2 4 15] [:grid-direction 0 0 0 1] [:grid-cell 0 0 0 1] [:add-child 0] [:structure 0 2 0]]})))) + +(t/deftest generated-a-resize-authors-the-size-it-gives-a-swapped-head + ;; a resize of a copy board that scales its swapped child through its + ;; constraint authors the child's new size, which later syncs keep + (t/is (map? (cg/run {:world [1 0 {:variants true :text-styles false :scale false :layout :grid + :variant-diff false :grid-square false :copies 3 :rich-variants true + :layout-children false :grid-empty false :layout-copies false :text false}] + :ops [[:switch] [:add-child] [:style 4 9 1] [:switch 4] [:switch] [:resize 1]]}))) + (t/is (map? (cg/run {:world [1 0 {:variants true :text-styles false :layout :flex :variant-diff false + :layout-item-margins false :grid-square false :rich-variants true + :layout-children false :grid-empty false :layout-copies false :text false}] + :ops [[:delete 5] [:restore] [:add-variant] [:switch] [:add-variant] [:variant-property 0 1] + [:switch 13] [:style 5 8 7] [:add-variant]]}))))