Allow select multiple frames and extend selrect with shift

This commit is contained in:
Andrés Moya 2020-12-11 15:12:07 +01:00 committed by Andrey Antukh
parent 6ed470ed5f
commit 9822c52573
3 changed files with 41 additions and 26 deletions

View file

@ -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,7 +67,8 @@
(ms/mouse-up? %)) (ms/mouse-up? %))
stream)] stream)]
(rx/concat (rx/concat
(rx/of (deselect-all)) (when-not preserve?
(rx/of (deselect-all)))
(->> ms/mouse-position (->> ms/mouse-position
(rx/scan (fn [data pos] (rx/scan (fn [data pos]
(if data (if data
@ -78,7 +80,7 @@
(> (:height %) 10))) (> (:height %) 10)))
(rx/map update-selrect) (rx/map update-selrect)
(rx/take-until stoper)) (rx/take-until stoper))
(rx/of select-shapes-by-current-selrect))))))) (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,11 +159,16 @@
;; --- 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
@ -173,7 +180,7 @@
(->> (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

View file

@ -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)]))

View file

@ -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)))))