diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 91074ceeef..1bdd0057c0 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -671,14 +671,20 @@ (generate-rename-component (:component-id shape-inst) (:name shape-inst) library))] (if component - (let [synced-ids (volatile! #{})] + (let [synced-ids (volatile! #{}) + root-main (ctf/get-component-root library component)] (-> (update-main-recursive changes {:container container :main-container (ctf/get-component-container library component) :component component :libraries libraries :root-inst shape-inst - :root-main (ctf/get-component-root library component) + :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)))) :remote-synced (when-not (:component-root shape-inst) true) :synced-ids synced-ids} shape-inst @@ -704,9 +710,13 @@ "Push the copy shape `shape-inst` into `shape-main`, the main shape it pairs with: the copy's values, overrides included, go into the main, and its touched groups move there (the copy keeps a swap)." - [changes {:keys [container main-container root-inst root-main remote-synced]} shape-inst shape-main] + [changes {:keys [container main-container root-inst root-main remote-synced inherited-turn]} shape-inst shape-main] (cond-> (-> changes - (update-attrs shape-main shape-inst root-main root-inst main-container false) + (update-attrs shape-main + (cond-> shape-inst (some? inherited-turn) inherited-turn) + root-main + (cond-> root-inst (some? inherited-turn) inherited-turn) + main-container false) ;; the copy keeps its swap, and the main takes the copy's overrides (set-touched shape-inst container (when (ctk/swapped? shape-inst) #{:swap-group})) ;; A previous update is not a reset of the main's authored diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 24280ef9c6..1c35405c4d 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -5,6 +5,7 @@ [app.common.geom.shapes :as gsh] [app.common.logic.shapes :as cls] [app.common.logic.variants :as clv] + [app.common.math :as mth] [app.common.schema.test :as smt] [app.common.test-helpers.composable.comp.files :as cf] [app.common.test-helpers.composable.comp.nodes :as n] @@ -671,6 +672,17 @@ :ops [[:rotate 0 0 0 0] [:edit 0 0 1 1] [:update-main 0] [:delete 0] [:restore 0] [:nest 0 0 0 0] [:swap 0 0 0 0] [:switch 0 0 0 0]]})))) +(t/deftest updating-a-main-from-a-copy-turned-by-its-parent-keeps-the-main-unturned + (let [program {:world [2 2 {:text true :text-styles true :layout nil}] + :ops [[:rotate 6 0 0 0] [:nest 13 0 0 0] [:transform 0 0 0 13] + [:update-main 3 0 0 0] [:update-main 0 0 0 0]]} + situation (:situation (cg/run program)) + rotation #(-> (tm/shape-by-id situation (thi/id %)) :rotation (or 0) (mod 360))] + ;; The nested copy inherits 45 degrees from its updated parent; its main + ;; stays unturned and the copy keeps the turn it had. + (t/is (mth/close? 0 (rotation :sync-random-0-outer-0) 0.01)) + (t/is (mth/close? 45 (rotation :sync-random-0-innercopy-1) 0.01)))) + (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]