mirror of
https://github.com/penpot/penpot.git
synced 2025-07-30 14:28:23 +02:00
🐛 Fix shape leaking on deletion when is grouped.
This commit is contained in:
parent
2d4e76619f
commit
7fb897a7ad
3 changed files with 22 additions and 6 deletions
|
@ -440,9 +440,16 @@
|
||||||
(defmethod process-change :del-obj
|
(defmethod process-change :del-obj
|
||||||
[data {:keys [id] :as change}]
|
[data {:keys [id] :as change}]
|
||||||
(when-let [{:keys [frame-id shapes] :as obj} (get-in data [:objects id])]
|
(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
|
(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)))
|
(update-in [:objects frame-id :shapes] (fn [s] (filterv #(not= % id) s)))
|
||||||
|
|
||||||
(seq shapes) ; Recursive delete all dependend objects
|
(seq shapes) ; Recursive delete all dependend objects
|
||||||
|
|
|
@ -659,18 +659,27 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
session-id (:session-id state)
|
|
||||||
objects (get-in state [:workspace-data page-id :objects])
|
objects (get-in state [:workspace-data page-id :objects])
|
||||||
cpindex (cp/calculate-child-parent-map objects)
|
cpindex (cp/calculate-child-parent-map objects)
|
||||||
|
|
||||||
del-change #(array-map :type :del-obj :id %)
|
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
|
rchanges
|
||||||
(reduce (fn [res id]
|
(reduce (fn [res id]
|
||||||
(let [chd (cp/get-children id objects)]
|
(let [chd (cp/get-children id objects)]
|
||||||
(into res (d/concat
|
(into res (d/concat
|
||||||
(mapv del-change (reverse chd))
|
(mapv del-change (reverse chd))
|
||||||
[(del-change id)]))))
|
[(del-change id)]
|
||||||
|
(map del-change (get-empty-parents id))))))
|
||||||
[]
|
[]
|
||||||
ids)
|
ids)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue