From 5f4ef663148e046f3c9c9ad95c9857832088ff3b Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 3 Nov 2026 14:30:42 +0100 Subject: [PATCH] :bug: Resize a copy's subtree through constraints when sync also turns it When sync turns a copy parent, it turns and moves the parent's whole subtree, geometry overrides included, by the parent's center. When the same sync also resizes the parent, that center shift carries half the resize, so a child with its own geometry moved as if its constraint were center: a top-constrained child ended 10 px above its place after an update main turned its parent back and shrank it by 20 px. A parent that is turned and resized at once now resizes its subtree through the children's constraints first, then turns and moves it as one piece, as the main's subtree is placed into a copy. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 23.162 | 0.66 | | edit-through-a-chain-of-dependents | 68.931 | 43.751 | 0.63 | | library-update-into-copies | 83.083 | 52.008 | 0.63 | | main-edit-among-many-shapes | 4.837 | 2.897 | 0.60 | | main-edit-into-10-copies | 1.79 | 1.103 | 0.62 | | main-edit-into-100-copies | 15.415 | 10.807 | 0.70 | | main-edit-into-1000-copies | 153.086 | 105.726 | 0.69 | | variant-switch-into-copies | 32.052 | 24.017 | 0.75 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/libraries.cljc | 17 +++++++++++------ .../common_tests/logic/composable_gen_test.cljc | 7 +++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index ce976a06e8..571483f47c 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -593,12 +593,14 @@ (defn- sync-descendant-orientation "A parent turned or moved by sync carries its whole subtree, including geometry overrides. Resize remains the job of constraints, not matrix - scale." + scale: a parent turned and resized at once resizes its subtree through + their constraints first, then turns and moves it as one piece." [changes container before] (let [after (get (pcb/get-objects changes) (:id before)) - moved? (and after - (mth/close? (-> before :selrect :width) (-> after :selrect :width)) - (mth/close? (-> before :selrect :height) (-> after :selrect :height)) + resized? (and after + (not (and (mth/close? (-> before :selrect :width) (-> after :selrect :width)) + (mth/close? (-> before :selrect :height) (-> after :selrect :height))))) + moved? (and after (not resized?) (not (gpt/close? (gsh/shape->center before) (gsh/shape->center after)))) changed? (and after (or moved? @@ -615,9 +617,12 @@ (:x vertical) (:y vertical) 0 0)] (assoc shape :transform matrix :transform-inverse (gmt/inverse matrix)))) turn (orient-like (orientation before) (orientation after) (gsh/shape->center before)) - delta (gpt/subtract (gsh/shape->center after) (gsh/shape->center before))] + delta (gpt/subtract (gsh/shape->center after) (gsh/shape->center before)) + placed (when resized? (placed-like (:objects container) before after {}))] (pcb/update-shapes changes ids - #(cond-> % (some? turn) turn :always (gsh/move delta)) + (if resized? + #(get placed (:id %) %) + #(cond-> % (some? turn) turn :always (gsh/move delta))) {:ignore-touched true})) changes))) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index bf213b05e7..92d4c82776 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1041,3 +1041,10 @@ :rich-variants true :layout-copies true :text true}] :ops [[:rotate 3 0 5 0] [:duplicate 0 0 0 0] [:duplicate 0 0 0 0] [:transform 5 4 0 4] [:rotate 0 0 0 0]]})))) + +(t/deftest generated-copy-child-override-keeps-its-constraint-when-sync-turns-and-resizes-its-parent + ;; a copy child moved on its own stays at its distance from the top of its + ;; parent when an update main turns the parent back and shrinks it + (t/is (map? (cg/run {:world [2 0 {:text true :text-styles true}] + :ops [[:resize 2 0 0 0] [:detach 3 0 0 0] [:detach 11 0 0 0] [:rotate 10 0 0 0] + [:update-main 0 0 0 0] [:transform 0 0 0 12] [:update-main 7 0 0 0]]}))))