0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 15:39:50 -05:00

🐛 Fix parent handling on duplicate.

This commit is contained in:
Andrey Antukh 2020-06-15 12:02:36 +02:00 committed by Hirunatan
parent df7092e2d4
commit 828455ac27
2 changed files with 15 additions and 16 deletions

View file

@ -777,7 +777,7 @@
(us/verify ::us/uuid parent-id) (us/verify ::us/uuid parent-id)
(us/verify number? to-index) (us/verify number? to-index)
(ptk/reify ::relocate-shape (ptk/reify ::relocate-shapes
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state stream]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)

View file

@ -197,25 +197,24 @@
fit." fit."
[objects names ids delta] [objects names ids delta]
(loop [names names (loop [names names
chgs [] ids (seq ids)
id (first ids) chgs []]
ids (rest ids)] (if ids
(if (nil? id) (let [id (first ids)
chgs result (prepare-duplicate-change objects names id delta)
(let [result (prepare-duplicate-change objects names id delta)
result (if (vector? result) result [result])] result (if (vector? result) result [result])]
(recur (recur
(into names (map change->name) result) (into names (map change->name) result)
(into chgs result) (next ids)
(first ids) (into chgs result)))
(rest ids)))))) chgs)))
(defn- prepare-duplicate-change (defn- prepare-duplicate-change
[objects names id delta] [objects names id delta]
(let [obj (get objects id)] (let [obj (get objects id)]
(if (= :frame (:type obj)) (if (= :frame (:type obj))
(prepare-duplicate-frame-change objects names obj delta) (prepare-duplicate-frame-change objects names obj delta)
(prepare-duplicate-shape-change objects names obj delta nil nil)))) (prepare-duplicate-shape-change objects names obj delta (:frame-id obj) (:parent-id obj)))))
(defn- prepare-duplicate-shape-change (defn- prepare-duplicate-shape-change
[objects names obj delta frame-id parent-id] [objects names obj delta frame-id parent-id]
@ -223,7 +222,7 @@
name (generate-unique-name names (:name obj)) name (generate-unique-name names (:name obj))
renamed-obj (assoc obj :id id :name name) renamed-obj (assoc obj :id id :name name)
moved-obj (geom/move renamed-obj delta) moved-obj (geom/move renamed-obj delta)
frames (cph/select-frames objects) frames (cph/select-frames objects)
frame-id (if frame-id frame-id (if frame-id
frame-id frame-id
(dwc/calculate-frame-overlap frames moved-obj)) (dwc/calculate-frame-overlap frames moved-obj))
@ -283,11 +282,11 @@
(ptk/reify ::duplicate-selected (ptk/reify ::duplicate-selected
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state stream]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
selected (get-in state [:workspace-local :selected]) selected (get-in state [:workspace-local :selected])
objects (get-in state [:workspace-data page-id :objects]) objects (get-in state [:workspace-data page-id :objects])
delta (gpt/point 0 0) delta (gpt/point 0 0)
unames (retrieve-used-names objects) unames (retrieve-used-names objects)
rchanges (prepare-duplicate-changes objects unames selected delta) rchanges (prepare-duplicate-changes objects unames selected delta)
uchanges (mapv #(array-map :type :del-obj :id (:id %)) uchanges (mapv #(array-map :type :del-obj :id (:id %))