0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-07 15:39:42 -05:00

Implement backspace / supr shortcut for delete selected shapes.

This commit is contained in:
Andrey Antukh 2016-01-10 23:13:29 +02:00
parent 34abb7eb27
commit 6693c8bc9b
2 changed files with 27 additions and 1 deletions

View file

@ -1,5 +1,6 @@
(ns uxbox.data.workspace
(:require [bouncer.validators :as v]
[beicon.core :as rx]
[uxbox.rstore :as rs]
[uxbox.router :as r]
[uxbox.state :as st]
@ -140,6 +141,31 @@
(update-in $ [:pages-by-id pid :shapes] conj sid)
(assoc-in $ [:shapes-by-id sid] shape))))))
(defn delete-shape
"Remove the shape using its id."
[sid]
(reify
rs/UpdateEvent
(-apply-update [_ state]
(let [pageid (get-in state [:shapes-by-id sid :page])
shapes (as-> state $
(get-in $ [:pages-by-id pageid :shapes])
(remove #(= % sid) $)
(into [] $))]
(as-> state $
(assoc-in $ [:pages-by-id pageid :shapes] shapes)
(update-in $ [:shapes-by-id] dissoc sid))))))
(defn remove-selected
"Deselect all and remove all selected shapes."
[]
(reify
rs/WatchEvent
(-apply-watch [_ state]
(let [selected (get-in state [:workspace :selected])]
(rx/from-coll
(into [(deselect-all)] (mapv #(delete-shape %) selected)))))))
(defn initialize
"Initialize the workspace state."
[projectid pageid]

View file

@ -19,7 +19,7 @@
:ctrl+shift+i #(rs/emit! (dw/toggle-toolbox :icons))
:ctrl+shift+l #(rs/emit! (dw/toggle-toolbox :layers))
:esc (constantly nil)
:backspace (constantly nil)})
:backspace #(rs/emit! (dw/remove-selected))})
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Keyboard Shortcuts Watcher