From a1d8b06c09f4be5d8044533fe654918d85618b7a Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 13 Oct 2026 14:14:50 +0200 Subject: [PATCH] :bug: Count the shared copy heads in get-nesting-level-delta get-nesting-level-delta counted the copy heads that a shape and its new parent share with a two-argument predicate over a seq of pairs, so it threw an arity error whenever both had copy heads. Its callers, duplicate and the advance of copied objects, only pass parents outside every copy today, so nobody reached it. The predicate now takes the pair and compares the heads by id. The advance of copied objects passed uuid/zero where the function expects a shape; it worked only because the id of a uuid is nil. It now passes the root shape. AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/libraries.cljc | 2 +- common/src/app/common/types/container.cljc | 2 +- .../test/common_tests/types/container_test.cljc | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) 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))]