Răsfoiți Sursa

enhance(ux): persist custom shortcuts for web platform

charlie 10 luni în urmă
părinte
comite
31e022f6e0

+ 13 - 10
src/main/frontend/modules/shortcut/core.cljs

@@ -9,6 +9,7 @@
             [frontend.modules.shortcut.utils :as shortcut-utils]
             [frontend.state :as state]
             [frontend.util :as util]
+            [frontend.storage :as storage]
             [goog.events :as events]
             [goog.ui.KeyboardShortcutHandler.EventType :as EventType]
             [lambdaisland.glogi :as log])
@@ -274,20 +275,22 @@
 
 (defn persist-user-shortcut!
   [id binding]
-  (let [graph-shortcuts (or (:shortcuts (state/get-graph-config)) {})
-        global-shortcuts (or (:shortcuts (state/get-global-config)) {})
-        global? true]
+  (let [global? true]
     (letfn [(into-shortcuts [shortcuts]
-              (cond-> shortcuts
+              (cond-> (or shortcuts {})
                 (nil? binding)
                 (dissoc id)
 
                 (and global?
-                     (or (string? binding)
-                         (vector? binding)
-                         (boolean? binding)))
+                  (or (string? binding)
+                    (vector? binding)
+                    (boolean? binding)))
                 (assoc id binding)))]
       ;; TODO: exclude current graph config shortcuts
-      (config-handler/set-config! :shortcuts (into-shortcuts graph-shortcuts))
-      (when (util/electron?)
-        (global-config-handler/set-global-config-kv! :shortcuts (into-shortcuts global-shortcuts))))))
+      (config-handler/set-config!
+        :shortcuts (into-shortcuts (:shortcuts (state/get-graph-config))))
+      (if (util/electron?)
+        (global-config-handler/set-global-config-kv!
+          :shortcuts (into-shortcuts (:shortcuts (state/get-global-config))))
+        ;; web browser platform
+        (storage/set :ls-shortcuts (into-shortcuts (storage/get :ls-shortcuts)))))))

+ 3 - 3
src/main/frontend/modules/shortcut/data_helper.cljs

@@ -50,15 +50,15 @@
 
 (defn get-bindings
   []
-  (m-flatten-bindings-by-id @shortcut-config/*config (state/shortcuts) true))
+  (m-flatten-bindings-by-id @shortcut-config/*config (state/custom-shortcuts) true))
 
 (defn get-bindings-keys-map
   []
-  (m-flatten-bindings-by-key @shortcut-config/*config (state/shortcuts)))
+  (m-flatten-bindings-by-key @shortcut-config/*config (state/custom-shortcuts)))
 
 (defn get-bindings-ids-map
   []
-  (m-flatten-bindings-by-id @shortcut-config/*config (state/shortcuts) false))
+  (m-flatten-bindings-by-id @shortcut-config/*config (state/custom-shortcuts) false))
 
 (defn get-shortcut-desc
   [binding-map]

+ 3 - 2
src/main/frontend/state.cljs

@@ -604,8 +604,9 @@ should be done through this fn in order to get global config and config defaults
              "MMM do, yyyy"))
       (common-config/get-date-formatter (get-config)))))
 
-(defn shortcuts []
-  (:shortcuts (get-config)))
+(defn custom-shortcuts []
+  (merge (storage/get :ls-shortcuts)
+    (:shortcuts (get-config))))
 
 (defn get-commands
   []

+ 1 - 1
src/main/frontend/ui.cljs

@@ -580,7 +580,7 @@
 
 (defn keyboard-shortcut-from-config [shortcut-name & {:keys [pick-first?]}]
   (let [built-in-binding (:binding (get shortcut-config/all-built-in-keyboard-shortcuts shortcut-name))
-        custom-binding  (when (state/shortcuts) (get (state/shortcuts) shortcut-name))
+        custom-binding  (when (state/custom-shortcuts) (get (state/custom-shortcuts) shortcut-name))
         binding         (or custom-binding built-in-binding)]
     (if (and pick-first? (coll? binding))
       (first binding)