From 6ecec4af0a56f6e022a3dc2831629af271198c48 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Sun, 10 Jan 2016 23:50:21 +0200 Subject: [PATCH] Enable precise moviments using keyboard up/down/right/left keys. --- frontend/uxbox/data/workspace.cljs | 16 ++++++++++++++++ frontend/uxbox/ui/workspace/shortcuts.cljs | 6 +++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/frontend/uxbox/data/workspace.cljs b/frontend/uxbox/data/workspace.cljs index 1652658b9d..05ece16eb5 100644 --- a/frontend/uxbox/data/workspace.cljs +++ b/frontend/uxbox/data/workspace.cljs @@ -188,6 +188,22 @@ (let [shape (get-in state [:shapes-by-id sid])] (update-in state [:shapes-by-id sid] shapes/-move {:dx dx :dy dy}))))) +(defn move-selected + "Move a minimal position unit the selected shapes." + [dir] + {:pre [(contains? #{:up :down :right :left} dir)]} + (reify + rs/WatchEvent + (-apply-watch [_ state] + (let [selected (get-in state [:workspace :selected]) + delta (case dir + :up [0 -1] + :down [0 +1] + :right [+1 0] + :left [-1 0])] + (rx/from-coll + (map #(move-shape % delta) selected)))))) + (defn update-shape-rotation [sid rotation] {:pre [(number? rotation) diff --git a/frontend/uxbox/ui/workspace/shortcuts.cljs b/frontend/uxbox/ui/workspace/shortcuts.cljs index efb99ba98e..3ccd360964 100644 --- a/frontend/uxbox/ui/workspace/shortcuts.cljs +++ b/frontend/uxbox/ui/workspace/shortcuts.cljs @@ -19,7 +19,11 @@ :ctrl+shift+i #(rs/emit! (dw/toggle-toolbox :icons)) :ctrl+shift+l #(rs/emit! (dw/toggle-toolbox :layers)) :esc #(rs/emit! (dw/deselect-all)) - :backspace #(rs/emit! (dw/remove-selected))}) + :backspace #(rs/emit! (dw/remove-selected)) + :up #(rs/emit! (dw/move-selected :up)) + :down #(rs/emit! (dw/move-selected :down)) + :right #(rs/emit! (dw/move-selected :right)) + :left #(rs/emit! (dw/move-selected :left))}) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Keyboard Shortcuts Watcher