mirror of
https://github.com/penpot/penpot.git
synced 2025-04-04 19:11:20 -05:00
✨ Use remove to delete guides
This commit is contained in:
parent
bb68838fa4
commit
d24f16563f
5 changed files with 48 additions and 9 deletions
|
@ -747,14 +747,21 @@
|
|||
|
||||
;; --- Delete Selected
|
||||
|
||||
(def delete-selected
|
||||
(defn delete-selected
|
||||
"Deselect all and remove all selected shapes."
|
||||
[]
|
||||
(ptk/reify ::delete-selected
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(let [selected (wsh/lookup-selected state)]
|
||||
(rx/of (dwc/delete-shapes selected)
|
||||
(dws/deselect-all))))))
|
||||
(let [selected (wsh/lookup-selected state)
|
||||
hover-guides (get-in state [:workspace-guides :hover])]
|
||||
(cond
|
||||
(d/not-empty? selected)
|
||||
(rx/of (dwc/delete-shapes selected)
|
||||
(dws/deselect-all))
|
||||
|
||||
(d/not-empty? hover-guides)
|
||||
(rx/of (dwgu/remove-guides hover-guides)))))))
|
||||
|
||||
;; --- Shape Vertical Ordering
|
||||
|
||||
|
@ -2068,4 +2075,5 @@
|
|||
;; Guides
|
||||
(d/export dwgu/update-guides)
|
||||
(d/export dwgu/remove-guide)
|
||||
(d/export dwgu/set-hover-guide)
|
||||
|
||||
|
|
|
@ -41,6 +41,12 @@
|
|||
(defn remove-guide [guide]
|
||||
(us/verify ::csp/guide guide)
|
||||
(ptk/reify ::remove-guide
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(let [sdisj (fnil disj #{})]
|
||||
(-> state
|
||||
(update-in [:workspace-guides :hover] sdisj (:id guide)))))
|
||||
|
||||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
(let [page (wsh/lookup-page state)
|
||||
|
@ -53,6 +59,16 @@
|
|||
(pcb/set-page-option :guides new-guides))]
|
||||
(rx/of (dwc/commit-changes changes))))))
|
||||
|
||||
(defn remove-guides
|
||||
[ids]
|
||||
(ptk/reify ::remove-guides
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(let [page (wsh/lookup-page state)
|
||||
guides (get-in page [:options :guides] {})
|
||||
guides (-> (select-keys guides ids) (vals))]
|
||||
(rx/from (->> guides (mapv #(remove-guide %))))))))
|
||||
|
||||
(defn move-frame-guides
|
||||
"Move guides that are inside a frame when that frame is moved"
|
||||
[ids]
|
||||
|
@ -86,3 +102,14 @@
|
|||
(filter (comp frame-ids? :frame-id))
|
||||
(map build-move-event)
|
||||
(rx/from))))))
|
||||
|
||||
(defn set-hover-guide
|
||||
[id hover?]
|
||||
(ptk/reify ::set-hover-guide
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(let [sconj (fnil conj #{})
|
||||
sdisj (fnil disj #{})]
|
||||
(if hover?
|
||||
(update-in state [:workspace-guides :hover] sconj id)
|
||||
(update-in state [:workspace-guides :hover] sdisj id))))))
|
||||
|
|
|
@ -190,7 +190,8 @@
|
|||
|
||||
:cut {:tooltip (ds/meta "X")
|
||||
:command (ds/c-mod "x")
|
||||
:fn #(st/emit! (dw/copy-selected) dw/delete-selected)}
|
||||
:fn #(st/emit! (dw/copy-selected)
|
||||
(dw/delete-selected))}
|
||||
|
||||
:paste {:tooltip (ds/meta "V")
|
||||
:disabled true
|
||||
|
@ -199,7 +200,7 @@
|
|||
|
||||
:delete {:tooltip (ds/supr)
|
||||
:command ["del" "backspace"]
|
||||
:fn #(st/emit! dw/delete-selected)}
|
||||
:fn #(st/emit! (dw/delete-selected))}
|
||||
|
||||
:bring-forward {:tooltip (ds/meta ds/up-arrow)
|
||||
:command (ds/c-mod "up")
|
||||
|
|
|
@ -103,7 +103,8 @@
|
|||
(mf/defc context-menu-edit
|
||||
[]
|
||||
(let [do-copy (st/emitf (dw/copy-selected))
|
||||
do-cut (st/emitf (dw/copy-selected) dw/delete-selected)
|
||||
do-cut (st/emitf (dw/copy-selected)
|
||||
(dw/delete-selected))
|
||||
do-paste (st/emitf dw/paste)
|
||||
do-duplicate (st/emitf (dw/duplicate-selected false))]
|
||||
[:*
|
||||
|
@ -406,7 +407,7 @@
|
|||
|
||||
(mf/defc context-menu-delete
|
||||
[]
|
||||
(let [do-delete (st/emitf dw/delete-selected)]
|
||||
(let [do-delete (st/emitf (dw/delete-selected))]
|
||||
[:& menu-entry {:title (tr "workspace.shape.menu.delete")
|
||||
:shortcut (sc/get-tooltip :delete)
|
||||
:on-click do-delete}]))
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
|
||||
(defn use-guide
|
||||
"Hooks to support drag/drop for existing guides and new guides"
|
||||
[on-guide-change get-hover-frame zoom {:keys [position axis frame-id]}]
|
||||
[on-guide-change get-hover-frame zoom {:keys [id position axis frame-id]}]
|
||||
(let [dragging-ref (mf/use-ref false)
|
||||
start-ref (mf/use-ref nil)
|
||||
start-pos-ref (mf/use-ref nil)
|
||||
|
@ -52,11 +52,13 @@
|
|||
on-pointer-enter
|
||||
(mf/use-callback
|
||||
(fn []
|
||||
(st/emit! (dw/set-hover-guide id true))
|
||||
(swap! state assoc :hover true)))
|
||||
|
||||
on-pointer-leave
|
||||
(mf/use-callback
|
||||
(fn []
|
||||
(st/emit! (dw/set-hover-guide id false))
|
||||
(swap! state assoc :hover false)))
|
||||
|
||||
on-pointer-down
|
||||
|
|
Loading…
Add table
Reference in a new issue