diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 9537161e51..d59750fd2c 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -671,20 +671,28 @@ (generate-rename-component (:component-id shape-inst) (:name shape-inst) library))] (if component - (let [synced-ids (volatile! #{}) - root-main (ctf/get-component-root library component)] + (let [synced-ids (volatile! #{}) + main-container (ctf/get-component-container library component) + root-main (ctf/get-component-root library component) + center (grc/rect->center (:selrect shape-inst))] (-> (update-main-recursive changes {:container container - :main-container (ctf/get-component-container library component) + :main-container main-container :component component :libraries libraries :root-inst shape-inst :root-main root-main - ;; An orientation the copy root inherits from its - ;; parent places it; it is not pushed into the main. - :inherited-turn (when-not (ctk/touched-group? shape-inst :geometry-group) - (orient-like shape-inst root-main - (grc/rect->center (:selrect shape-inst)))) + ;; An orientation the copy root inherits places it + ;; and is not pushed into the main. Sync composes a + ;; nested root with its parent's turn; a top copy + ;; root owns its turn only when it authors geometry. + :inherited-turn (if (:component-root shape-inst) + (when-not (ctk/touched-group? shape-inst :geometry-group) + (orient-like shape-inst root-main center)) + (when-let [parent (ctn/get-shape container (:parent-id shape-inst))] + (orient-like parent + (or (ctn/get-shape main-container (:parent-id root-main)) {}) + center))) :remote-synced (when-not (:component-root shape-inst) true) :synced-ids synced-ids} shape-inst diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index e30767f8b5..dc25f2c33e 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -696,6 +696,15 @@ (t/is (true? (:fixed-scroll pushed))) (t/is (contains? (:touched pushed) :constraints-group)))) +(t/deftest updating-a-main-from-a-resized-copy-turned-by-its-parent-keeps-its-turn + ;; The nested copy authors only its size; its 45 degree turn still comes + ;; from its parent, so update-main must not turn the main. + (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout nil :layout-item-margins false + :library true :rich-variants true :layout-children false + :layout-copies true :text true}] + :ops [[:transform 6 15 0 0] [:resize 0 0 0 0] [:resize 2 0 0 0] [:resize 1 0 0 0] + [:edit 22 20 0 0] [:edit 11 0 1 1] [:update-main 11]]})))) + (t/deftest detached-swapped-head-follows-its-own-component-without-position-overrides (t/is (map? (cg/run {:world [2 1 {:library true :variants true}] :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync]