0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-18 13:04:38 -05:00

🐛 Use update position for align

This commit is contained in:
Pablo Alba 2023-05-29 13:05:14 +02:00 committed by Andrés Moya
parent c189b5e638
commit 61cad18bcc
2 changed files with 14 additions and 8 deletions

View file

@ -977,6 +977,12 @@
:else :else
(not= uuid/zero (:parent-id (get objects (first selected)))))) (not= uuid/zero (:parent-id (get objects (first selected))))))
(defn- move-shape
[shape]
(let [bbox (-> shape :points gsh/points->selrect)
pos (gpt/point (:x bbox) (:y bbox))]
(dwt/update-position (:id shape) pos)))
(defn align-objects (defn align-objects
[axis] [axis]
(dm/assert! (dm/assert!
@ -992,15 +998,15 @@
moved (if (= 1 (count selected)) moved (if (= 1 (count selected))
(align-object-to-parent objects (first selected) axis) (align-object-to-parent objects (first selected) axis)
(align-objects-list objects selected axis)) (align-objects-list objects selected axis))
moved-objects (->> moved (group-by :id)) ids (map :id moved)
ids (keys moved-objects)
update-fn (fn [shape] (first (get moved-objects (:id shape))))
undo-id (js/Symbol)] undo-id (js/Symbol)]
(when (can-align? selected objects) (when (can-align? selected objects)
(rx/of (dwu/start-undo-transaction undo-id) (rx/concat
(dch/update-shapes ids update-fn {:reg-objects? true}) (rx/of (dwu/start-undo-transaction undo-id))
(ptk/data-event :layout/update ids) (->> (rx/from moved)
(dwu/commit-undo-transaction undo-id))))))) (rx/map move-shape))
(rx/of (ptk/data-event :layout/update ids)
(dwu/commit-undo-transaction undo-id))))))))
(defn align-object-to-parent (defn align-object-to-parent
[objects object-id axis] [objects object-id axis]

View file

@ -685,7 +685,7 @@
(rx/of (nudge-selected-shapes direction shift?))))))) (rx/of (nudge-selected-shapes direction shift?)))))))
(defn update-position (defn update-position
"Move shapes to a new position, from the sidebar options form." "Move shapes to a new position"
[id position] [id position]
(js/console.log "DEBUG" (pr-str position)) (js/console.log "DEBUG" (pr-str position))
(dm/assert! (uuid? id)) (dm/assert! (uuid? id))