🐛 Implement undo in layer move operation

This commit is contained in:
Andrés Moya 2020-05-21 10:56:42 +02:00
parent a050a45424
commit 25518a4ac0
3 changed files with 21 additions and 10 deletions

View file

@ -916,13 +916,11 @@
;; --- Change Shape Order (D&D Ordering)
;; TODO: pending UNDO
(defn relocate-shape
[id parent-id index]
[id parent-id to-index]
(us/verify ::us/uuid id)
(us/verify ::us/uuid parent-id)
(us/verify number? index)
(us/verify number? to-index)
(ptk/reify ::relocate-shape
dwc/IUpdateGroup
@ -931,12 +929,18 @@
ptk/WatchEvent
(watch [_ state stream]
(let [page-id (:current-page-id state)
objects (get-in state [:workspace-data page-id :objects])
parent (get objects (cp/get-parent id objects))
current-index (d/index-of (:shapes parent) id)
selected (get-in state [:workspace-local :selected])]
(rx/of (dwc/commit-changes [{:type :mov-objects
:parent-id parent-id
:index index
:index to-index
:shapes (vec selected)}]
[{:type :mov-objects
:parent-id (:id parent)
:index current-index
:shapes (vec selected)}]
[]
{:commit-local? true}))))))
;; --- Change Page Order (D&D Ordering)

View file

@ -153,9 +153,9 @@
(fn [side {:keys [id] :as data}]
(if (= side :center)
(st/emit! (dw/relocate-shape id (:id item) 0))
(let [index (if (= side :top) (inc index) index)
(let [to-index (if (= side :top) (inc index) index)
parent-id (cp/get-parent (:id item) objects)]
(st/emit! (dw/relocate-shape id parent-id index)))))
(st/emit! (dw/relocate-shape id parent-id to-index)))))
[dprops dref] (hooks/use-sortable
:type (str (:frame-id item))