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