From 6693c8bc9bc46fca719ad47f545dc3eceb8b3283 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Sun, 10 Jan 2016 23:13:29 +0200 Subject: [PATCH] Implement backspace / supr shortcut for delete selected shapes. --- frontend/uxbox/data/workspace.cljs | 26 ++++++++++++++++++++++ frontend/uxbox/ui/workspace/shortcuts.cljs | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/frontend/uxbox/data/workspace.cljs b/frontend/uxbox/data/workspace.cljs index 39b823e01..f38f2a9d5 100644 --- a/frontend/uxbox/data/workspace.cljs +++ b/frontend/uxbox/data/workspace.cljs @@ -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] diff --git a/frontend/uxbox/ui/workspace/shortcuts.cljs b/frontend/uxbox/ui/workspace/shortcuts.cljs index 6390f35f5..5972d41ad 100644 --- a/frontend/uxbox/ui/workspace/shortcuts.cljs +++ b/frontend/uxbox/ui/workspace/shortcuts.cljs @@ -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