0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-04-03 10:31:38 -05:00

Minor improvements on shape selection.

This commit is contained in:
Andrey Antukh 2019-12-20 10:51:14 +01:00
parent 78509f3a06
commit f906945101
4 changed files with 27 additions and 20 deletions

View file

@ -573,6 +573,7 @@
(assoc-in $ [:workspace-data :shapes-by-id id] shape))))
(declare commit-shapes-changes)
(declare select-shape)
(declare recalculate-shape-canvas-relation)
(defn add-shape
@ -589,7 +590,8 @@
ptk/WatchEvent
(watch [_ state stream]
(let [shape (get-in state [:workspace-data :shapes-by-id id])]
(rx/of (commit-shapes-changes [[:add-shape id shape]])))))))
(rx/of (commit-shapes-changes [[:add-shape id shape]])
(select-shape id)))))))
;; --- Duplicate Selected
@ -612,7 +614,6 @@
;; --- Toggle shape's selection status (selected or deselected)
(defn select-shape
"Mark a shape selected for drawing."
[id]
(s/assert ::us/uuid id)
(ptk/reify ::select-shape
@ -638,18 +639,6 @@
(assoc :selected #{})
(dissoc :selected-canvas))))))
;; --- Select First Shape
;; TODO: first???
(def select-first-shape
(ptk/reify ::select-first-shape
ptk/UpdateEvent
(update [_ state]
(let [pid (get-in state [:workspace-local :id])
sid (first (get-in state [:workspace-data :shapes]))]
(assoc-in state [:workspace-local :selected] #{sid})))))
;; --- Select Shapes (By selrect)
(defn- impl-try-match-shape
@ -1034,10 +1023,29 @@
(ptk/reify ::select-for-drawing
ptk/UpdateEvent
(update [_ state]
(update state :workspace-local assoc :drawing-tool tool :drawing data)))))
(update state :workspace-local assoc :drawing-tool tool :drawing data))
ptk/WatchEvent
(watch [_ state stream]
(let [cancel-event? (fn [event]
(interrupt? event))
stoper (rx/filter (ptk/type? ::clear-drawing) stream)]
(->> (rx/filter cancel-event? stream)
(rx/take 1)
(rx/map (constantly clear-drawing))
(rx/take-until stoper)))))))
;; --- Shape Proportions
;; (defn toggle-shape-proportion-lock
;; [id]
;; (ptk/reify ::toggle-shape-proportion-lock
;; ptk/UpdateEvent
;; (update [_ state]
;; (let [shape (-> (get-in state [:workspace-data :shapes-by-id id])
;; (geom/size)
;; TODO: revisit
(deftype LockShapeProportions [id]

View file

@ -119,7 +119,7 @@
[:& messages-widget]
[:& header {:page page :layout layout :flags flags}]
(when (:colorpalette flags)
(when (:colorpalette layout)
[:& colorpalette])
(when (and layout page)

View file

@ -280,9 +280,8 @@
(geom/transform shape modifier-mtx)
shape)
shape (dissoc shape ::initialized? :modifier-mtx)]
;; Add & select the cred shape to the workspace
(rx/of (dw/add-shape shape)
dw/select-first-shape))))))))
;; Add & select the created shape to the workspace
(rx/of (dw/add-shape shape)))))))))
(def close-drawing-path
(ptk/reify ::close-drawing-path

View file

@ -40,7 +40,7 @@
:ctrl+b #(st/emit! (dw/select-for-drawing :rect))
:ctrl+e #(st/emit! (dw/select-for-drawing :circle))
:ctrl+t #(st/emit! (dw/select-for-drawing :text))
:esc #(st/emit! dw/deselect-all)
:esc #(st/emit! :interrupt dw/deselect-all)
:delete #(st/emit! dw/delete-selected)
:ctrl+up #(st/emit! (dw/order-selected-shapes :up))
:ctrl+down #(st/emit! (dw/order-selected-shapes :down))