Fix paste shapes from another components should detach them

This commit is contained in:
Pablo Alba 2023-06-07 16:14:01 +02:00 committed by Andrés Moya
parent 55a821f193
commit 8b29a50577

View file

@ -1756,6 +1756,7 @@
(let [libraries (wsh/get-libraries state) (let [libraries (wsh/get-libraries state)
file-id (:current-file-id state) file-id (:current-file-id state)
page (wsh/lookup-page state) page (wsh/lookup-page state)
page-objects (:objects page)
media-idx (d/index-by :prev-id media) media-idx (d/index-by :prev-id media)
;; Calculate position for the pasted elements ;; Calculate position for the pasted elements
@ -1763,18 +1764,24 @@
process-shape process-shape
(fn [_ shape] (fn [_ shape]
(-> shape (let [parent (get page-objects parent-id)
(assoc :frame-id frame-id :parent-id parent-id) component-shape (ctn/get-component-shape page-objects shape)
component-shape-parent (ctn/get-component-shape page-objects parent)
;; if foreign instance, detach the shape ;; if foreign instance, or a shape belonging to another component, detach the shape
(cond-> (foreign-instance? shape paste-objects state) detach? (or (foreign-instance? shape paste-objects state)
(-> (and (ctk/in-component-copy-not-root? shape)
(assoc :saved-component-root? (:component-root? shape)) ;; this is used later, if the paste needs to create a new component from the detached shape (not= (:id component-shape)
(dissoc :component-id :component-file :component-root? (:id component-shape-parent))))]
:remote-synced? :shape-ref :touched))) (-> shape
;; if is a text, remove references to external typographies (assoc :frame-id frame-id :parent-id parent-id)
(cond-> (= (:type shape) :text) (cond-> detach?
(ctt/remove-external-typographies file-id)))) (->
;; this is used later, if the paste needs to create a new component from the detached shape
(assoc :saved-component-root? (:component-root? shape))
ctk/detach-shape))
;; if is a text, remove references to external typographies
(cond-> (= (:type shape) :text)
(ctt/remove-external-typographies file-id)))))
paste-objects (->> paste-objects (d/mapm process-shape)) paste-objects (->> paste-objects (d/mapm process-shape))