0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-13 10:38:13 -05:00

Shift+select path nodes

This commit is contained in:
alonso.torres 2021-04-14 13:24:55 +02:00 committed by Andrés Moya
parent 07799d9b01
commit 74a09301a7
3 changed files with 66 additions and 29 deletions

View file

@ -62,10 +62,18 @@
page-id (:current-page-id state)
shape (get-in state (st/get-path state))
content-modifiers (get-in state [:workspace-local :edit-path id :content-modifiers])
new-content (ugp/apply-content-modifiers (:content shape) content-modifiers)
content (:content shape)
new-content (ugp/apply-content-modifiers content content-modifiers)
old-points (->> content ugp/content->points)
new-points (->> new-content ugp/content->points)
point-change (->> (map hash-map old-points new-points) (reduce merge))
[rch uch] (changes/generate-path-changes page-id shape (:content shape) new-content)]
(rx/of (dwc/commit-changes rch uch {:commit-local? true})
(selection/update-selection point-change)
(fn [state] (update-in state [:workspace-local :edit-path id] dissoc :content-modifiers :moving-nodes :moving-handler)))))))
(defn move-selected-path-point [from-point to-point]
@ -108,36 +116,44 @@
(assoc-in [:workspace-local :edit-path id :moving-nodes] true)
(assoc-in [:workspace-local :edit-path id :content-modifiers] modifiers)))))))
(declare drag-selected-points)
(defn start-move-path-point
[position shift?]
(ptk/reify ::start-move-path-point
ptk/WatchEvent
(watch [_ state stream]
(let [start-position @ms/mouse-position
stopper (->> stream (rx/filter ms/mouse-up?))
(let [id (get-in state [:workspace-local :edition])
selected-points (get-in state [:workspace-local :edit-path id :selected-points] #{})
selected? (contains? selected-points position)]
(streams/drag-stream
(rx/of
(when-not selected? (selection/select-node position shift? "drag"))
(drag-selected-points @ms/mouse-position))
(rx/of (selection/select-node position shift? "click")))))))
(defn drag-selected-points
[start-position]
(ptk/reify ::drag-selected-points
ptk/WatchEvent
(watch [_ state stream]
(let [stopper (->> stream (rx/filter ms/mouse-up?))
zoom (get-in state [:workspace-local :zoom])
id (get-in state [:workspace-local :edition])
selected-points (get-in state [:workspace-local :edit-path id :selected-points] #{})
snap-toggled (get-in state [:workspace-local :edit-path id :snap-toggled])
selected? (contains? selected-points position)
selected-points (get-in state [:workspace-local :edit-path id :selected-points] #{})
content (get-in state (st/get-path state :content))
points (ugp/content->points content)
points (ugp/content->points content)]
mouse-drag-stream
(rx/concat
;; This stream checks the consecutive mouse positions to do the draging
(->> points
(streams/move-points-stream snap-toggled start-position selected-points)
(rx/take-until stopper)
(rx/map #(move-selected-path-point start-position %)))
(rx/of (apply-content-modifiers)))
;; When there is not drag we select the node
mouse-click-stream
(rx/of (selection/select-node position shift?))]
(streams/drag-stream mouse-drag-stream mouse-click-stream)))))
(rx/concat
;; This stream checks the consecutive mouse positions to do the draging
(->> points
(streams/move-points-stream snap-toggled start-position selected-points)
(rx/take-until stopper)
(rx/map #(move-selected-path-point start-position %)))
(rx/of (apply-content-modifiers)))))))
(defn start-move-handler
[index prefix]

View file

@ -49,9 +49,11 @@
(let [selrect (get-in state [:workspace-local :selrect])
id (get-in state [:workspace-local :edition])
content (get-in state (st/get-path state :content))
selected-point? (fn [point]
(gsh/has-point-rect? selrect point))
positions (into #{}
selected-point? #(gsh/has-point-rect? selrect %)
selected-points (get-in state [:workspace-local :edit-path id :selected-points])
positions (into (if shift? selected-points #{})
(comp (map (comp gpt/point :params))
(filter selected-point?))
content)]
@ -59,14 +61,24 @@
(some? id)
(assoc-in [:workspace-local :edit-path id :selected-points] positions))))))
(defn select-node [position shift?]
(defn select-node [position shift? kk]
(ptk/reify ::select-node
ptk/UpdateEvent
(update [_ state]
(let [id (get-in state [:workspace-local :edition])]
(let [id (get-in state [:workspace-local :edition])
selected-points (or (get-in state [:workspace-local :edit-path id :selected-points]) #{})
selected-points (cond
(and shift? (contains? selected-points position))
(disj selected-points position)
shift?
(conj selected-points position)
:else
#{position})]
(cond-> state
(some? id)
(assoc-in [:workspace-local :edit-path id :selected-points] #{position}))))))
(assoc-in [:workspace-local :edit-path id :selected-points] selected-points))))))
(defn deselect-node [position shift?]
(ptk/reify ::deselect-node
@ -142,3 +154,14 @@
(rx/of (select-node-area shift?)
(clear-area-selection))))))))
(defn update-selection
[point-change]
(ptk/reify ::update-selection
ptk/UpdateEvent
(update [_ state]
(let [id (st/get-path-id state)
selected-points (get-in state [:workspace-local :edit-path id :selected-points] #{})
selected-points (into #{} (map point-change) selected-points)]
(-> state
(assoc-in [:workspace-local :edit-path id :selected-points] selected-points))))))

View file

@ -44,9 +44,7 @@
(cond
(= edit-mode :move)
;; If we're dragging a selected item we don't change the selection
(do (when (not selected?)
(st/emit! (drp/select-node position shift?)))
(st/emit! (drp/start-move-path-point position shift?)))
(st/emit! (drp/start-move-path-point position shift?))
(and (= edit-mode :draw) start-path?)
(st/emit! (drp/start-path-from-point position))