Properly remove empty gropups after relocation.

Related to #72.
This commit is contained in:
Andrey Antukh 2017-03-10 10:36:40 +01:00
parent 13e02283d8
commit b313aa47ce
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
2 changed files with 53 additions and 6 deletions

View file

@ -419,6 +419,16 @@
(assert (not (nil? parent-id)) "parent-id should never be nil here")
(update-in state [:shapes parent-id :items] #(into [] (remove #{id}) %)))
(strip-empty-groups [state parent-id]
(if (nil? parent-id)
state
(let [group (get-in state [:shapes parent-id])]
(if (empty? (:items group))
(-> state
(remove-group group)
(strip-empty-groups (:group group)))
state))))
(selective-degroup [state [shape & rest :as shapes]]
(let [group (get-in state [:shapes (:group shape)])
position (get-relocation-position state group)
@ -429,7 +439,8 @@
(-> state
(relocate-shape shape-id parent-id position)
(remove-from-parent shape-id (:id group))))
$ shapes))))]
$ (reverse shapes))
(strip-empty-groups $ (:id group)))))]
(let [shapes (into #{} (map #(get-in state [:shapes %])) shapes)
groups (into #{} (filter #(= (:type %) :group)) shapes)
parents (into #{} (map :group) shapes)]