Browse Source

feat: wip, organize shortcut docs page

Weihua Lu 4 years ago
parent
commit
e0f32fe878

+ 1 - 1
src/main/frontend/components/onboarding.cljs

@@ -233,7 +233,7 @@
                 (t :help/working-with-lists)]]
           [:th (t :help/shortcut)]]]
         [:tbody
-         [:tr [:td (t :help/indent-block-tab)] [:td "Tab"]]
+         [:tr [:td (t :shortcut.editor/indent)] [:td "Tab"]]
          [:tr [:td (t :help/unindent-block)] [:td "Shift-Tab"]]
          [:tr [:td (t :help/move-block-up)] [:td (util/->platform-shortcut "Alt-Shift-Up")]]
          [:tr [:td (t :help/move-block-down)] [:td (util/->platform-shortcut "Alt-Shift-Down")]]

+ 89 - 0
src/main/frontend/components/shortcut.cljs

@@ -0,0 +1,89 @@
+(ns frontend.components.shortcut
+  (:require [rum.core :as rum]
+            [frontend.context.i18n :as i18n]
+            [frontend.util :as util]
+            [frontend.modules.shortcut.data-helper :as dh]))
+
+(rum/defc shortcut-table
+  [tag]
+  (rum/with-context [[t] i18n/*tongue-context*]
+    [:table
+     [:thead
+      [:tr
+       [:th [:b (t tag)]]
+       [:th (t :help/shortcut)]]]
+     [:tbody
+      (map (fn [[k {:keys [i18n binding]}]]
+             [:tr {:key k}
+              [:td (t i18n)]
+              [:td binding]])
+           (dh/binding-by-tag tag))]]))
+
+(rum/defc shortcut
+  []
+  (rum/with-context [[t] i18n/*tongue-context*]
+    [:div
+     [:h1.title (t :shortcut/page-title)]
+       [:table
+        [:thead
+         [:tr
+          [:th [:b (t :help/shortcuts-triggers)]]
+          [:th (t :help/shortcut)]]]
+        [:tbody
+         [:tr [:td (t :help/slash-autocomplete)] [:td "/"]]
+         [:tr [:td (t :help/block-content-autocomplete)] [:td "<"]]
+         [:tr [:td (t :help/reference-autocomplete)] [:td "[[]]"]]
+         [:tr [:td (t :help/block-reference)] [:td "(())"]]]]
+     (shortcut-table :shortcut.tag/basics)
+
+     #_
+     [:table
+      [:thead
+       [:tr
+        [:th [:b "Basics"]]
+        [:th (t :help/shortcut)]]]
+      [:tbody
+       [:tr [:td (t :shortcut.editor/indent)] [:td "Tab"]]
+       [:tr [:td (t :help/unindent-block)] [:td "Shift-Tab"]]
+       [:tr [:td (t :help/move-block-up)] [:td (util/->platform-shortcut "Alt-Shift-Up")]]
+       [:tr [:td (t :help/move-block-down)] [:td (util/->platform-shortcut "Alt-Shift-Down")]]
+       [:tr [:td (t :help/create-new-block)] [:td "Enter"]]
+       [:tr [:td (t :help/new-line-in-block)] [:td "Shift-Enter"]]
+       [:tr [:td (t :undo)] [:td (util/->platform-shortcut "Ctrl-z")]]
+       [:tr [:td (t :redo)] [:td (util/->platform-shortcut "Ctrl-y")]]
+       [:tr [:td (t :help/zoom-in)] [:td (util/->platform-shortcut (if util/mac? "Cmd-." "Alt-Right"))]]
+       [:tr [:td (t :help/zoom-out)] [:td (util/->platform-shortcut (if util/mac? "Cmd-," "Alt-left"))]]
+       [:tr [:td (t :help/follow-link-under-cursor)] [:td (util/->platform-shortcut "Ctrl-o")]]
+       [:tr [:td (t :help/open-link-in-sidebar)] [:td (util/->platform-shortcut "Ctrl-shift-o")]]
+       [:tr [:td (t :expand)] [:td (util/->platform-shortcut "Ctrl-Down")]]
+       [:tr [:td (t :collapse)] [:td (util/->platform-shortcut "Ctrl-Up")]]
+       [:tr [:td (t :select-block-above)] [:td "Shift-Up"]]
+       [:tr [:td (t :select-block-below)] [:td "Shift-Down"]]
+       [:tr [:td (t :select-all-blocks)] [:td (util/->platform-shortcut "Ctrl-Shift-a")]]]]
+       [:table
+        [:thead
+         [:tr
+          [:th [:b (t :general)]]
+          [:th (t :help/shortcut)]]]
+        [:tbody
+         [:tr [:td (t :help/toggle)] [:td "?"]]
+         [:tr [:td (t :help/git-commit-message)] [:td "c"]]
+         [:tr [:td (t :help/full-text-search)] [:td (util/->platform-shortcut "Ctrl-u")]]
+         [:tr [:td (t :help/page-search)] [:td (util/->platform-shortcut "Ctrl-Shift-u")]]
+         [:tr [:td (t :help/open-link-in-sidebar)] [:td "Shift-Click"]]
+         [:tr [:td (t :help/context-menu)] [:td "Right Click"]]
+         [:tr [:td (t :help/fold-unfold)] [:td "Tab"]]
+         [:tr [:td (t :help/toggle-contents)] [:td "t c"]]
+         [:tr [:td (t :help/toggle-doc-mode)] [:td "t d"]]
+         [:tr [:td (t :help/toggle-theme)] [:td "t t"]]
+         [:tr [:td (t :help/toggle-right-sidebar)] [:td "t r"]]
+         [:tr [:td (t :help/toggle-settings)] [:td "t s"]]
+         [:tr [:td (t :help/toggle-insert-new-block)] [:td "t e"]]
+         [:tr [:td (t :help/jump-to-journals)] [:td (if util/mac? "Cmd-j" "Alt-j")]]]]
+       (shortcut-table :shortcut.tag/formatting)
+
+     ]
+
+
+    )
+  )

+ 11 - 7
src/main/frontend/dicts.cljs

@@ -157,7 +157,7 @@ title: How to take dummy notes?
         :help/toggle-settings "Toggle settings"
         :help/toggle-insert-new-block "Toggle Enter/Alt+Enter for inserting new block"
         :help/jump-to-journals "Jump to Journals"
-        :formatting "Formatting"
+        :shortcut.tag/formatting "Formatting"
         :help/markdown-syntax "Markdown syntax"
         :help/org-mode-syntax "Org mode syntax"
         :bold "Bold"
@@ -350,7 +350,11 @@ title: How to take dummy notes?
         :open-a-directory "Open a local directory"
         :user/delete-account "Delete account"
         :user/delete-your-account "Delete your account"
-        :user/delete-account-notice "All your published pages on logseq.com will be deleted."}
+        :user/delete-account-notice "All your published pages on logseq.com will be deleted."
+
+        :shortcut/page-title "Learn & Customize Shortcuts"
+        :shortcut.tag/basics "Basics"
+        }
 
    :de {:help/about "Über Logseq"
         :help/bug "Fehlerbericht"
@@ -399,7 +403,7 @@ title: How to take dummy notes?
         :help/toggle-right-sidebar "Rechte Seitenleiste umschalten"
         :help/toggle-insert-new-block "Umschalten von Enter/Alt+Enter zum Einfügen eines neuen Blocks"
         :help/jump-to-journals "Zu Journalen springen"
-        :formatting "Formatierung"
+        :shortcut.tag/formatting "Formatierung"
         :help/markdown-syntax "Markdown-Syntax"
         :help/org-mode-syntax "Org-Mode-Syntax"
         :bold "Fett"
@@ -625,7 +629,7 @@ title: How to take dummy notes?
         :help/toggle-right-sidebar "Afficher/cacher la barre latérale"
         :help/toggle-insert-new-block "Activer Entreée ou Alt+Enter pour insérer un bloc"
         :help/jump-to-journals "Aller au Journal"
-        :formatting "Formats"
+        :shortcut.tag/formatting "Formats"
         :help/markdown-syntax "Syntaxe Markdown"
         :help/org-mode-syntax "Syntaxe Org mode"
         :bold "Gras"
@@ -888,7 +892,7 @@ title: How to take dummy notes?
            :help/toggle-settings "显示/关闭设置"
            :help/toggle-insert-new-block "切换 Enter/Alt+Enter 以插入新块"
            :help/jump-to-journals "跳转到日记"
-           :formatting "格式化"
+           :shortcut.tag/formatting "格式化"
            :help/markdown-syntax "Markdown 语法"
            :help/org-mode-syntax "Org Mode 语法"
            :bold "粗体"
@@ -1168,7 +1172,7 @@ title: How to take dummy notes?
              :help/toggle-right-sidebar "啟用/關閉右側欄"
              :help/toggle-insert-new-block "切換 Enter/Alt+Enter 以插入新塊"
              :help/jump-to-journals "跳轉到日記"
-             :formatting "格式化"
+             :shortcut.tag/formatting "格式化"
              :help/markdown-syntax "Markdown 語法"
              :help/org-mode-syntax "Org Mode 語法"
              :bold "粗體"
@@ -1421,7 +1425,7 @@ title: How to take dummy notes?
         :help/toggle-right-sidebar "Wissel regter sybalk"
         :help/toggle-insert-new-block "Wissel Enter/Alt+enter vir die byvoeging van nuwe blokke"
         :help/jump-to-journals "Spring na joernale"
-        :formatting "Formatering"
+        :shortcut.tag/formatting "Formatering"
         :help/markdown-syntax "Markdown sintaksis"
         :help/org-mode-syntax "Org mode sintaksis"
         :bold "Vetdruk"

+ 1 - 23
src/main/frontend/modules/shortcut/core.cljs

@@ -12,28 +12,6 @@
 
 (def *installed (atom {}))
 
-(defn- mod-key [shortcut]
-  (str/replace shortcut #"(?i)mod"
-               (if util/mac? "meta" "ctrl")))
-
-(defn shortcut-binding
-  [id]
-  (let [shortcut (or (state/get-shortcut id)
-                     (get (dh/binding-map) id))]
-    (cond
-      (nil? shortcut)
-      (log/error :shortcut/binding-not-found {:id id})
-
-      (false? shortcut)
-      (log/debug :shortcut/disabled {:id id})
-
-      :else
-      (->>
-       (if (string? shortcut)
-         [shortcut]
-         shortcut)
-       (mapv mod-key)))))
-
 (def global-keys #js
   [KeyCodes/TAB
    KeyCodes/ENTER
@@ -55,7 +33,7 @@
     ;; register shortcuts
     (doseq [[id _] shortcut-map]
       ;; (log/info :shortcut/install-shortcut {:id id :shortcut (shortcut-binding id)})
-      (doseq [k (shortcut-binding id)]
+      (doseq [k (dh/shortcut-binding id)]
         (.registerShortcut handler (util/keyname id) k)))
 
     (let [f (fn [e]

+ 12 - 0
src/main/frontend/modules/shortcut/data.cljs

@@ -52,9 +52,13 @@
      :fn      editor-handler/editor-delete}
     :editor/indent
     {:binding "tab"
+     :i18n    :help/indent-block-tab
+     :tags    #{:shortcut.tag/basics}
      :fn      (editor-handler/keydown-tab-handler :right)}
     :editor/outindent
     {:binding "shift+tab"
+     :i18n    :help/unindent-block
+     :tags    #{:shortcut.tag/basics}
      :fn      (editor-handler/keydown-tab-handler :left)}
     :editor/new-block
     {:binding "enter"
@@ -85,15 +89,23 @@
      :fn      editor-handler/open-link-in-sidebar!}
     :editor/bold
     {:binding "mod+b"
+     :i18n    :bold
+     :tags    #{:shortcut.tag/formatting}
      :fn      editor-handler/bold-format!}
     :editor/italics
     {:binding "mod+i"
+     :i18n    :italics
+     :tags    #{:shortcut.tag/formatting}
      :fn      editor-handler/italics-format!}
     :editor/highlight
     {:binding "mod+shift+h"
+     :i18n    :highlight
+     :tags    #{:shortcut.tag/formatting}
      :fn      editor-handler/highlight-format!}
     :editor/insert-link
     {:binding "mod+shift+k"
+     :tags    #{:shortcut.tag/formatting}
+     :i18n    :html-link
      :fn      editor-handler/html-link-format!}
     :editor/select-all-blocks
     {:binding "mod+shift+a"

+ 42 - 1
src/main/frontend/modules/shortcut/data_helper.cljs

@@ -1,5 +1,9 @@
 (ns frontend.modules.shortcut.data-helper
-  (:require [frontend.modules.shortcut.data :refer [data]]))
+  (:require [frontend.modules.shortcut.data :refer [data]]
+            [lambdaisland.glogi :as log]
+            [frontend.util :as util]
+            [clojure.string :as str]
+            [frontend.state :as state]))
 
 (defn binding-map []
   (->> (vals data)
@@ -8,6 +12,43 @@
               {k binding}))
        (into {})))
 
+(defn- mod-key [shortcut]
+  (str/replace shortcut #"(?i)mod"
+               (if util/mac? "meta" "ctrl")))
+
+(defn shortcut-binding
+  [id]
+  (let [shortcut (or (state/get-shortcut id)
+                     (get (binding-map) id))]
+    (cond
+      (nil? shortcut)
+      (log/error :shortcut/binding-not-found {:id id})
+
+      (false? shortcut)
+      (log/debug :shortcut/disabled {:id id})
+
+      :else
+      (->>
+       (if (string? shortcut)
+         [shortcut]
+         shortcut)
+       (mapv mod-key)))))
+
+(defn binding-by-tag
+  [tag]
+  (->> (vals data)
+       (apply merge)
+       (map (fn [[k {:keys [tags] :as v}]]
+              (when (and tags (tags tag))
+                {k (assoc v :binding (shortcut-binding k))})))
+       (into {})))
+
+
+(defn decorate-namespace [k]
+  (let [n (name k)
+        ns (namespace k)]
+    (keyword (str "shortcut." ns) n)))
+
 (defn shortcut-map
   ([handler-id]
    (shortcut-map handler-id nil))

+ 7 - 2
src/main/frontend/routes.cljs

@@ -7,7 +7,8 @@
             [frontend.components.journal :as journal]
             [frontend.components.search :as search]
             [frontend.components.settings :as settings]
-            [frontend.components.external :as external]))
+            [frontend.components.external :as external]
+            [frontend.components.shortcut :as shortcut]))
 
 ;; http://localhost:3000/#?anchor=fn.1
 (def routes
@@ -65,4 +66,8 @@
 
    ["/all-journals"
     {:name :all-journals
-     :view journal/all-journals}]])
+     :view journal/all-journals}]
+
+   ["/helper/shortcut"
+    {:name :shortcut
+     :view shortcut/shortcut}]])