mirror of
https://github.com/penpot/penpot.git
synced 2025-01-23 06:58:58 -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"}
|
[:map {:title "DelComponentChange"}
|
||||||
[:type [:= :del-component]]
|
[:type [:= :del-component]]
|
||||||
[:id ::sm/uuid]
|
[:id ::sm/uuid]
|
||||||
|
[:main-instance {:optional true} :any]
|
||||||
[:skip-undelete? {:optional true} :boolean]]]
|
[:skip-undelete? {:optional true} :boolean]]]
|
||||||
|
|
||||||
[:restore-component
|
[:restore-component
|
||||||
|
@ -642,8 +643,8 @@
|
||||||
(ctkl/mod-component data params))
|
(ctkl/mod-component data params))
|
||||||
|
|
||||||
(defmethod process-change :del-component
|
(defmethod process-change :del-component
|
||||||
[data {:keys [id skip-undelete?]}]
|
[data {:keys [id skip-undelete? main-instance]}]
|
||||||
(ctf/delete-component data id skip-undelete?))
|
(ctf/delete-component data id skip-undelete? main-instance))
|
||||||
|
|
||||||
(defmethod process-change :restore-component
|
(defmethod process-change :restore-component
|
||||||
[data {:keys [id page-id]}]
|
[data {:keys [id page-id]}]
|
||||||
|
|
|
@ -752,17 +752,15 @@
|
||||||
:page-id page-id})))
|
:page-id page-id})))
|
||||||
|
|
||||||
(defn restore-component
|
(defn restore-component
|
||||||
([changes id]
|
[changes id page-id main-instance]
|
||||||
(restore-component changes id nil))
|
(assert-library! changes)
|
||||||
([changes id page-id]
|
(-> changes
|
||||||
(assert-library! changes)
|
(update :redo-changes conj {:type :restore-component
|
||||||
(-> changes
|
:id id
|
||||||
(update :redo-changes conj {:type :restore-component
|
:page-id page-id})
|
||||||
:id id
|
(update :undo-changes conj {:type :del-component
|
||||||
:page-id page-id})
|
:id id
|
||||||
(update :undo-changes conj {:type :del-component
|
:main-instance main-instance})))
|
||||||
:id id}))))
|
|
||||||
|
|
||||||
(defn ignore-remote
|
(defn ignore-remote
|
||||||
[changes]
|
[changes]
|
||||||
(letfn [(add-ignore-remote
|
(letfn [(add-ignore-remote
|
||||||
|
|
|
@ -258,16 +258,18 @@
|
||||||
(defn delete-component
|
(defn delete-component
|
||||||
"Mark a component as deleted and store the main instance shapes iside it, to
|
"Mark a component as deleted and store the main instance shapes iside it, to
|
||||||
be able to be recovered later."
|
be able to be recovered later."
|
||||||
([file-data component-id]
|
[file-data component-id skip-undelete? main-instance]
|
||||||
(delete-component file-data component-id false))
|
(let [components-v2 (dm/get-in file-data [:options :components-v2])]
|
||||||
|
(if (or (not components-v2) skip-undelete?)
|
||||||
([file-data component-id skip-undelete?]
|
(ctkl/delete-component file-data component-id)
|
||||||
(let [components-v2 (dm/get-in file-data [:options :components-v2])]
|
(let [set-main-instance ;; If there is a saved main-instance, restore it. This happens on the restore-component action
|
||||||
(if (or (not components-v2) skip-undelete?)
|
#(if main-instance
|
||||||
(ctkl/delete-component file-data component-id)
|
(assoc-in % [:objects (:main-instance-id %)] main-instance)
|
||||||
(-> file-data
|
%)]
|
||||||
(ctkl/update-component component-id (partial load-component-objects file-data))
|
(-> file-data
|
||||||
(ctkl/mark-component-deleted component-id))))))
|
(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
|
(defn restore-component
|
||||||
"Recover a deleted component and all its shapes and put all this again in place."
|
"Recover a deleted component and all its shapes and put all this again in place."
|
||||||
|
|
|
@ -254,6 +254,7 @@
|
||||||
([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)])
|
||||||
inside-component? (some? (ctn/get-instance-root (:objects page) parent))
|
inside-component? (some? (ctn/get-instance-root (:objects page) parent))
|
||||||
|
|
||||||
shapes (cfh/get-children-with-self (:objects component) (:main-instance-id component))
|
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 (reduce #(pcb/add-object %1 %2 {:ignore-touched true})
|
||||||
changes
|
changes
|
||||||
(rest shapes))]
|
(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)})))
|
:shape (first shapes)})))
|
||||||
|
|
||||||
;; ---- General library synchronization functions ----
|
;; ---- General library synchronization functions ----
|
||||||
|
|
Loading…
Add table
Reference in a new issue