0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-10 00:40:30 -05:00

🐛 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

@ -72,6 +72,12 @@
(into result (calculate-invalid-targets child-id objects)))]
(reduce reduce-fn result children)))
(defn- valid-frame-target
[shape-id parent-id objects]
(let [shape (get objects shape-id)]
(or (not= (:type shape) :frame)
(= parent-id uuid/zero))))
(defn- insert-at-index
[shapes index ids]
(let [[before after] (split-at index shapes)
@ -389,8 +395,9 @@
;; Check if the move from shape-id -> parent-id is valid
is-valid-move
(fn [shape-id]
(let [invalid (calculate-invalid-targets shape-id (:objects data))]
(not (invalid parent-id))))
(let [invalid-targets (calculate-invalid-targets shape-id (:objects data))]
(and (not (invalid-targets parent-id))
(valid-frame-target shape-id parent-id (:objects data)))))
valid? (every? is-valid-move shapes)

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))