0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-23 23:18:48 -05:00

🐛 Fix shape leaking on deletion when is grouped.

This commit is contained in:
Andrey Antukh 2020-06-10 08:29:13 +02:00
parent 2d4e76619f
commit 7fb897a7ad
3 changed files with 22 additions and 6 deletions

View file

@ -440,9 +440,16 @@
(defmethod process-change :del-obj
[data {:keys [id] :as change}]
(when-let [{:keys [frame-id shapes] :as obj} (get-in data [:objects id])]
(let [data (update data :objects dissoc id)]
(let [objects (:objects data)
parent-id (get-parent id objects)
parent (get objects parent-id)
data (update data :objects dissoc id)]
(cond-> data
(contains? (:objects data) frame-id)
(and (not= parent-id frame-id)
(= :group (:type parent)))
(update-in [:objects parent-id :shapes] (fn [s] (filterv #(not= % id) s)))
(contains? objects frame-id)
(update-in [:objects frame-id :shapes] (fn [s] (filterv #(not= % id) s)))
(seq shapes) ; Recursive delete all dependend objects

View file

@ -659,18 +659,27 @@
ptk/WatchEvent
(watch [_ state stream]
(let [page-id (:current-page-id state)
session-id (:session-id state)
objects (get-in state [:workspace-data page-id :objects])
cpindex (cp/calculate-child-parent-map objects)
del-change #(array-map :type :del-obj :id %)
get-empty-parents
(fn get-empty-parents [id]
(let [parent (get objects (get cpindex id))]
(if (and (= :group (:type parent))
(= 1 (count (:shapes parent))))
(lazy-seq (cons (:id parent)
(get-empty-parents (:id parent))))
nil)))
rchanges
(reduce (fn [res id]
(let [chd (cp/get-children id objects)]
(into res (d/concat
(mapv del-change (reverse chd))
[(del-change id)]))))
[(del-change id)]
(map del-change (get-empty-parents id))))))
[]
ids)

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 [to-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 to-index)))))
(st/emit! (dw/relocate-shape id parent-id to-index)))))
on-hold
(fn []