diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index d5567e9c07..ce1460d547 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -511,7 +511,8 @@ children-main {:pair? ctk/is-main-of? :on-pair (fn [changes child-inst child-main] - (if (and (not reset?) (ctk/swapped? child-inst)) + (if (and (not reset?) (ctk/swapped? child-inst) + (ctk/instance-head? child-main)) (update-swapped-placement changes ctx child-inst child-main) (sync-copy-recursive changes ctx child-inst child-main))) :only-inst (fn [changes child-inst] @@ -1118,7 +1119,9 @@ (if (and (= (:shape-ref dest-shape) (:id origin-shape)) (ctk/subcopy-head? dest-shape) (not (ctk/instance-head? origin-shape))) - (pcb/update-shapes changes [(:id dest-shape)] ctk/unhead-shape {:ignore-touched true}) + (pcb/update-shapes changes [(:id dest-shape)] + #(-> % ctk/remove-swap-group ctk/unhead-shape) + {:ignore-touched true}) changes)) (defn- check-swapped-main diff --git a/common/test/common_tests/logic/swap_group_test.cljc b/common/test/common_tests/logic/swap_group_test.cljc index 0072848e98..5414bddf4e 100644 --- a/common/test/common_tests/logic/swap_group_test.cljc +++ b/common/test/common_tests/logic/swap_group_test.cljc @@ -785,3 +785,15 @@ (t/is (mth/close? 80 (:height head) 0.001)) (t/is (= (thn/normalize-file (tm/file edited)) (thn/normalize-file (tm/file (r/step updated (n/undo)))))))) + +(t/deftest detaching-a-main-child-removes-the-copys-now-invalid-swap + (let [initial (tm/make-situation (setup)) + detached (-> initial (r/step (n/detach :card-star)) r/settle) + head (tm/resolve-shape detached :copy-star) + main (tm/resolve-shape detached :card-star) + objects (:objects (thf/current-page (tm/file detached)))] + (t/is (not (ctk/instance-head? head))) + (t/is (not (ctk/swapped? head))) + (t/is (= (:shapes main) (mapv #(get-in objects [% :shape-ref]) (:shapes head)))) + (t/is (= (thn/normalize-file (tm/file initial)) + (thn/normalize-file (tm/file (r/step detached (n/undo))))))))