mirror of
https://github.com/penpot/penpot.git
synced 2025-02-13 18:48:37 -05:00
✨ Allow select multiple frames and extend selrect with shift
This commit is contained in:
parent
6ed470ed5f
commit
9822c52573
3 changed files with 41 additions and 26 deletions
|
@ -46,7 +46,8 @@
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(assoc-in state [:workspace-local :selrect] selrect))))
|
(assoc-in state [:workspace-local :selrect] selrect))))
|
||||||
|
|
||||||
(def handle-selection
|
(defn handle-selection
|
||||||
|
[preserve?]
|
||||||
(letfn [(data->selrect [data]
|
(letfn [(data->selrect [data]
|
||||||
(let [start (:start data)
|
(let [start (:start data)
|
||||||
stop (:stop data)
|
stop (:stop data)
|
||||||
|
@ -66,19 +67,20 @@
|
||||||
(ms/mouse-up? %))
|
(ms/mouse-up? %))
|
||||||
stream)]
|
stream)]
|
||||||
(rx/concat
|
(rx/concat
|
||||||
(rx/of (deselect-all))
|
(when-not preserve?
|
||||||
(->> ms/mouse-position
|
(rx/of (deselect-all)))
|
||||||
(rx/scan (fn [data pos]
|
(->> ms/mouse-position
|
||||||
(if data
|
(rx/scan (fn [data pos]
|
||||||
(assoc data :stop pos)
|
(if data
|
||||||
{:start pos :stop pos}))
|
(assoc data :stop pos)
|
||||||
nil)
|
{:start pos :stop pos}))
|
||||||
(rx/map data->selrect)
|
nil)
|
||||||
(rx/filter #(or (> (:width %) 10)
|
(rx/map data->selrect)
|
||||||
(> (:height %) 10)))
|
(rx/filter #(or (> (:width %) 10)
|
||||||
(rx/map update-selrect)
|
(> (:height %) 10)))
|
||||||
(rx/take-until stoper))
|
(rx/map update-selrect)
|
||||||
(rx/of select-shapes-by-current-selrect)))))))
|
(rx/take-until stoper))
|
||||||
|
(rx/of (select-shapes-by-current-selrect preserve?))))))))
|
||||||
|
|
||||||
;; --- Toggle shape's selection status (selected or deselected)
|
;; --- Toggle shape's selection status (selected or deselected)
|
||||||
|
|
||||||
|
@ -157,24 +159,29 @@
|
||||||
|
|
||||||
;; --- Select Shapes (By selrect)
|
;; --- Select Shapes (By selrect)
|
||||||
|
|
||||||
(def select-shapes-by-current-selrect
|
(defn select-shapes-by-current-selrect
|
||||||
|
[preserve?]
|
||||||
(ptk/reify ::select-shapes-by-current-selrect
|
(ptk/reify ::select-shapes-by-current-selrect
|
||||||
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])
|
||||||
|
initial-set (if preserve?
|
||||||
|
selected
|
||||||
|
lks/empty-linked-set)
|
||||||
selrect (get-in state [:workspace-local :selrect])
|
selrect (get-in state [:workspace-local :selrect])
|
||||||
is-not-blocked (fn [shape-id] (not (get-in state [:workspace-data
|
is-not-blocked (fn [shape-id] (not (get-in state [:workspace-data
|
||||||
:pages-index page-id
|
:pages-index page-id
|
||||||
:objects shape-id
|
:objects shape-id
|
||||||
:blocked] false)))]
|
:blocked] false)))]
|
||||||
(rx/merge
|
(rx/merge
|
||||||
(rx/of (update-selrect nil))
|
(rx/of (update-selrect nil))
|
||||||
(when selrect
|
(when selrect
|
||||||
(->> (uw/ask! {:cmd :selection/query
|
(->> (uw/ask! {:cmd :selection/query
|
||||||
:page-id page-id
|
:page-id page-id
|
||||||
:rect selrect})
|
:rect selrect})
|
||||||
(rx/map #(into lks/empty-linked-set (filter is-not-blocked) %))
|
(rx/map #(into initial-set (filter is-not-blocked) %))
|
||||||
(rx/map select-shapes))))))))
|
(rx/map select-shapes))))))))
|
||||||
|
|
||||||
(defn select-inside-group
|
(defn select-inside-group
|
||||||
[group-id position]
|
[group-id position]
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
[app.main.data.workspace :as dw]
|
[app.main.data.workspace :as dw]
|
||||||
[app.main.refs :as refs]
|
[app.main.refs :as refs]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
|
[app.main.ui.keyboard :as kbd]
|
||||||
[app.main.ui.shapes.frame :as frame]
|
[app.main.ui.shapes.frame :as frame]
|
||||||
[app.main.ui.shapes.shape :refer [shape-container]]
|
[app.main.ui.shapes.shape :refer [shape-container]]
|
||||||
[app.main.ui.workspace.effects :as we]
|
[app.main.ui.workspace.effects :as we]
|
||||||
|
@ -44,9 +45,16 @@
|
||||||
(mf/use-callback
|
(mf/use-callback
|
||||||
(mf/deps id)
|
(mf/deps id)
|
||||||
(fn [event]
|
(fn [event]
|
||||||
|
(let [selected @refs/selected-shapes
|
||||||
|
selected? (contains? selected id)]
|
||||||
(dom/prevent-default event)
|
(dom/prevent-default event)
|
||||||
(st/emit! (dw/deselect-all)
|
(if selected?
|
||||||
(dw/select-shape id)))))
|
(when (kbd/shift? event)
|
||||||
|
(st/emit! (dw/select-shape id true)))
|
||||||
|
(do
|
||||||
|
(when-not (or (empty? selected) (kbd/shift? event))
|
||||||
|
(st/emit! (dw/deselect-all)))
|
||||||
|
(st/emit! (dw/select-shape id))))))))
|
||||||
|
|
||||||
;; Ensure that the label has always the same font
|
;; Ensure that the label has always the same font
|
||||||
;; size, regardless of zoom
|
;; size, regardless of zoom
|
||||||
|
@ -72,7 +80,7 @@
|
||||||
:height 20
|
:height 20
|
||||||
:class "workspace-frame-label"
|
:class "workspace-frame-label"
|
||||||
:transform (text-transform label-pos zoom)
|
:transform (text-transform label-pos zoom)
|
||||||
:on-click handle-click
|
:on-mouse-down handle-click
|
||||||
:on-pointer-over handle-pointer-enter
|
:on-pointer-over handle-pointer-enter
|
||||||
:on-pointer-out handle-pointer-leave}
|
:on-pointer-out handle-pointer-leave}
|
||||||
(:name frame)]))
|
(:name frame)]))
|
||||||
|
|
|
@ -241,7 +241,7 @@
|
||||||
(if drawing-tool
|
(if drawing-tool
|
||||||
(when (not (#{:comments :path} drawing-tool))
|
(when (not (#{:comments :path} drawing-tool))
|
||||||
(st/emit! (dd/start-drawing drawing-tool)))
|
(st/emit! (dd/start-drawing drawing-tool)))
|
||||||
(st/emit! dw/handle-selection))
|
(st/emit! (dw/handle-selection shift?)))
|
||||||
|
|
||||||
(and (= 2 (.-which event)))
|
(and (= 2 (.-which event)))
|
||||||
(handle-viewport-positioning viewport-ref)))))
|
(handle-viewport-positioning viewport-ref)))))
|
||||||
|
|
Loading…
Add table
Reference in a new issue