mirror of
https://github.com/penpot/penpot.git
synced 2025-02-18 21:06:11 -05:00
✨ Shift+select path nodes
This commit is contained in:
parent
07799d9b01
commit
74a09301a7
3 changed files with 66 additions and 29 deletions
|
@ -62,10 +62,18 @@
|
||||||
page-id (:current-page-id state)
|
page-id (:current-page-id state)
|
||||||
shape (get-in state (st/get-path state))
|
shape (get-in state (st/get-path state))
|
||||||
content-modifiers (get-in state [:workspace-local :edit-path id :content-modifiers])
|
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)]
|
[rch uch] (changes/generate-path-changes page-id shape (:content shape) new-content)]
|
||||||
|
|
||||||
(rx/of (dwc/commit-changes rch uch {:commit-local? true})
|
(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)))))))
|
(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]
|
(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 :moving-nodes] true)
|
||||||
(assoc-in [:workspace-local :edit-path id :content-modifiers] modifiers)))))))
|
(assoc-in [:workspace-local :edit-path id :content-modifiers] modifiers)))))))
|
||||||
|
|
||||||
|
(declare drag-selected-points)
|
||||||
|
|
||||||
(defn start-move-path-point
|
(defn start-move-path-point
|
||||||
[position shift?]
|
[position shift?]
|
||||||
(ptk/reify ::start-move-path-point
|
(ptk/reify ::start-move-path-point
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [start-position @ms/mouse-position
|
(let [id (get-in state [:workspace-local :edition])
|
||||||
stopper (->> stream (rx/filter ms/mouse-up?))
|
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])
|
zoom (get-in state [:workspace-local :zoom])
|
||||||
id (get-in state [:workspace-local :edition])
|
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])
|
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))
|
content (get-in state (st/get-path state :content))
|
||||||
points (ugp/content->points content)
|
points (ugp/content->points content)]
|
||||||
|
|
||||||
mouse-drag-stream
|
|
||||||
(rx/concat
|
(rx/concat
|
||||||
;; This stream checks the consecutive mouse positions to do the draging
|
;; This stream checks the consecutive mouse positions to do the draging
|
||||||
(->> points
|
(->> points
|
||||||
(streams/move-points-stream snap-toggled start-position selected-points)
|
(streams/move-points-stream snap-toggled start-position selected-points)
|
||||||
(rx/take-until stopper)
|
(rx/take-until stopper)
|
||||||
(rx/map #(move-selected-path-point start-position %)))
|
(rx/map #(move-selected-path-point start-position %)))
|
||||||
(rx/of (apply-content-modifiers)))
|
(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)))))
|
|
||||||
|
|
||||||
(defn start-move-handler
|
(defn start-move-handler
|
||||||
[index prefix]
|
[index prefix]
|
||||||
|
|
|
@ -49,9 +49,11 @@
|
||||||
(let [selrect (get-in state [:workspace-local :selrect])
|
(let [selrect (get-in state [:workspace-local :selrect])
|
||||||
id (get-in state [:workspace-local :edition])
|
id (get-in state [:workspace-local :edition])
|
||||||
content (get-in state (st/get-path state :content))
|
content (get-in state (st/get-path state :content))
|
||||||
selected-point? (fn [point]
|
selected-point? #(gsh/has-point-rect? selrect %)
|
||||||
(gsh/has-point-rect? selrect point))
|
|
||||||
positions (into #{}
|
selected-points (get-in state [:workspace-local :edit-path id :selected-points])
|
||||||
|
|
||||||
|
positions (into (if shift? selected-points #{})
|
||||||
(comp (map (comp gpt/point :params))
|
(comp (map (comp gpt/point :params))
|
||||||
(filter selected-point?))
|
(filter selected-point?))
|
||||||
content)]
|
content)]
|
||||||
|
@ -59,14 +61,24 @@
|
||||||
(some? id)
|
(some? id)
|
||||||
(assoc-in [:workspace-local :edit-path id :selected-points] positions))))))
|
(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/reify ::select-node
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(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
|
(cond-> state
|
||||||
(some? id)
|
(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?]
|
(defn deselect-node [position shift?]
|
||||||
(ptk/reify ::deselect-node
|
(ptk/reify ::deselect-node
|
||||||
|
@ -142,3 +154,14 @@
|
||||||
|
|
||||||
(rx/of (select-node-area shift?)
|
(rx/of (select-node-area shift?)
|
||||||
(clear-area-selection))))))))
|
(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))))))
|
||||||
|
|
|
@ -44,9 +44,7 @@
|
||||||
(cond
|
(cond
|
||||||
(= edit-mode :move)
|
(= edit-mode :move)
|
||||||
;; If we're dragging a selected item we don't change the selection
|
;; If we're dragging a selected item we don't change the selection
|
||||||
(do (when (not selected?)
|
(st/emit! (drp/start-move-path-point position shift?))
|
||||||
(st/emit! (drp/select-node position shift?)))
|
|
||||||
(st/emit! (drp/start-move-path-point position shift?)))
|
|
||||||
|
|
||||||
(and (= edit-mode :draw) start-path?)
|
(and (= edit-mode :draw) start-path?)
|
||||||
(st/emit! (drp/start-path-from-point position))
|
(st/emit! (drp/start-path-from-point position))
|
||||||
|
|
Loading…
Add table
Reference in a new issue