mirror of
https://github.com/penpot/penpot.git
synced 2025-01-08 07:50:43 -05:00
🐛 Fix weird positioning of component mixing undos and cut/paste
This commit is contained in:
parent
4c815998f8
commit
8bd10c3c04
4 changed files with 26 additions and 24 deletions
|
@ -205,6 +205,7 @@
|
|||
[:map {:title "DelComponentChange"}
|
||||
[:type [:= :del-component]]
|
||||
[:id ::sm/uuid]
|
||||
[:main-instance {:optional true} :any]
|
||||
[:skip-undelete? {:optional true} :boolean]]]
|
||||
|
||||
[:restore-component
|
||||
|
@ -642,8 +643,8 @@
|
|||
(ctkl/mod-component data params))
|
||||
|
||||
(defmethod process-change :del-component
|
||||
[data {:keys [id skip-undelete?]}]
|
||||
(ctf/delete-component data id skip-undelete?))
|
||||
[data {:keys [id skip-undelete? main-instance]}]
|
||||
(ctf/delete-component data id skip-undelete? main-instance))
|
||||
|
||||
(defmethod process-change :restore-component
|
||||
[data {:keys [id page-id]}]
|
||||
|
|
|
@ -752,17 +752,15 @@
|
|||
:page-id page-id})))
|
||||
|
||||
(defn restore-component
|
||||
([changes id]
|
||||
(restore-component changes id nil))
|
||||
([changes id page-id]
|
||||
[changes id page-id main-instance]
|
||||
(assert-library! changes)
|
||||
(-> changes
|
||||
(update :redo-changes conj {:type :restore-component
|
||||
:id id
|
||||
:page-id page-id})
|
||||
(update :undo-changes conj {:type :del-component
|
||||
:id id}))))
|
||||
|
||||
:id id
|
||||
:main-instance main-instance})))
|
||||
(defn ignore-remote
|
||||
[changes]
|
||||
(letfn [(add-ignore-remote
|
||||
|
|
|
@ -258,15 +258,17 @@
|
|||
(defn delete-component
|
||||
"Mark a component as deleted and store the main instance shapes iside it, to
|
||||
be able to be recovered later."
|
||||
([file-data component-id]
|
||||
(delete-component file-data component-id false))
|
||||
|
||||
([file-data component-id skip-undelete?]
|
||||
[file-data component-id skip-undelete? main-instance]
|
||||
(let [components-v2 (dm/get-in file-data [:options :components-v2])]
|
||||
(if (or (not components-v2) skip-undelete?)
|
||||
(ctkl/delete-component file-data component-id)
|
||||
(let [set-main-instance ;; If there is a saved main-instance, restore it. This happens on the restore-component action
|
||||
#(if main-instance
|
||||
(assoc-in % [:objects (:main-instance-id %)] main-instance)
|
||||
%)]
|
||||
(-> file-data
|
||||
(ctkl/update-component component-id (partial load-component-objects file-data))
|
||||
(ctkl/update-component component-id set-main-instance)
|
||||
(ctkl/mark-component-deleted component-id))))))
|
||||
|
||||
(defn restore-component
|
||||
|
|
|
@ -254,6 +254,7 @@
|
|||
([changes library-data component-id it page delta old-id parent-id frame-id]
|
||||
(let [component (ctkl/get-deleted-component library-data component-id)
|
||||
parent (get-in page [:objects parent-id])
|
||||
main-inst (get-in component [:objects (:main-instance-id component)])
|
||||
inside-component? (some? (ctn/get-instance-root (:objects page) parent))
|
||||
|
||||
shapes (cfh/get-children-with-self (:objects component) (:main-instance-id component))
|
||||
|
@ -281,7 +282,7 @@
|
|||
changes (reduce #(pcb/add-object %1 %2 {:ignore-touched true})
|
||||
changes
|
||||
(rest shapes))]
|
||||
{:changes (pcb/restore-component changes component-id (:id page))
|
||||
{:changes (pcb/restore-component changes component-id (:id page) main-inst)
|
||||
:shape (first shapes)})))
|
||||
|
||||
;; ---- General library synchronization functions ----
|
||||
|
|
Loading…
Reference in a new issue