Fix group deletion mechanism.

This commit is contained in:
Andrey Antukh 2016-01-20 21:45:22 +02:00
parent a4d3136707
commit 2124aba21f

View File

@ -156,18 +156,23 @@
(defn delete-shape (defn delete-shape
"Remove the shape using its id." "Remove the shape using its id."
[sid] [id]
(reify (letfn [(dissoc-shape [state {:keys [id] :as shape}]
rs/UpdateEvent (if (= (:type shape) :builtin/group)
(-apply-update [_ state] (let [state (update-in state [:shapes-by-id] dissoc id)]
(let [pageid (get-in state [:shapes-by-id sid :page]) (->> (map #(get-in state [:shapes-by-id %]) (:items shape))
shapes (as-> state $ (reduce dissoc-shape state)))
(get-in $ [:pages-by-id pageid :shapes]) (update-in state [:shapes-by-id] dissoc id)))]
(remove #(= % sid) $) (reify
(into [] $))] rs/UpdateEvent
(-apply-update [_ state]
(let [shape (get-in state [:shapes-by-id id])
pageid (:page shape)
shapes (get-in state [:pages-by-id pageid :shapes])
shapes (into [] (remove #(= % id) shapes))]
(as-> state $ (as-> state $
(assoc-in $ [:pages-by-id pageid :shapes] shapes) (assoc-in $ [:pages-by-id pageid :shapes] shapes)
(update-in $ [:shapes-by-id] dissoc sid)))))) (dissoc-shape $ shape)))))))
(defn move-shape (defn move-shape
"Mark a shape selected for drawing in the canvas." "Mark a shape selected for drawing in the canvas."