mirror of
https://github.com/penpot/penpot.git
synced 2025-08-07 14:38:33 +02:00
🐛 Fix cut/paste component inside a board
This commit is contained in:
parent
c4e707d5a2
commit
5cbb3f76c7
1 changed files with 30 additions and 27 deletions
|
@ -254,36 +254,39 @@
|
||||||
(prepare-restore-component nil library-data component-id it page (gpt/point 0 0) nil nil nil)))
|
(prepare-restore-component nil library-data component-id it page (gpt/point 0 0) nil nil nil)))
|
||||||
|
|
||||||
([changes library-data component-id it page delta old-id parent-id frame-id]
|
([changes library-data component-id it page delta old-id parent-id frame-id]
|
||||||
(let [component (ctkl/get-deleted-component library-data component-id)
|
(let [component (ctkl/get-deleted-component library-data component-id)
|
||||||
parent (get-in page [:objects parent-id])
|
parent (get-in page [:objects parent-id])
|
||||||
main-inst (get-in component [:objects (:main-instance-id component)])
|
main-inst (get-in component [:objects (:main-instance-id component)])
|
||||||
inside-component? (some? (ctn/get-instance-root (:objects page) parent))
|
inside-component? (some? (ctn/get-instance-root (:objects page) parent))
|
||||||
|
origin-frame (get-in page [:objects (:frame-id main-inst)])
|
||||||
|
;; We are using a deleted component andit's coordenates are absolute, we must adjust them to its containing frame to adjust the delta
|
||||||
|
delta (gpt/subtract delta (-> origin-frame :selrect gpt/point))
|
||||||
|
shapes (cfh/get-children-with-self (:objects component) (:main-instance-id component))
|
||||||
|
shapes (map #(gsh/move % delta) shapes)
|
||||||
|
|
||||||
shapes (cfh/get-children-with-self (:objects component) (:main-instance-id component))
|
first-shape (cond-> (first shapes)
|
||||||
shapes (map #(gsh/move % delta) shapes)
|
(not (nil? parent-id))
|
||||||
first-shape (cond-> (first shapes)
|
(assoc :parent-id parent-id)
|
||||||
(not (nil? parent-id))
|
(not (nil? frame-id))
|
||||||
(assoc :parent-id parent-id)
|
(assoc :frame-id frame-id)
|
||||||
(not (nil? frame-id))
|
(and (nil? frame-id) parent (= :frame (:type parent)))
|
||||||
(assoc :frame-id frame-id)
|
(assoc :frame-id parent-id)
|
||||||
(and (nil? frame-id) parent (= :frame (:type parent)))
|
(and (nil? frame-id) parent (not= :frame (:type parent)))
|
||||||
(assoc :frame-id parent-id)
|
(assoc :frame-id (:frame-id parent))
|
||||||
(and (nil? frame-id) parent (not= :frame (:type parent)))
|
inside-component?
|
||||||
(assoc :frame-id (:frame-id parent))
|
(dissoc :component-root)
|
||||||
inside-component?
|
(not inside-component?)
|
||||||
(dissoc :component-root)
|
(assoc :component-root true))
|
||||||
(not inside-component?)
|
|
||||||
(assoc :component-root true))
|
|
||||||
|
|
||||||
changes (-> (or changes (pcb/empty-changes it))
|
changes (-> (or changes (pcb/empty-changes it))
|
||||||
(pcb/with-page page)
|
(pcb/with-page page)
|
||||||
(pcb/with-objects (:objects page))
|
(pcb/with-objects (:objects page))
|
||||||
(pcb/with-library-data library-data))
|
(pcb/with-library-data library-data))
|
||||||
changes (cond-> (pcb/add-object changes first-shape {:ignore-touched true})
|
changes (cond-> (pcb/add-object changes first-shape {:ignore-touched true})
|
||||||
(some? old-id) (pcb/amend-last-change #(assoc % :old-id old-id))) ; on copy/paste old id is used later to reorder the paster layers
|
(some? old-id) (pcb/amend-last-change #(assoc % :old-id old-id))) ; on copy/paste old id is used later to reorder the paster layers
|
||||||
changes (reduce #(pcb/add-object %1 %2 {:ignore-touched true})
|
changes (reduce #(pcb/add-object %1 %2 {:ignore-touched true})
|
||||||
changes
|
changes
|
||||||
(rest shapes))]
|
(rest shapes))]
|
||||||
{:changes (pcb/restore-component changes component-id (:id page) main-inst)
|
{:changes (pcb/restore-component changes component-id (:id page) main-inst)
|
||||||
:shape (first shapes)})))
|
:shape (first shapes)})))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue