Explorar el Código

feat: add shortcut t c to toggle Contents

Tienson Qin hace 4 años
padre
commit
84190df469

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

@@ -258,6 +258,7 @@
          [: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"]]

+ 7 - 5
src/main/frontend/components/sidebar.cljs

@@ -278,11 +278,13 @@
                (state/sidebar-add-block! (state/get-current-repo) "help" :help nil)))
        ;; c
        67 (fn [state e]
-            (when (and (not (util/input? (gobj/get e "target")))
-                       (not (gobj/get e "shiftKey"))
-                       (not (gobj/get e "ctrlKey"))
-                       (not (gobj/get e "altKey"))
-                       (not (gobj/get e "metaKey")))
+            (when (and
+                   (string/starts-with? (state/get-current-repo) "https://")
+                   (not (util/input? (gobj/get e "target")))
+                   (not (gobj/get e "shiftKey"))
+                   (not (gobj/get e "ctrlKey"))
+                   (not (gobj/get e "altKey"))
+                   (not (gobj/get e "metaKey")))
               (when-let [repo-url (state/get-current-repo)]
                 (when-not (state/get-edit-input-id)
                   (util/stop e)

+ 4 - 2
src/main/frontend/dicts.cljs

@@ -141,8 +141,8 @@ title: How to take dummy notes?
         :help/select-nfs-browser "Please use another browser (like latest chrome) which support NFS features to open local directory."
         :undo "Undo"
         :redo "Redo"
-        :help/zoom-in "Zoom In"
-        :help/zoom-out "Zoom out"
+        :help/zoom-in "Zoom In/Forward"
+        :help/zoom-out "Zoom out/Back"
         :help/follow-link-under-cursor "Follow link under cursor"
         :help/open-link-in-sidebar "Open link in Sidebar"
         :expand "Expand"
@@ -157,6 +157,7 @@ title: How to take dummy notes?
         :help/context-menu "Context Menu"
         :help/fold-unfold "Fold/Unfold blocks (when not in edit mode)"
         :help/toggle-doc-mode "Toggle document mode"
+        :help/toggle-contents "Toggle Contents"
         :help/toggle-theme "Toggle between dark/light theme"
         :help/toggle-right-sidebar "Toggle right sidebar"
         :help/toggle-insert-new-block "Toggle Enter/Alt+Enter for inserting new block"
@@ -881,6 +882,7 @@ title: How to take dummy notes?
            :help/context-menu "右键菜单"
            :help/fold-unfold "折叠/展开方块(不在编辑模式中)"
            :help/toggle-doc-mode "切换文档模式"
+           :help/toggle-contents "打开/关闭目录"
            :help/toggle-theme "“在暗色/亮色主题之间切换”"
            :help/toggle-right-sidebar "启用/关闭右侧栏"
            :help/toggle-insert-new-block "切换 Enter/Alt+Enter 以插入新块"

+ 7 - 0
src/main/frontend/handler/ui.cljs

@@ -25,6 +25,13 @@
   []
   (state/toggle-sidebar-open?!))
 
+(defn toggle-contents!
+  []
+  (when-let [current-repo (state/get-current-repo)]
+    (let [id "contents"]
+      (if (state/sidebar-block-exists? id)
+        (state/sidebar-remove-block! id)
+        (state/sidebar-add-block! current-repo id :contents nil)))))
 
 ;; FIXME: re-render all embedded blocks since they will not be re-rendered automatically
 

+ 2 - 0
src/main/frontend/keyboards.cljs

@@ -45,6 +45,8 @@
    (enable-when-not-editing-mode! ui-handler/toggle-right-sidebar!)
    (or (shortcut :ui/toggle-new-block) "t e")
    (enable-when-not-editing-mode! state/toggle-new-block-shortcut!)
+   (or (shortcut :ui/show-contents) "t c")
+   [(enable-when-not-editing-mode! ui-handler/toggle-contents!) true]
    (or (shortcut :ui/toggle-between-page-and-file) "s")
    (enable-when-not-editing-mode! route-handler/toggle-between-page-and-file!)
    "tab" (-> (editor-handler/on-tab :right)

+ 8 - 1
src/main/frontend/state.cljs

@@ -646,10 +646,17 @@
 
 (defn sidebar-remove-block!
   [idx]
-  (update-state! :sidebar/blocks #(util/drop-nth idx %))
+  (update-state! :sidebar/blocks (fn [blocks]
+                                   (if (= (str idx) "contents")
+                                     (remove #(= (second %) "contents") blocks)
+                                     (util/drop-nth idx blocks))))
   (when (empty? (:sidebar/blocks @state))
     (hide-right-sidebar!)))
 
+(defn sidebar-block-exists?
+  [idx]
+  (some #(= (second %) idx) (:sidebar/blocks @state)))
+
 (defn get-sidebar-blocks
   []
   (:sidebar/blocks @state))