0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 23:49:45 -05:00

🐛 Fix problem with non existing children

This commit is contained in:
alonso.torres 2021-07-09 10:40:39 +02:00
parent beaea73276
commit b9b287d3b2
2 changed files with 35 additions and 34 deletions

View file

@ -317,40 +317,41 @@
(defn- prepare-duplicate-shape-change (defn- prepare-duplicate-shape-change
[objects page-id names obj delta frame-id parent-id] [objects page-id names obj delta frame-id parent-id]
(let [id (uuid/next) (when (some? obj)
name (dwc/generate-unique-name names (:name obj)) (let [id (uuid/next)
renamed-obj (assoc obj :id id :name name) name (dwc/generate-unique-name names (:name obj))
moved-obj (geom/move renamed-obj delta) renamed-obj (assoc obj :id id :name name)
frames (cp/select-frames objects) moved-obj (geom/move renamed-obj delta)
parent-id (or parent-id frame-id) frames (cp/select-frames objects)
parent-id (or parent-id frame-id)
children-changes children-changes
(loop [names names (loop [names names
result [] result []
cid (first (:shapes obj)) cid (first (:shapes obj))
cids (rest (:shapes obj))] cids (rest (:shapes obj))]
(if (nil? cid) (if (nil? cid)
result result
(let [obj (get objects cid) (let [obj (get objects cid)
changes (prepare-duplicate-shape-change objects page-id names obj delta frame-id id)] changes (prepare-duplicate-shape-change objects page-id names obj delta frame-id id)]
(recur (recur
(into names (map change->name changes)) (into names (map change->name changes))
(into result changes) (into result changes)
(first cids) (first cids)
(rest cids))))) (rest cids)))))
reframed-obj (-> moved-obj reframed-obj (-> moved-obj
(assoc :frame-id frame-id) (assoc :frame-id frame-id)
(dissoc :shapes))] (dissoc :shapes))]
(into [{:type :add-obj (into [{:type :add-obj
:id id :id id
:page-id page-id :page-id page-id
:old-id (:id obj) :old-id (:id obj)
:frame-id frame-id :frame-id frame-id
:parent-id parent-id :parent-id parent-id
:ignore-touched true :ignore-touched true
:obj (dissoc reframed-obj :shapes)}] :obj (dissoc reframed-obj :shapes)}]
children-changes))) children-changes))))
(defn- prepare-duplicate-frame-change (defn- prepare-duplicate-frame-change
[objects page-id names obj delta] [objects page-id names obj delta]
@ -363,7 +364,7 @@
(assoc :id frame-id) (assoc :id frame-id)
(assoc :name frame-name) (assoc :name frame-name)
(assoc :frame-id uuid/zero) (assoc :frame-id uuid/zero)
(dissoc :shapes) (assoc :shapes [])
(geom/move delta)) (geom/move delta))
fch {:type :add-obj fch {:type :add-obj

View file

@ -138,7 +138,7 @@
(gpt/negate) (gpt/negate)
(gmt/translate-matrix)) (gmt/translate-matrix))
update-fn #(assoc-in %1 [%2 :modifiers :displacement] modifier) update-fn #(d/update-when %1 %2 assoc-in [:modifiers :displacement] modifier)
objects (->> (d/concat [frame-id] (cp/get-children frame-id objects)) objects (->> (d/concat [frame-id] (cp/get-children frame-id objects))
(reduce update-fn objects)) (reduce update-fn objects))