diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index f3281fba09..e17d9cfe59 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -705,11 +705,6 @@ library (dm/get-in libraries [(:component-file shape-inst) :data]) component (ctkl/get-component library (:component-id shape-inst)) - shape-main (when component - (ctf/find-remote-shape container libraries shape-inst)) - - initial-root? (:component-root shape-inst) - ;; The component name is normalized (path separators with one space at ;; each side), so the name synced to the main instance root must be ;; normalized too. Otherwise the root would not match the component's @@ -723,9 +718,6 @@ (some? clean-name) (assoc :name clean-name)) - root-inst shape-inst - root-main (ctf/get-component-root library component) - ;; When the synced shape is itself the component's main instance root, ;; `find-remote-shape` returns nil and the recursive sync never reaches ;; it, so it must be renamed explicitly to keep it matching the @@ -735,26 +727,8 @@ changes (cond-> changes (some? clean-name) - (generate-rename-component (:component-id shape-inst) clean-name library)) + (generate-rename-component (:component-id shape-inst) clean-name library) - changes (if component - (let [synced-ids (volatile! #{})] - (-> (update-main-recursive changes - {:container container - :main-container (ctf/get-component-container library component) - :component component - :libraries libraries - :root-inst root-inst - :root-main root-main - :remote-synced (when-not initial-root? true) - :synced-ids synced-ids} - shape-inst - shape-main) - (mark-local-changes @synced-ids) - (settle-updated-main-placement libraries (:component-file shape-inst) component))) - changes) - - changes (cond-> changes (and (some? clean-name) main-root? (not= clean-name original-name)) @@ -768,7 +742,28 @@ :local-change? true :operations [{:type :set :attr :name :val original-name}]}]))] - changes)) + (if component + (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 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 + (ctf/find-remote-shape container libraries shape-inst)) + (mark-local-changes @synced-ids) + (settle-updated-main-placement libraries (:component-file shape-inst) component))) + changes))) (defn split-local-changes "`changes` of an update main (`generate-sync-shape-inverse`) as `[local @@ -787,9 +782,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]