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]]}))))