mirror of
https://github.com/penpot/penpot.git
synced 2025-03-17 10:11:22 -05:00
🐛 Fix when trying to relocate a shape and their children
This commit is contained in:
parent
1c098d9b04
commit
4b9ac6f1e5
5 changed files with 22 additions and 16 deletions
|
@ -46,6 +46,7 @@
|
|||
(d/export helpers/get-parent)
|
||||
(d/export helpers/get-parents)
|
||||
(d/export helpers/generate-child-parent-index)
|
||||
(d/export helpers/clean-loops)
|
||||
(d/export helpers/calculate-invalid-targets)
|
||||
(d/export helpers/valid-frame-target)
|
||||
(d/export helpers/position-on-parent)
|
||||
|
|
|
@ -169,6 +169,20 @@
|
|||
(assoc index id (:parent-id obj)))
|
||||
{} objects))
|
||||
|
||||
(defn clean-loops
|
||||
"Clean a list of ids from circular references."
|
||||
[objects ids]
|
||||
(loop [ids ids
|
||||
id (first ids)
|
||||
others (rest ids)]
|
||||
(if-not id
|
||||
ids
|
||||
(recur (cond-> ids
|
||||
(some #(contains? ids %) (get-parents id objects))
|
||||
(disj id))
|
||||
(first others)
|
||||
(rest others)))))
|
||||
|
||||
(defn calculate-invalid-targets
|
||||
[shape-id objects]
|
||||
(let [result #{shape-id}
|
||||
|
|
|
@ -816,6 +816,10 @@
|
|||
(watch [_ state stream]
|
||||
(let [page-id (:current-page-id state)
|
||||
objects (dwc/lookup-page-objects state page-id)
|
||||
|
||||
;; Ignore any shape whose parent is also intented to be moved
|
||||
ids (cp/clean-loops objects ids)
|
||||
|
||||
parents (loop [res #{parent-id}
|
||||
ids (seq ids)]
|
||||
(if (nil? ids)
|
||||
|
|
|
@ -95,20 +95,6 @@
|
|||
;; GROUPS
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defn- clean-selected
|
||||
"A helper that cleans selected from circular references."
|
||||
[objects selected]
|
||||
(loop [selected selected
|
||||
id (first selected)
|
||||
items (rest selected)]
|
||||
(if-not id
|
||||
selected
|
||||
(recur (cond-> selected
|
||||
(some #(contains? selected %) (cp/get-parents id objects))
|
||||
(disj id))
|
||||
(first items)
|
||||
(rest items)))))
|
||||
|
||||
(def group-selected
|
||||
(ptk/reify ::group-selected
|
||||
ptk/WatchEvent
|
||||
|
@ -116,7 +102,7 @@
|
|||
(let [page-id (:current-page-id state)
|
||||
objects (dwc/lookup-page-objects state page-id)
|
||||
selected (get-in state [:workspace-local :selected])
|
||||
selected (clean-selected objects selected)
|
||||
selected (cp/clean-loops objects selected)
|
||||
shapes (shapes-for-grouping objects selected)]
|
||||
(when-not (empty? shapes)
|
||||
(let [[group rchanges uchanges] (prepare-create-group page-id shapes "Group-" false)]
|
||||
|
|
|
@ -148,7 +148,8 @@
|
|||
(merge-attrs (select-keys shape attrs))
|
||||
(merge-attrs (ut/get-text-attrs-multi content attrs)))]
|
||||
:children (let [children (->> (:shapes shape []) (map #(get objects %)))]
|
||||
(get-attrs children objects attr-type)))]
|
||||
(get-attrs children objects attr-type))
|
||||
[])]
|
||||
result))]
|
||||
(reduce extract-attrs [[] []] shapes)))
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue