Move selection with space

This commit is contained in:
alonso.torres 2022-02-07 15:05:38 +01:00
parent 2b1c8cafe9
commit af8e9058a3
3 changed files with 50 additions and 45 deletions

View file

@ -22,6 +22,7 @@
- Add update components in bulk option in context menu [Taiga #1975](https://tree.taiga.io/project/penpot/us/1975) - Add update components in bulk option in context menu [Taiga #1975](https://tree.taiga.io/project/penpot/us/1975)
- Create first E2E tests [Taiga #2608](https://tree.taiga.io/project/penpot/task/2608), [Taiga #2608](https://tree.taiga.io/project/penpot/task/2608) - Create first E2E tests [Taiga #2608](https://tree.taiga.io/project/penpot/task/2608), [Taiga #2608](https://tree.taiga.io/project/penpot/task/2608)
- Redesign of workspace toolbars [Taiga #2319](https://tree.taiga.io/project/penpot/us/2319) - Redesign of workspace toolbars [Taiga #2319](https://tree.taiga.io/project/penpot/us/2319)
- Graphic Tablet usability improvements [Taiga #1913](https://tree.taiga.io/project/penpot/us/1913)
### :bug: Bugs fixed ### :bug: Bugs fixed

View file

@ -45,11 +45,11 @@
(when (= tool :curve) (when (= tool :curve)
(let [stopper (->> stream (rx/filter dwc/interrupt?))] (let [stopper (->> stream (rx/filter dwc/interrupt?))]
(->> stream (->> stream
(rx/take-until stopper)
(rx/filter (ptk/type? ::common/handle-finish-drawing)) (rx/filter (ptk/type? ::common/handle-finish-drawing))
(rx/take 1) (rx/take 1)
(rx/observe-on :async) (rx/observe-on :async)
(rx/map #(select-for-drawing tool data))))) (rx/map #(select-for-drawing tool data))
(rx/take-until stopper))))
;; NOTE: comments are a special case and they manage they ;; NOTE: comments are a special case and they manage they
;; own interrupt cycle.q ;; own interrupt cycle.q

View file

@ -9,7 +9,6 @@
[app.common.data :as d] [app.common.data :as d]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.shapes :as geom] [app.common.geom.shapes :as geom]
[app.common.math :as mth]
[app.common.pages :as cp] [app.common.pages :as cp]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.spec.interactions :as cti] [app.common.spec.interactions :as cti]
@ -48,52 +47,57 @@
(defn handle-area-selection (defn handle-area-selection
[preserve? ignore-groups?] [preserve? ignore-groups?]
(letfn [(data->selrect [data] (ptk/reify ::handle-area-selection
(let [start (:start data) ptk/WatchEvent
stop (:stop data) (watch [_ state stream]
start-x (min (:x start) (:x stop)) (let [zoom (get-in state [:workspace-local :zoom] 1)
start-y (min (:y start) (:y stop)) stop? (fn [event] (or (dwc/interrupt? event) (ms/mouse-up? event)))
end-x (max (:x start) (:x stop)) stoper (->> stream (rx/filter stop?))
end-y (max (:y start) (:y stop))]
{:type :rect
:x start-x
:y start-y
:width (mth/abs (- end-x start-x))
:height (mth/abs (- end-y start-y))}))]
(ptk/reify ::handle-area-selection
ptk/WatchEvent
(watch [_ state stream]
(let [zoom (get-in state [:workspace-local :zoom] 1)
stop? (fn [event] (or (dwc/interrupt? event) (ms/mouse-up? event)))
stoper (->> stream (rx/filter stop?))
calculate-selrect init-selrect
(fn [data pos] {:type :rect
(if data :x (:x @ms/mouse-position)
(assoc data :stop pos) :y (:y @ms/mouse-position)
{:start pos :stop pos})) :width 0
:height 0}
selrect-stream calculate-selrect
(->> ms/mouse-position (fn [selrect [delta space?]]
(rx/scan calculate-selrect nil) (if space?
(rx/map data->selrect) (-> selrect
(rx/filter #(or (> (:width %) (/ 10 zoom)) (update :x + (:x delta))
(> (:height %) (/ 10 zoom)))) (update :y + (:y delta)))
(rx/take-until stoper))]
(rx/concat
(if preserve?
(rx/empty)
(rx/of (deselect-all)))
(rx/merge (-> selrect
(->> selrect-stream (rx/map update-selrect)) (update :width + (:x delta))
(->> selrect-stream (update :height + (:y delta)))))
(rx/buffer-time 100)
(rx/map #(last %))
(rx/dedupe)
(rx/map #(select-shapes-by-current-selrect preserve? ignore-groups?))))
(rx/of (update-selrect nil)))))))) selrect-stream
(->> ms/mouse-position
(rx/buffer 2 1)
(rx/map (fn [[from to]] (when (and from to) (gpt/to-vec from to))))
(rx/filter some?)
(rx/with-latest-from ms/keyboard-space)
(rx/scan calculate-selrect init-selrect)
(rx/filter #(or (> (:width %) (/ 10 zoom))
(> (:height %) (/ 10 zoom))))
(rx/take-until stoper))]
(rx/concat
(if preserve?
(rx/empty)
(rx/of (deselect-all)))
(rx/merge
(->> selrect-stream
(rx/map update-selrect))
(->> selrect-stream
(rx/buffer-time 100)
(rx/map #(last %))
(rx/dedupe)
(rx/map #(select-shapes-by-current-selrect preserve? ignore-groups?))))
(rx/of (update-selrect nil)))))))
;; --- Toggle shape's selection status (selected or deselected) ;; --- Toggle shape's selection status (selected or deselected)