Ver Fonte

Cleanup keyboard-shortcut UI code

Devon Zuegel há 4 anos atrás
pai
commit
d56ed867bb

+ 13 - 7
src/main/frontend/components/shortcut.cljs

@@ -18,13 +18,19 @@
      [:div
       [:p.mb-4 "Press any sequence of keys to set the shortcut for the " [:b action-name] " action."]
       [:p.mb-4.mt-4
-       (map-indexed (fn [i key]
-                      [:span.keyboard-shortcut {:key i}
-                       [:code {:style {:font-size "1.5em" :margin-right "8px"}}
-                        (clojure.string/replace key "meta" "cmd")]])
-                    (-> keyboard-shortcut
-                        (clojure.string/trim)
-                        (clojure.string/split  #" |\+")))]]
+       (ui/keyboard-shortcut (-> keyboard-shortcut
+                                 (clojure.string/trim)
+                                 (clojure.string/split  #" |\+")))
+       #_(map-indexed (fn [i key]
+                        [:span.keyboard-shortcut {:key i}
+                         [:code {:style {:font-size "1.5em" :margin-right "8px"}}
+                        ;; When displaying to the user, use "cmd" rather than
+                        ;; "meta" to describe the Mac mod key, because that's 
+                        ;; what the Mac keyboards actually say.
+                          (clojure.string/replace key "meta" "cmd")]])
+                      (-> keyboard-shortcut
+                          (clojure.string/trim)
+                          (clojure.string/split  #" |\+")))]]
      [:div.cancel-save-buttons.text-right.mt-4
       (ui/button "Save" :on-click state/close-modal!)
       [:a.ml-4

+ 8 - 10
src/main/frontend/modules/shortcut/data_helper.cljs

@@ -97,16 +97,11 @@
   (let [tmp (cond
               (false? binding)
               (cond
-                (and util/mac? (= k :editor/kill-line-after))
-                "disabled (system default: ctrl+k)"
-                (and util/mac? (= k :editor/beginning-of-block))
-                "disabled (system default: ctrl+a)"
-                (and util/mac? (= k :editor/end-of-block))
-                "disabled (system default: ctrl+e)"
-                (and util/mac? (= k :editor/backward-kill-word))
-                "disabled (system default: opt+delete)"
-                :else
-                "disabled")
+                (and util/mac? (= k :editor/kill-line-after))    "disabled (system default: ctrl+k)"
+                (and util/mac? (= k :editor/beginning-of-block)) "disabled (system default: ctrl+a)"
+                (and util/mac? (= k :editor/end-of-block))       "disabled (system default: ctrl+e)"
+                (and util/mac? (= k :editor/backward-kill-word)) "disabled (system default: opt+delete)"
+                :else "disabled")
 
               (string? binding)
               (decorate-binding binding)
@@ -115,6 +110,9 @@
               (->> binding
                    (map decorate-binding)
                    (str/join " | ")))]
+
+    ;; Display "cmd" rather than "meta" to the user to describe the Mac
+    ;; mod key, because that's what the Mac keyboards actually say.
     (clojure.string/replace tmp "meta" "cmd")))
 
 

+ 6 - 3
src/main/frontend/ui.cljs

@@ -385,11 +385,14 @@
       {:class       (if on? (if small? "translate-x-4" "translate-x-5") "translate-x-0")
        :aria-hidden "true"}]]]))
 
+;; `sequence` can be a list of symbols or strings
 (defn keyboard-shortcut [sequence]
   [:div.keyboard-shortcut
-   (map (fn [key]
-          [:code
-           (if (= :meta key)
+   (map-indexed (fn [i key]
+          [:code {:key i}
+           ;; Display "cmd" rather than "meta" to the user to describe the Mac
+           ;; mod key, because that's what the Mac keyboards actually say.
+           (if (or (= :meta key) (= "meta" key))
              (util/meta-key-name)
              (name key))])
         sequence)]