mirror of
https://github.com/penpot/penpot.git
synced 2025-01-22 14:39:45 -05:00
Improved multiple selection/deselection.
This commit is contained in:
parent
efeaa7a79e
commit
c182340be4
3 changed files with 31 additions and 35 deletions
|
@ -76,6 +76,13 @@
|
|||
(update-in state [:workspace :selected] disj id)
|
||||
(update-in state [:workspace :selected] conj id))))))
|
||||
|
||||
(defn deselect-all
|
||||
"Mark a shape selected for drawing in the canvas."
|
||||
[]
|
||||
(reify
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(assoc-in state [:workspace :selected] #{}))))
|
||||
|
||||
;; TODO: validate shape
|
||||
|
||||
|
|
|
@ -59,22 +59,7 @@
|
|||
;; Mouse Position Stream
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(def immediate-scheduler js/Rx.Scheduler.immediate)
|
||||
(def current-thread-scheduler js/Rx.Scheduler.currentThread)
|
||||
|
||||
(defn observe-on
|
||||
[scheduler ob]
|
||||
(.observeOn ob scheduler))
|
||||
|
||||
(defn subscribe-on
|
||||
[scheduler ob]
|
||||
(.subscribeOn ob scheduler))
|
||||
|
||||
;; (defn window
|
||||
;; [n ob]
|
||||
;; (.windowWithCount ob n))
|
||||
|
||||
(defonce selected-shape-b (rx/bus))
|
||||
(defonce shapes-dragging? (atom false))
|
||||
|
||||
(defonce mouse-b (rx/bus))
|
||||
(defonce mouse-s (rx/dedupe mouse-b))
|
||||
|
@ -94,16 +79,12 @@
|
|||
(rx/buffer 2 1)
|
||||
(rx/map coords-delta)))
|
||||
|
||||
(defonce _subscription_
|
||||
(as-> (rx/with-latest-from vector selected-shape-b mouse-delta-s) $
|
||||
(rx/filter #(not= :nothing (second %)) $)
|
||||
;; (observe-on current-thread-scheduler $)
|
||||
(rx/on-value $ (fn [[delta shape]]
|
||||
(rs/emit! (dw/apply-delta (:id shape) delta))))))
|
||||
|
||||
;; (rx/on-value mouse-delta-s
|
||||
;; (fn [val]
|
||||
;; (println "delta" val))))
|
||||
(defonce $$drag-subscription$$
|
||||
(as-> mouse-delta-s $
|
||||
(rx/filter #(deref shapes-dragging?) $)
|
||||
(rx/on-value $ (fn [delta]
|
||||
(doseq [id @selected-state]
|
||||
(rs/emit! (dw/apply-delta id delta)))))))
|
||||
|
||||
;; Materialized views
|
||||
|
||||
|
|
|
@ -57,20 +57,22 @@
|
|||
[:g {
|
||||
:on-mouse-down
|
||||
(fn [event]
|
||||
(dom/stop-propagation event)
|
||||
(swap! local assoc :init-coords [x y])
|
||||
(rx/push! wb/selected-shape-b shape))
|
||||
(reset! wb/shapes-dragging? true))
|
||||
|
||||
:on-click
|
||||
(fn [ev]
|
||||
(fn [event]
|
||||
(when (= (:init-coords @local) [x y])
|
||||
(rs/emit! (dw/select-shape id))
|
||||
(println "click")))
|
||||
(if (.-ctrlKey event)
|
||||
(rs/emit! (dw/select-shape id))
|
||||
(rs/emit! (dw/deselect-all)
|
||||
(dw/select-shape id)))))
|
||||
|
||||
:on-mouse-up
|
||||
(fn [event]
|
||||
(println "mouse-up")
|
||||
(rx/push! wb/selected-shape-b :nothing)
|
||||
(dom/stop-propagation event))
|
||||
(dom/stop-propagation event)
|
||||
(reset! wb/shapes-dragging? false))
|
||||
}
|
||||
(shapes/render shape)
|
||||
(if (contains? selected id)
|
||||
|
@ -133,10 +135,16 @@
|
|||
:ref "canvas"
|
||||
:width page-width
|
||||
:height page-height
|
||||
|
||||
:on-mouse-down
|
||||
(fn [event]
|
||||
(dom/stop-propagation event)
|
||||
(rs/emit! (dw/deselect-all)))
|
||||
|
||||
:on-mouse-up
|
||||
(fn [event]
|
||||
(rx/push! wb/selected-shape-b :nothing)
|
||||
(dom/stop-propagation event))
|
||||
(dom/stop-propagation event)
|
||||
(reset! wb/shapes-dragging? false))
|
||||
}
|
||||
(background)
|
||||
[:svg.page-layout {}
|
||||
|
|
Loading…
Add table
Reference in a new issue