mirror of
https://github.com/penpot/penpot.git
synced 2026-10-30 06:20:32 +00:00
🐛 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
This commit is contained in:
parent
280c34302f
commit
a1d8b06c09
@ -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
|
||||
|
||||
@ -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)))
|
||||
|
||||
|
||||
@ -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))]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user