From e568ad0370b4fa17b787d9b8efd47daae1c8af21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Tue, 31 Oct 2023 19:06:53 +0100 Subject: [PATCH] :bug: Fix automatic frame assignment in clone-object --- common/src/app/common/types/container.cljc | 4 +-- common/src/app/common/types/shape_tree.cljc | 31 +++++++++++++-------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/common/src/app/common/types/container.cljc b/common/src/app/common/types/container.cljc index b4db7f8554..f8471e9899 100644 --- a/common/src/app/common/types/container.cljc +++ b/common/src/app/common/types/container.cljc @@ -296,7 +296,7 @@ (gpt/add orig-pos delta) {:skip-components? true :bottom-frames? true})) - ids-map (volatile! {}) + ids-map (volatile! {}) update-new-shape (fn [new-shape original-shape] @@ -339,7 +339,7 @@ [new-shape new-shapes _] (ctst/clone-object component-shape - nil + uuid/zero (if components-v2 (:objects component-page) (:objects component)) update-new-shape (fn [object _] object) diff --git a/common/src/app/common/types/shape_tree.cljc b/common/src/app/common/types/shape_tree.cljc index 096e803262..a8a6cc1d49 100644 --- a/common/src/app/common/types/shape_tree.cljc +++ b/common/src/app/common/types/shape_tree.cljc @@ -354,29 +354,38 @@ the order of the children of each parent." ([object parent-id objects] - (clone-object object parent-id objects (fn [object _] object) (fn [object _] object) nil false)) + (clone-object object parent-id objects (fn [object _] object) (fn [object _] object) nil false true)) ([object parent-id objects update-new-object] - (clone-object object parent-id objects update-new-object (fn [object _] object) nil false)) + (clone-object object parent-id objects update-new-object (fn [object _] object) nil false true)) ([object parent-id objects update-new-object update-original-object] - (clone-object object parent-id objects update-new-object update-original-object nil false)) + (clone-object object parent-id objects update-new-object update-original-object nil false true)) ([object parent-id objects update-new-object update-original-object force-id] - (clone-object object parent-id objects update-new-object update-original-object force-id false)) + (clone-object object parent-id objects update-new-object update-original-object force-id false true)) ([object parent-id objects update-new-object update-original-object force-id keep-ids?] + (clone-object object parent-id objects update-new-object update-original-object force-id keep-ids? true)) + + ([object parent-id objects update-new-object update-original-object force-id keep-ids? calc-frame?] (let [new-id (cond (some? force-id) force-id keep-ids? (:id object) :else (uuid/next)) - ;; Assign the correct frame-id for the given parent. - ;; It's the parent-id (if frame) or the parent's frame-id otherwise. - frame-id - (if (cph/frame-shape? objects parent-id) - parent-id - (dm/get-in objects [parent-id :frame-id]))] + ;; Assign the correct frame-id for the given parent. It's the parent-id (if parent is frame) + ;; or the parent's frame-id otherwise. Only for the first cloned shapes. In recursive calls + ;; this is not needed. + frame-id (cond + (and calc-frame? (cph/frame-shape? objects parent-id)) + parent-id + + calc-frame? + (dm/get-in objects [parent-id :frame-id]) + + :else + (:frame-id object))] (loop [child-ids (seq (:shapes object)) new-direct-children [] @@ -408,7 +417,7 @@ _ (dm/assert! (some? child)) [new-child new-child-objects updated-child-objects] - (clone-object child new-id objects update-new-object update-original-object nil keep-ids?)] + (clone-object child new-id objects update-new-object update-original-object nil keep-ids? false)] (recur (next child-ids)