From b2757fdbb938f3511c773cd23d93b9edbf74d4d0 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Sun, 1 Nov 2026 01:30:40 +0100 Subject: [PATCH] :bug: Carry a copy child's own position when sync moves its parent A copy child with a geometry override keeps its place inside its parent. When sync turned or flipped the parent, the child followed, but when sync only moved it, for instance a nested copy that its main's layout shifted to make room for a new child, the child stayed where it was and came loose from its parent. A parent that sync moves without resizing now carries its whole subtree as well. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+--------+-------| | deepest-edit-through-three-levels | 35.215 | 18.821 | 0.53 | | edit-through-a-chain-of-dependents | 68.931 | 37.929 | 0.55 | | library-update-into-copies | 83.083 | 48.193 | 0.58 | | main-edit-among-many-shapes | 4.837 | 2.06 | 0.43 | | main-edit-into-10-copies | 1.79 | 0.959 | 0.54 | | main-edit-into-100-copies | 15.415 | 9.24 | 0.6 | | main-edit-into-1000-copies | 153.086 | 92.816 | 0.61 | | variant-switch-into-copies | 32.052 | 19.519 | 0.61 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/libraries.cljc | 12 ++++++++--- .../logic/comp_expected_geometry_test.cljc | 20 +++++++++++++++++++ .../logic/composable_gen_test.cljc | 7 +++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 1eaadca276..35dc408308 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -586,12 +586,18 @@ (reduce #(update %1 %2 gsh/move delta) objects ids))) (defn- sync-descendant-orientation - "A parent turned by sync carries its whole subtree, including geometry - overrides. Resize remains the job of constraints, not matrix scale." + "A parent turned or moved by sync carries its whole subtree, including + geometry overrides. Resize remains the job of constraints, not matrix + scale." [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)) + (not (gpt/close? (gsh/shape->center before) (gsh/shape->center after)))) changed? (and after - (or (not (mth/close? (or (:rotation before) 0) (or (:rotation after) 0) 1e-10)) + (or moved? + (not (mth/close? (or (:rotation before) 0) (or (:rotation after) 0) 1e-10)) (not= (boolean (:flip-x before)) (boolean (:flip-x after))) (not= (boolean (:flip-y before)) (boolean (:flip-y after))))) ids (when changed? (cfh/get-children-ids (:objects container) (:id before)))] diff --git a/common/test/common_tests/logic/comp_expected_geometry_test.cljc b/common/test/common_tests/logic/comp_expected_geometry_test.cljc index 2c0d5df946..0883cb998b 100644 --- a/common/test/common_tests/logic/comp_expected_geometry_test.cljc +++ b/common/test/common_tests/logic/comp_expected_geometry_test.cljc @@ -202,6 +202,26 @@ (t/is (= (thn/normalize-file (tm/file edited)) (thn/normalize-file (tm/file (r/step turned (n/undo))))))))) +(t/deftest authored-child-position-follows-a-parent-move-received-through-sync + (let [file (-> (thf/sample-file :file) + (tho/add-simple-component :a :main-a :rect-a + :root-params {:width 100 :height 100}) + (tho/add-frame :main-b {:width 200 :height 200}) + (thc/instantiate-component :a :b-a :parent-label :main-b) + (thc/make-component :b :main-b) + (tho/add-frame :main-c {:width 300 :height 300}) + (thc/instantiate-component :b :c-b :parent-label :main-c) + (thc/make-component :c :main-c) + (thc/instantiate-component :c :copy-c :children-labels [:copy-b :copy-a])) + edited (-> (tm/make-situation file) r/settle (r/step (n/transform-shape :copy-a :move [5 3])) r/settle) + moved (-> edited (r/step (n/transform-shape :c-b :move [20 0])) r/settle) + delta (fn [label] + (gpt/subtract (gsh/shape->center (tm/resolve-shape moved label)) + (gsh/shape->center (tm/resolve-shape edited label))))] + (t/is (gpt/close? (gpt/point 20 0) (delta :copy-b))) + (t/is (gpt/close? (gpt/point 20 0) (delta :copy-a))) + (t/is (= #{:geometry-group} (:touched (tm/resolve-shape moved :copy-a)))))) + (t/deftest a-nested-copy-keeps-its-detached-parents-orientation-on-sync (let [detached (-> (setup/nested-component-with-copy) (r/step (n/rotate :copy-root 90)) r/settle diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index a21cc754cb..086b3e8852 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -874,3 +874,10 @@ :let [child (get objects id)] :when (not (or (:hidden child) (:layout-item-absolute child)))] (t/is (contains? in-cells id) (:name child))))) + +(t/deftest generated-moved-child-follows-its-nested-parent-shifted-by-a-main-layout + ;; a child moved in a copy keeps its place in its nested parent copy, which + ;; sync moves when a new child shifts the main's flex layout + (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout :flex :library true + :rich-variants true :layout-copies true :text true}] + :ops [[:transform 7 0 0 8] [:delete 0] [:restore 0] [:add-child 9 0 0 0]]}))))