Browse Source

feat: allow to overwrite the shortcuts

We only enabled both :editor/zoom-in and :editor/zoom-out for now.
Tienson Qin 5 years ago
parent
commit
d3e2788d3a
2 changed files with 19 additions and 9 deletions
  1. 3 3
      src/main/frontend/keyboards.cljs
  2. 16 6
      src/main/frontend/state.cljs

+ 3 - 3
src/main/frontend/keyboards.cljs

@@ -49,7 +49,7 @@
 ;; Markdown
 ;; Block
 
-(defonce keyboards
+(def keyboards
   (->>
    {"tab" (editor-handler/on-tab :right)
     "shift+tab" (editor-handler/on-tab :left)
@@ -57,8 +57,8 @@
     "ctrl+y" history-handler/redo!
     "ctrl+u" route-handler/go-to-search!
     "alt+j" route-handler/go-to-journals!
-    "alt+right" editor-handler/zoom-in!
-    "alt+left" editor-handler/zoom-out!
+    (or (state/get-shortcut :editor/zoom-in) "alt+right") editor-handler/zoom-in!
+    (or (state/get-shortcut :editor/zoom-out) "alt+left") editor-handler/zoom-out!
     "ctrl+enter" editor-handler/cycle-todo!
     "ctrl+down" editor-handler/expand!
     "ctrl+up" editor-handler/collapse!

+ 16 - 6
src/main/frontend/state.cljs

@@ -687,8 +687,12 @@
   (swap! state assoc-in [:git/status repo-url] value))
 
 (defn get-shortcut
-  [repo key]
-  (get-in @state [:config repo :shortcuts key]))
+  ([key]
+   (get-shortcut (get-current-repo) key))
+  ([repo key]
+   (or
+    (get (storage/get (str repo "-shortcuts")) key)
+    (get-in @state [:config repo :shortcuts key]))))
 
 (defn get-me
   []
@@ -823,10 +827,16 @@
 
 (defn set-config!
   [repo-url value]
-  (set-state! [:config repo-url] value)
-  (set-new-block-shortcut!
-   (or (get-shortcut repo-url :editor/new-block)
-       "enter")))
+  (let [old-shortcuts (get-in @state [:config repo-url :shortcuts])]
+    (set-state! [:config repo-url] value)
+
+    ;; TODO: refactor
+    (set-new-block-shortcut!
+     (or (get-shortcut repo-url :editor/new-block)
+         "enter"))
+
+    (let [shortcuts (or (:shortcuts value) {})]
+      (storage/set (str repo-url "-shortcuts") shortcuts))))
 
 (defn git-auto-push?
   []