0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-23 15:09:10 -05:00

Change to add when selected shape

This commit is contained in:
alonso.torres 2021-02-03 11:09:59 +01:00 committed by Hirunatan
parent b7e266e350
commit 69b4968578

View file

@ -536,20 +536,26 @@
(defn get-shape-layer-position
[objects selected attrs]
(cond
(= :frame (:type attrs))
(if (= :frame (:type attrs))
;; Frames are alwasy positioned on the root frame
[uuid/zero uuid/zero nil]
(empty? selected)
;; Calculate the frame over which we're drawing
(let [position @ms/mouse-position
frame-id (:frame-id attrs (cp/frame-id-by-position objects position))]
[frame-id frame-id nil])
frame-id (:frame-id attrs (cp/frame-id-by-position objects position))
shape (when-not (empty? selected)
(cp/get-base-shape objects selected))]
:else
(let [shape (cp/get-base-shape objects selected)
index (cp/position-on-parent (:id shape) objects)
{:keys [frame-id parent-id]} shape]
[frame-id parent-id (inc index)])))
;; When no shapes has been selected or we're over a different frame
;; we add it as the latest shape of that frame
(if (or (not shape) (not= (:frame-id shape) frame-id))
[frame-id frame-id nil]
;; Otherwise, we add it to next to the selected shape
(let [index (cp/position-on-parent (:id shape) objects)
{:keys [frame-id parent-id]} shape]
[frame-id parent-id (inc index)])))))
(defn add-shape-changes
[page-id objects selected attrs]
@ -562,6 +568,9 @@
shape (merge default-attrs shape)
not-frame? #(not (= :frame (get-in objects [% :type])))
selected (into #{} (filter not-frame?) selected)
[frame-id parent-id index] (get-shape-layer-position objects selected attrs)
redo-changes [{:type :add-obj