|
@@ -5,12 +5,14 @@
|
|
|
[frontend.modules.shortcut.data-helper :as dh]
|
|
|
[frontend.state :as state]
|
|
|
[frontend.ui :as ui]
|
|
|
+ [frontend.extensions.latex :as latex]
|
|
|
+ [frontend.extensions.highlight :as highlight]
|
|
|
[rum.core :as rum]))
|
|
|
|
|
|
(rum/defcs customize-shortcut-dialog-inner <
|
|
|
(rum/local "")
|
|
|
(shortcut/record!)
|
|
|
- [state _ action-name current-binding]
|
|
|
+ [state k action-name current-binding]
|
|
|
(let [keypress (:rum/local state)
|
|
|
keyboard-shortcut (if (= "" @keypress) current-binding @keypress)]
|
|
|
[:div
|
|
@@ -19,12 +21,22 @@
|
|
|
[:p.mb-4.mt-4
|
|
|
(ui/keyboard-shortcut (-> keyboard-shortcut
|
|
|
(str/trim)
|
|
|
- (str/split #" |\+")))]]
|
|
|
+ (str/lower-case)
|
|
|
+ (str/split #" |\+")))
|
|
|
+ " "
|
|
|
+ [:a.text-sm
|
|
|
+ {:style {:margin-left "12px"}
|
|
|
+ :on-click (fn []
|
|
|
+ (dh/remove-shortcut k)
|
|
|
+ (shortcut/refresh!)
|
|
|
+ (swap! keypress (fn [] "")) ;; Clear local state
|
|
|
+ )}
|
|
|
+ "Reset"]]]
|
|
|
[:div.cancel-save-buttons.text-right.mt-4
|
|
|
(ui/button "Save" :on-click state/close-modal!)
|
|
|
[:a.ml-4
|
|
|
{:on-click (fn []
|
|
|
- (reset! keypress current-binding)
|
|
|
+ (reset! keypress (dh/binding-for-storage current-binding))
|
|
|
(state/close-modal!))} "Cancel"]]]))
|
|
|
|
|
|
(defn customize-shortcut-dialog [k action-name displayed-binding]
|
|
@@ -33,22 +45,21 @@
|
|
|
|
|
|
(rum/defc shortcut-col [k binding configurable? action-name]
|
|
|
(let [conflict? (dh/potential-confilct? k)
|
|
|
- displayed-binding (dh/binding-for-display k binding)]
|
|
|
+ displayed-binding (dh/binding-for-display k binding)
|
|
|
+ disabled? (clojure.string/includes? displayed-binding "system default")]
|
|
|
(if (not configurable?)
|
|
|
[:td.text-right displayed-binding]
|
|
|
[:td.text-right
|
|
|
(ui/button
|
|
|
displayed-binding
|
|
|
:class "text-sm p-1"
|
|
|
+ :style {:cursor (if disabled? "not-allowed" "pointer")}
|
|
|
:title (if conflict?
|
|
|
"Shortcut conflict!"
|
|
|
- "Click to modify")
|
|
|
- :background (when conflict? "pink")
|
|
|
- :on-click #(state/set-modal! (customize-shortcut-dialog k action-name displayed-binding)))
|
|
|
- [:a.text-sm
|
|
|
- {:style {:margin-left "12px"}
|
|
|
- :on-click (fn [] (dh/remove-shortcut k) (shortcut/refresh!))}
|
|
|
- "Reset"]])))
|
|
|
+ (if disabled? "Cannot override system default" "Click to modify"))
|
|
|
+ :background (if conflict? "pink" (when disabled? "gray"))
|
|
|
+ :on-click (if-not disabled?
|
|
|
+ #(state/set-modal! (customize-shortcut-dialog k action-name displayed-binding))))])))
|
|
|
|
|
|
(rum/defc shortcut-table < rum/reactive
|
|
|
([name]
|
|
@@ -94,16 +105,76 @@
|
|
|
[:td.text-right [:code "(())"]]]
|
|
|
[:tr
|
|
|
[:td.text-left (t :command.editor/open-link-in-sidebar)]
|
|
|
- [:td.text-right "shift-click"]]
|
|
|
+ [:td.text-right (ui/keyboard-shortcut ["shift" "click"])]]
|
|
|
[:tr
|
|
|
[:td.text-left (t :help/context-menu)]
|
|
|
- [:td.text-right "right click"]]]]))
|
|
|
+ [:td.text-right (ui/keyboard-shortcut ["right click"])]]]]))
|
|
|
+
|
|
|
+(defn markdown-and-orgmode-syntax []
|
|
|
+ (rum/with-context [[t] i18n/*tongue-context*]
|
|
|
+ (let [list [:bold :italics :del :mark :latex :code :link :pre :img]
|
|
|
+
|
|
|
+ preferred-format (state/get-preferred-format) ; markdown/org
|
|
|
+
|
|
|
+ title (case preferred-format
|
|
|
+ :markdown (t :help/markdown-syntax)
|
|
|
+ :org (t :help/org-mode-syntax))
|
|
|
+
|
|
|
+ learn-more (case preferred-format
|
|
|
+ :markdown "https://www.markdownguide.org/basic-syntax"
|
|
|
+ :org "https://orgmode.org/worg/dev/org-syntax.html")
|
|
|
+
|
|
|
+ raw (case preferred-format
|
|
|
+ :markdown {:bold (str "**" (t :bold) "**")
|
|
|
+ :italics (str "_" (t :italics) "_")
|
|
|
+ :link "[Link](https://www.example.com)"
|
|
|
+ :del (str "~~" (t :strikethrough) "~~")
|
|
|
+ :mark (str "^^" (t :highlight) "^^")
|
|
|
+ :latex "$$E = mc^2$$"
|
|
|
+ :code (str "`" (t :code) "`")
|
|
|
+ :pre "```clojure\n (println \"Hello world!\")\n```"
|
|
|
+ :img ""}
|
|
|
+ :org {:bold (str "*" (t :bold) "*")
|
|
|
+ :italic (str "/" (t :italics) "/")
|
|
|
+ :del (str "+" (t :strikethrough) "+")
|
|
|
+ :pre [:pre "#+BEGIN_SRC clojure\n (println \"Hello world!\")\n#+END_SRC"]
|
|
|
+ :link "[[https://www.example.com][Link]]"
|
|
|
+ :mark (str "^^" (t :highlight) "^^")
|
|
|
+ :latex "$$E = mc^2$$"
|
|
|
+ :code "~Code~"
|
|
|
+ :img "[[https://asset.logseq.com/static/img/logo.png][image]]"})
|
|
|
+
|
|
|
+ rendered {:italics [:i (t :italics)]
|
|
|
+ :bold [:b (t :bold)]
|
|
|
+ :link [:a {:href "https://www.example.com"} "Link"]
|
|
|
+ :del [:del (t :strikethrough)]
|
|
|
+ :mark [:mark (t :highlight)]
|
|
|
+ :latex (latex/latex "help-latex" "E = mc^2" true false)
|
|
|
+ :code [:code (t :code)]
|
|
|
+ :pre (highlight/highlight "help-highlight" {:data-lang "clojure"} "(println \"Hello world!\")")
|
|
|
+ :img [:img {:style {:float "right" :width 32 :height 32}
|
|
|
+ :src "https://asset.logseq.com/static/img/logo.png"
|
|
|
+ :alt "image"}]}]
|
|
|
+
|
|
|
+ [:table
|
|
|
+ [:thead
|
|
|
+ [:tr
|
|
|
+ [:th.text-left [:b title]]
|
|
|
+ [:th.text-right [:a {:href learn-more} "Learn more →"]]]]
|
|
|
+ [:tbody
|
|
|
+ (map (fn [name]
|
|
|
+ [:tr
|
|
|
+ [:td.text-left [(if (= :pre name) :pre :code) (get raw name)]]
|
|
|
+ [:td.text-right (get rendered name)]])
|
|
|
+ list)]])))
|
|
|
|
|
|
(rum/defc shortcut
|
|
|
[]
|
|
|
(rum/with-context [[t] i18n/*tongue-context*]
|
|
|
[:div
|
|
|
[:h1.title (t :help/shortcut-page-title)]
|
|
|
+ (trigger-table)
|
|
|
+ (markdown-and-orgmode-syntax)
|
|
|
(shortcut-table :shortcut.category/basics true)
|
|
|
(shortcut-table :shortcut.category/navigating true)
|
|
|
(shortcut-table :shortcut.category/block-editing true)
|