diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index f356856d98..cfe1e01527 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -1203,9 +1203,13 @@ :include-deleted? true :with-context? true) take-position (ctf/take-position nil libraries objects new-head (:shape-ref replaced) position) - position-objects (get-in (meta position) [:container :objects])] + position-objects (get-in (meta position) [:container :objects]) + ;; the head takes the place the replaced child authored + placement (set/intersection (set (:touched replaced)) placement-groups)] (mapv (fn [shape] - (let [shape (take-position shape)] + (let [shape (cond-> (take-position shape) + (and (= (:id shape) (:id new-head)) (seq placement)) + (update :touched (fnil into #{}) placement))] (author-pushed-content shape (get position-objects (:shape-ref shape))))) new-shapes)) new-shapes) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index e63dbb35c8..b60957180d 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1056,3 +1056,10 @@ :rich-variants true :layout-copies true :text true}] :ops [[:style 24 8 1] [:swap 2 0 0 0] [:edit 3 0 1 1] [:update-main 3] [:update-main 0 0 0 0]]})))) + +(t/deftest generated-pushed-switch-takes-the-place-its-copy-authored + ;; a switched head pushed into a copy in a main takes the place the copy + ;; child it replaces had moved to, as its own geometry + (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :variant-diff false :rich-variants true + :layout-copies true :text true}] + :ops [[:delete 5 0 0 0] [:switch 3 0 0 0] [:transform 0 0 0 3] [:update-main 0 0 0 0]]}))))