diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index c193d900f3..df229bc6ba 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -3260,7 +3260,7 @@ (cfh/get-children-ids-with-self objects (:id shape)))) advance-copy (fn [objects shape] (if (and (ctk/instance-head? shape) (not (ctk/main-instance? shape))) - (let [level-delta (ctn/get-nesting-level-delta (:objects page) shape uuid/zero)] + (let [level-delta (ctn/get-nesting-level-delta (:objects page) shape (get-in page [:objects uuid/zero]))] (cond (not (pos? level-delta)) objects diff --git a/common/src/app/common/types/container.cljc b/common/src/app/common/types/container.cljc index 0274bab41e..1196de0514 100644 --- a/common/src/app/common/types/container.cljc +++ b/common/src/app/common/types/container.cljc @@ -196,7 +196,7 @@ ;; Calculate how many parent heads share in common the original ;; shape and the new parent. pairs (map vector orig-heads dest-heads) - common-count (count (take-while (fn [a b] (= a b)) pairs))] + common-count (count (take-while (fn [[a b]] (= (:id a) (:id b))) pairs))] (- (count orig-heads) common-count))) diff --git a/common/test/common_tests/types/container_test.cljc b/common/test/common_tests/types/container_test.cljc index 695685caef..0fd1e8879d 100644 --- a/common/test/common_tests/types/container_test.cljc +++ b/common/test/common_tests/types/container_test.cljc @@ -350,6 +350,23 @@ ;; stops after the direct parent (tm/known-failure "F63" true false (ctc/has-any-copy-parent? objects rect)))) +(t/deftest nesting-level-delta-of-a-move-between-copies + ;; :copy2-root #--> [Component :component2] + ;; :copy-nested @--> [Component :component1] + ;; :copy-rect + (let [file (tho/add-nested-component-with-copy (thf/sample-file :file1) + :component1 :main1-root :main1-child + :component2 :main2-root :nested-head + :copy2-root + :copy2-root-params {:children-labels [:copy-nested :copy-rect]}) + objects (:objects (thf/current-page file)) + delta #(ctc/get-nesting-level-delta objects + (ths/get-shape file :copy-rect) + (get objects %))] + (t/is (= 0 (delta (thi/id :copy-nested)))) + (t/is (= 1 (delta (thi/id :copy2-root)))) + (t/is (= 2 (delta uuid/zero))))) + (t/deftest container-of-a-component (let [file (placement-file) container (ctc/get-container (:data file) :component (thi/id :c1))]