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,18 +47,6 @@
(defn handle-area-selection (defn handle-area-selection
[preserve? ignore-groups?] [preserve? ignore-groups?]
(letfn [(data->selrect [data]
(let [start (:start data)
stop (:stop data)
start-x (min (:x start) (:x stop))
start-y (min (:y start) (:y stop))
end-x (max (:x start) (:x 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/reify ::handle-area-selection
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state stream]
@ -67,16 +54,31 @@
stop? (fn [event] (or (dwc/interrupt? event) (ms/mouse-up? event))) stop? (fn [event] (or (dwc/interrupt? event) (ms/mouse-up? event)))
stoper (->> stream (rx/filter stop?)) stoper (->> stream (rx/filter stop?))
init-selrect
{:type :rect
:x (:x @ms/mouse-position)
:y (:y @ms/mouse-position)
:width 0
:height 0}
calculate-selrect calculate-selrect
(fn [data pos] (fn [selrect [delta space?]]
(if data (if space?
(assoc data :stop pos) (-> selrect
{:start pos :stop pos})) (update :x + (:x delta))
(update :y + (:y delta)))
(-> selrect
(update :width + (:x delta))
(update :height + (:y delta)))))
selrect-stream selrect-stream
(->> ms/mouse-position (->> ms/mouse-position
(rx/scan calculate-selrect nil) (rx/buffer 2 1)
(rx/map data->selrect) (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)) (rx/filter #(or (> (:width %) (/ 10 zoom))
(> (:height %) (/ 10 zoom)))) (> (:height %) (/ 10 zoom))))
(rx/take-until stoper))] (rx/take-until stoper))]
@ -86,14 +88,16 @@
(rx/of (deselect-all))) (rx/of (deselect-all)))
(rx/merge (rx/merge
(->> selrect-stream (rx/map update-selrect)) (->> selrect-stream
(rx/map update-selrect))
(->> selrect-stream (->> selrect-stream
(rx/buffer-time 100) (rx/buffer-time 100)
(rx/map #(last %)) (rx/map #(last %))
(rx/dedupe) (rx/dedupe)
(rx/map #(select-shapes-by-current-selrect preserve? ignore-groups?)))) (rx/map #(select-shapes-by-current-selrect preserve? ignore-groups?))))
(rx/of (update-selrect nil)))))))) (rx/of (update-selrect nil)))))))
;; --- Toggle shape's selection status (selected or deselected) ;; --- Toggle shape's selection status (selected or deselected)