config.cljs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  1. (ns frontend.modules.shortcut.config
  2. (:require [frontend.components.commit :as commit]
  3. [frontend.extensions.srs.handler :as srs]
  4. [frontend.extensions.pdf.utils :as pdf-utils]
  5. [frontend.handler.config :as config-handler]
  6. [frontend.handler.editor :as editor-handler]
  7. [frontend.handler.paste :as paste-handler]
  8. [frontend.handler.history :as history]
  9. [frontend.handler.page :as page-handler]
  10. [frontend.handler.route :as route-handler]
  11. [frontend.handler.journal :as journal-handler]
  12. [frontend.handler.search :as search-handler]
  13. [frontend.handler.ui :as ui-handler]
  14. [frontend.handler.plugin :as plugin-handler]
  15. [frontend.handler.export :as export-handler]
  16. [frontend.handler.whiteboard :as whiteboard-handler]
  17. [frontend.handler.plugin-config :as plugin-config-handler]
  18. [frontend.modules.editor.undo-redo :as undo-redo]
  19. [frontend.modules.shortcut.dicts :as dicts]
  20. [frontend.modules.shortcut.before :as m]
  21. [frontend.state :as state]
  22. [frontend.util :refer [mac?] :as util]
  23. [frontend.commands :as commands]
  24. [frontend.config :as config]
  25. [electron.ipc :as ipc]
  26. [promesa.core :as p]
  27. [clojure.data :as data]
  28. [medley.core :as medley]))
  29. ;; TODO: Namespace all-default-keyboard-shortcuts keys with `:command` e.g.
  30. ;; `:command.date-picker/complete`. They are namespaced in translation but
  31. ;; almost everywhere else they are not which could cause needless conflicts
  32. ;; with other config keys
  33. ;; To add a new entry to this map, first add it here and then a description for
  34. ;; it in frontend.modules.shortcut.dicts/all-default-keyboard-shortcuts.
  35. ;; A shortcut is a map with the following keys:
  36. ;; * :binding - A string representing a keybinding. Avoid using single letter
  37. ;; shortcuts to allow chords that start with those characters
  38. ;; * :fn - Fn or a qualified keyword that represents a fn
  39. ;; * :inactive - Optional boolean to disable a shortcut for certain conditions
  40. ;; e.g. a given platform or feature condition
  41. (def ^:large-vars/data-var all-default-keyboard-shortcuts
  42. ;; BUG: Actually, "enter" is registered by mixin behind a "when inputing" guard
  43. ;; So this setting item does not cover all cases.
  44. ;; See-also: frontend.components.datetime/time-repeater
  45. {:date-picker/complete {:binding "enter"
  46. :fn ui-handler/shortcut-complete}
  47. :date-picker/prev-day {:binding "left"
  48. :fn ui-handler/shortcut-prev-day}
  49. :date-picker/next-day {:binding "right"
  50. :fn ui-handler/shortcut-next-day}
  51. :date-picker/prev-week {:binding ["up" "ctrl+p"]
  52. :fn ui-handler/shortcut-prev-week}
  53. :date-picker/next-week {:binding ["down" "ctrl+n"]
  54. :fn ui-handler/shortcut-next-week}
  55. :pdf/previous-page {:binding "alt+p"
  56. :fn pdf-utils/prev-page}
  57. :pdf/next-page {:binding "alt+n"
  58. :fn pdf-utils/next-page}
  59. :pdf/close {:binding "alt+x"
  60. :fn #(state/set-state! :pdf/current nil)}
  61. :pdf/find {:binding "alt+f"
  62. :fn pdf-utils/open-finder}
  63. :whiteboard/lock {:binding "mod+l"
  64. :fn #(.setLocked (state/active-tldraw-app) true)}
  65. :whiteboard/unlock {:binding "mod+shift+l"
  66. :fn #(.setLocked (state/active-tldraw-app) false)}
  67. :whiteboard/group {:binding "mod+g"
  68. :fn #(.doGroup (.-api ^js (state/active-tldraw-app)))}
  69. :whiteboard/ungroup {:binding "mod+shift+g"
  70. :fn #(.unGroup (.-api ^js (state/active-tldraw-app)))}
  71. :whiteboard/toggle-grid {:binding "mod+shift+g"
  72. :fn #(.toggleGrid (.-api ^js (state/active-tldraw-app)))}
  73. :auto-complete/complete {:binding "enter"
  74. :fn ui-handler/auto-complete-complete}
  75. :auto-complete/prev {:binding ["up" "ctrl+p"]
  76. :fn ui-handler/auto-complete-prev}
  77. :auto-complete/next {:binding ["down" "ctrl+n"]
  78. :fn ui-handler/auto-complete-next}
  79. :auto-complete/shift-complete {:binding "shift+enter"
  80. :fn ui-handler/auto-complete-shift-complete}
  81. :auto-complete/open-link {:binding "mod+o"
  82. :fn ui-handler/auto-complete-open-link}
  83. :cards/toggle-answers {:binding "s"
  84. :fn srs/toggle-answers}
  85. :cards/next-card {:binding "n"
  86. :fn srs/next-card}
  87. :cards/forgotten {:binding "f"
  88. :fn srs/forgotten}
  89. :cards/remembered {:binding "r"
  90. :fn srs/remembered}
  91. :cards/recall {:binding "t"
  92. :fn srs/recall}
  93. :editor/escape-editing {:binding false
  94. :fn (fn [_ _]
  95. (editor-handler/escape-editing))}
  96. :editor/backspace {:binding "backspace"
  97. :fn editor-handler/editor-backspace}
  98. :editor/delete {:binding "delete"
  99. :fn editor-handler/editor-delete}
  100. :editor/new-block {:binding "enter"
  101. :fn editor-handler/keydown-new-block-handler}
  102. :editor/new-line {:binding "shift+enter"
  103. :fn editor-handler/keydown-new-line-handler}
  104. :editor/new-whiteboard {:binding "n w"
  105. :fn #(whiteboard-handler/create-new-whiteboard-and-redirect!)}
  106. :editor/follow-link {:binding "mod+o"
  107. :fn editor-handler/follow-link-under-cursor!}
  108. :editor/open-link-in-sidebar {:binding "mod+shift+o"
  109. :fn editor-handler/open-link-in-sidebar!}
  110. :editor/bold {:binding "mod+b"
  111. :fn editor-handler/bold-format!}
  112. :editor/italics {:binding "mod+i"
  113. :fn editor-handler/italics-format!}
  114. :editor/highlight {:binding "mod+shift+h"
  115. :fn editor-handler/highlight-format!}
  116. :editor/strike-through {:binding "mod+shift+s"
  117. :fn editor-handler/strike-through-format!}
  118. :editor/clear-block {:binding (if mac? "ctrl+l" "alt+l")
  119. :fn editor-handler/clear-block-content!}
  120. :editor/kill-line-before {:binding (if mac? "ctrl+u" "alt+u")
  121. :fn editor-handler/kill-line-before!}
  122. :editor/kill-line-after {:binding (if mac? false "alt+k")
  123. :fn editor-handler/kill-line-after!}
  124. :editor/beginning-of-block {:binding (if mac? false "alt+a")
  125. :fn editor-handler/beginning-of-block}
  126. :editor/end-of-block {:binding (if mac? false "alt+e")
  127. :fn editor-handler/end-of-block}
  128. :editor/forward-word {:binding (if mac? "ctrl+shift+f" "alt+f")
  129. :fn editor-handler/cursor-forward-word}
  130. :editor/backward-word {:binding (if mac? "ctrl+shift+b" "alt+b")
  131. :fn editor-handler/cursor-backward-word}
  132. :editor/forward-kill-word {:binding (if mac? "ctrl+w" "alt+d")
  133. :fn editor-handler/forward-kill-word}
  134. :editor/backward-kill-word {:binding (if mac? false "alt+w")
  135. :fn editor-handler/backward-kill-word}
  136. :editor/replace-block-reference-at-point {:binding "mod+shift+r"
  137. :fn editor-handler/replace-block-reference-with-content-at-point}
  138. :editor/copy-embed {:binding "mod+e"
  139. :fn editor-handler/copy-current-block-embed}
  140. :editor/paste-text-in-one-block-at-point {:binding "mod+shift+v"
  141. :fn paste-handler/editor-on-paste-raw!}
  142. :editor/insert-youtube-timestamp {:binding "mod+shift+y"
  143. :fn commands/insert-youtube-timestamp}
  144. :editor/cycle-todo {:binding "mod+enter"
  145. :fn editor-handler/cycle-todo!}
  146. :editor/up {:binding ["up" "ctrl+p"]
  147. :fn (editor-handler/shortcut-up-down :up)}
  148. :editor/down {:binding ["down" "ctrl+n"]
  149. :fn (editor-handler/shortcut-up-down :down)}
  150. :editor/left {:binding "left"
  151. :fn (editor-handler/shortcut-left-right :left)}
  152. :editor/right {:binding "right"
  153. :fn (editor-handler/shortcut-left-right :right)}
  154. :editor/move-block-up {:binding (if mac? "mod+shift+up" "alt+shift+up")
  155. :fn (editor-handler/move-up-down true)}
  156. :editor/move-block-down {:binding (if mac? "mod+shift+down" "alt+shift+down")
  157. :fn (editor-handler/move-up-down false)}
  158. ;; FIXME: add open edit in non-selection mode
  159. :editor/open-edit {:binding "enter"
  160. :fn (partial editor-handler/open-selected-block! :right)}
  161. :editor/select-block-up {:binding "alt+up"
  162. :fn (editor-handler/on-select-block :up)}
  163. :editor/select-block-down {:binding "alt+down"
  164. :fn (editor-handler/on-select-block :down)}
  165. :editor/select-up {:binding "shift+up"
  166. :fn (editor-handler/shortcut-select-up-down :up)}
  167. :editor/select-down {:binding "shift+down"
  168. :fn (editor-handler/shortcut-select-up-down :down)}
  169. :editor/delete-selection {:binding ["backspace" "delete"]
  170. :fn editor-handler/delete-selection}
  171. :editor/expand-block-children {:binding "mod+down"
  172. :fn editor-handler/expand!}
  173. :editor/collapse-block-children {:binding "mod+up"
  174. :fn editor-handler/collapse!}
  175. :editor/indent {:binding "tab"
  176. :fn (editor-handler/keydown-tab-handler :right)}
  177. :editor/outdent {:binding "shift+tab"
  178. :fn (editor-handler/keydown-tab-handler :left)}
  179. :editor/copy {:binding "mod+c"
  180. :fn editor-handler/shortcut-copy}
  181. :editor/copy-text {:binding "mod+shift+c"
  182. :fn editor-handler/shortcut-copy-text}
  183. :editor/cut {:binding "mod+x"
  184. :fn editor-handler/shortcut-cut}
  185. :editor/undo {:binding "mod+z"
  186. :fn history/undo!}
  187. :editor/redo {:binding ["mod+shift+z" "mod+y"]
  188. :fn history/redo!}
  189. :editor/insert-link {:binding "mod+l"
  190. :fn #(editor-handler/html-link-format!)}
  191. :editor/select-all-blocks {:binding "mod+shift+a"
  192. :fn editor-handler/select-all-blocks!}
  193. :editor/select-parent {:binding "mod+a"
  194. :fn editor-handler/select-parent}
  195. :editor/zoom-in {:binding (if mac? "mod+." "alt+right")
  196. :fn editor-handler/zoom-in!}
  197. :editor/zoom-out {:binding (if mac? "mod+," "alt+left")
  198. :fn editor-handler/zoom-out!}
  199. :editor/toggle-undo-redo-mode {:fn undo-redo/toggle-undo-redo-mode!}
  200. :ui/toggle-brackets {:binding "mod+c mod+b"
  201. :fn config-handler/toggle-ui-show-brackets!}
  202. :go/search-in-page {:binding "mod+shift+k"
  203. :fn #(do
  204. (editor-handler/escape-editing)
  205. (route-handler/go-to-search! :page))}
  206. :go/search {:binding "mod+k"
  207. :fn #(do
  208. (editor-handler/escape-editing false)
  209. (route-handler/go-to-search! :global))}
  210. :go/electron-find-in-page {:binding "mod+f"
  211. :inactive (not (util/electron?))
  212. :fn #(search-handler/open-find-in-page!)}
  213. :go/electron-jump-to-the-next {:binding ["enter" "mod+g"]
  214. :inactive (not (util/electron?))
  215. :fn #(search-handler/loop-find-in-page! false)}
  216. :go/electron-jump-to-the-previous {:binding ["shift+enter" "mod+shift+g"]
  217. :inactive (not (util/electron?))
  218. :fn #(search-handler/loop-find-in-page! true)}
  219. :go/journals {:binding "g j"
  220. :fn route-handler/go-to-journals!}
  221. :go/backward {:binding "mod+open-square-bracket"
  222. :fn (fn [_] (js/window.history.back))}
  223. :go/forward {:binding "mod+close-square-bracket"
  224. :fn (fn [_] (js/window.history.forward))}
  225. :search/re-index {:binding "mod+c mod+s"
  226. :fn (fn [_] (search-handler/rebuild-indices! true))}
  227. :sidebar/open-today-page {:binding (if mac? "mod+shift+j" "alt+shift+j")
  228. :fn page-handler/open-today-in-sidebar}
  229. :sidebar/close-top {:binding "c t"
  230. :fn #(state/sidebar-remove-block! 0)}
  231. :sidebar/clear {:binding "mod+c mod+c"
  232. :fn #(do
  233. (state/clear-sidebar-blocks!)
  234. (state/hide-right-sidebar!))}
  235. :misc/copy {:binding "mod+c"
  236. :fn (fn [] (js/document.execCommand "copy"))}
  237. :command-palette/toggle {:binding "mod+shift+p"
  238. :fn #(do
  239. (editor-handler/escape-editing)
  240. (state/pub-event! [:modal/command-palette]))}
  241. :graph/export-as-html {:fn #(export-handler/download-repo-as-html!
  242. (state/get-current-repo))
  243. :binding false}
  244. :graph/open {:fn #(do
  245. (editor-handler/escape-editing)
  246. (state/set-state! :ui/open-select :graph-open))
  247. :binding "alt+shift+g"}
  248. :graph/remove {:fn #(do
  249. (editor-handler/escape-editing)
  250. (state/set-state! :ui/open-select :graph-remove))
  251. :binding false}
  252. :graph/add {:fn (fn [] (route-handler/redirect! {:to :repo-add}))
  253. :binding false}
  254. :graph/save {:fn #(state/pub-event! [:graph/save])
  255. :binding false}
  256. :graph/re-index {:fn (fn []
  257. (p/let [multiple-windows? (ipc/ipc "graphHasMultipleWindows" (state/get-current-repo))]
  258. (state/pub-event! [:graph/ask-for-re-index (atom multiple-windows?) nil])))
  259. :binding false}
  260. :command/run {:binding "mod+shift+1"
  261. :inactive (not (util/electron?))
  262. :fn #(do
  263. (editor-handler/escape-editing)
  264. (state/pub-event! [:command/run]))}
  265. :go/home {:binding "g h"
  266. :fn #(route-handler/redirect-to-home!)}
  267. :go/all-pages {:binding "g a"
  268. :fn route-handler/redirect-to-all-pages!}
  269. :go/graph-view {:binding "g g"
  270. :fn route-handler/redirect-to-graph-view!}
  271. :go/all-graphs {:binding "g shift+g"
  272. :fn route-handler/redirect-to-all-graphs}
  273. :go/whiteboards {:binding "g w"
  274. :fn route-handler/redirect-to-whiteboard-dashboard!}
  275. :go/keyboard-shortcuts {:binding "g s"
  276. :fn #(route-handler/redirect! {:to :shortcut-setting})}
  277. :go/tomorrow {:binding "g t"
  278. :fn journal-handler/go-to-tomorrow!}
  279. :go/next-journal {:binding "g n"
  280. :fn journal-handler/go-to-next-journal!}
  281. :go/prev-journal {:binding "g p"
  282. :fn journal-handler/go-to-prev-journal!}
  283. :go/flashcards {:binding "g f"
  284. :fn (fn []
  285. (if (state/modal-opened?)
  286. (state/close-modal!)
  287. (state/pub-event! [:modal/show-cards])))}
  288. :ui/toggle-document-mode {:binding "t d"
  289. :fn state/toggle-document-mode!}
  290. :ui/toggle-settings {:binding (if mac? "t s" ["t s" "mod+,"])
  291. :fn ui-handler/toggle-settings-modal!}
  292. :ui/toggle-right-sidebar {:binding "t r"
  293. :fn ui-handler/toggle-right-sidebar!}
  294. :ui/toggle-left-sidebar {:binding "t l"
  295. :fn state/toggle-left-sidebar!}
  296. :ui/toggle-help {:binding "shift+/"
  297. :fn ui-handler/toggle-help!}
  298. :ui/toggle-theme {:binding "t t"
  299. :fn state/toggle-theme!}
  300. :ui/toggle-contents {:binding "alt+shift+c"
  301. :fn ui-handler/toggle-contents!}
  302. :command/toggle-favorite {:binding "mod+shift+f"
  303. :fn page-handler/toggle-favorite!}
  304. :editor/open-file-in-default-app {:binding "mod+d mod+a"
  305. :inactive (not (util/electron?))
  306. :fn page-handler/open-file-in-default-app}
  307. :editor/open-file-in-directory {:binding "mod+d mod+i"
  308. :inactive (not (util/electron?))
  309. :fn page-handler/open-file-in-directory}
  310. :editor/copy-current-file {:binding false
  311. :inactive (not (util/electron?))
  312. :fn page-handler/copy-current-file}
  313. :editor/copy-page-url {:binding false
  314. :inactive (not (util/electron?))
  315. :fn #(page-handler/copy-page-url)}
  316. :ui/toggle-wide-mode {:binding "t w"
  317. :fn ui-handler/toggle-wide-mode!}
  318. :ui/select-theme-color {:binding "t i"
  319. :fn plugin-handler/show-themes-modal!}
  320. :ui/goto-plugins {:binding "t p"
  321. :inactive (not config/lsp-enabled?)
  322. :fn plugin-handler/goto-plugins-dashboard!}
  323. :ui/install-plugins-from-file {:binding false
  324. :inactive (not (config/plugin-config-enabled?))
  325. :fn plugin-config-handler/open-replace-plugins-modal}
  326. :ui/clear-all-notifications {:binding false
  327. :fn :frontend.handler.notification/clear-all!}
  328. :editor/toggle-open-blocks {:binding "t o"
  329. :fn editor-handler/toggle-open!}
  330. :ui/toggle-cards {:binding "t c"
  331. :fn ui-handler/toggle-cards!}
  332. :git/commit {:binding "mod+g c"
  333. :inactive (not (util/electron?))
  334. :fn commit/show-commit-modal!}
  335. :dev/show-block-data {:binding false
  336. :inactive (not (state/developer-mode?))
  337. :fn :frontend.handler.common.developer/show-block-data}
  338. :dev/show-block-ast {:binding false
  339. :inactive (not (state/developer-mode?))
  340. :fn :frontend.handler.common.developer/show-block-ast}
  341. :dev/show-page-data {:binding false
  342. :inactive (not (state/developer-mode?))
  343. :fn :frontend.handler.common.developer/show-page-data}
  344. :dev/show-page-ast {:binding false
  345. :inactive (not (state/developer-mode?))
  346. :fn :frontend.handler.common.developer/show-page-ast}})
  347. (let [keyboard-shortcuts
  348. {::keyboard-shortcuts (set (keys all-default-keyboard-shortcuts))
  349. ::dicts/keyboard-shortcuts (set (keys dicts/all-default-keyboard-shortcuts))}]
  350. (assert (= (::keyboard-shortcuts keyboard-shortcuts) (::dicts/keyboard-shortcuts keyboard-shortcuts))
  351. (str "Keys for keyboard shortcuts must be the same "
  352. (data/diff (::keyboard-shortcuts keyboard-shortcuts) (::dicts/keyboard-shortcuts keyboard-shortcuts)))))
  353. (defn- resolve-fn
  354. "Converts a keyword fn to the actual fn. The fn to be resolved needs to be
  355. marked as ^:export for advanced mode"
  356. [keyword-fn]
  357. (fn []
  358. (if-let [resolved-fn (some-> (find-ns-obj (namespace keyword-fn))
  359. (aget (munge (name keyword-fn))))]
  360. (resolved-fn)
  361. (throw (ex-info (str "Unable to resolve " keyword-fn " to a fn") {})))))
  362. (defn build-category-map [ks]
  363. (->> (select-keys all-default-keyboard-shortcuts ks)
  364. (remove (comp :inactive val))
  365. ;; Convert keyword fns to real fns
  366. (map (fn [[k v]]
  367. [k (if (keyword? (:fn v))
  368. (assoc v :fn (resolve-fn (:fn v)))
  369. v)]))
  370. (into {})))
  371. ;; This is the only var that should be publicly expose :fn functionality
  372. (defonce ^:large-vars/data-var config
  373. (atom
  374. {:shortcut.handler/date-picker
  375. (build-category-map [:date-picker/complete
  376. :date-picker/prev-day
  377. :date-picker/next-day
  378. :date-picker/prev-week
  379. :date-picker/next-week])
  380. :shortcut.handler/pdf
  381. (-> (build-category-map [:pdf/previous-page
  382. :pdf/next-page
  383. :pdf/close
  384. :pdf/find])
  385. (with-meta {:before m/enable-when-not-editing-mode!}))
  386. :shortcut.handler/whiteboard
  387. (-> (build-category-map [:whiteboard/lock
  388. :whiteboard/unlock
  389. :whiteboard/group
  390. :whiteboard/ungroup])
  391. (with-meta {:before m/enable-when-not-editing-mode!}))
  392. :shortcut.handler/auto-complete
  393. (build-category-map [:auto-complete/complete
  394. :auto-complete/prev
  395. :auto-complete/next
  396. :auto-complete/shift-complete
  397. :auto-complete/open-link])
  398. :shortcut.handler/cards
  399. (-> (build-category-map [:cards/toggle-answers
  400. :cards/next-card
  401. :cards/forgotten
  402. :cards/remembered
  403. :cards/recall])
  404. (with-meta {:before m/enable-when-not-editing-mode!}))
  405. :shortcut.handler/block-editing-only
  406. (->
  407. (build-category-map [:editor/escape-editing
  408. :editor/backspace
  409. :editor/delete
  410. :editor/new-block
  411. :editor/new-line
  412. :editor/follow-link
  413. :editor/open-link-in-sidebar
  414. :editor/bold
  415. :editor/italics
  416. :editor/highlight
  417. :editor/strike-through
  418. :editor/clear-block
  419. :editor/kill-line-before
  420. :editor/kill-line-after
  421. :editor/beginning-of-block
  422. :editor/end-of-block
  423. :editor/forward-word
  424. :editor/backward-word
  425. :editor/forward-kill-word
  426. :editor/backward-kill-word
  427. :editor/replace-block-reference-at-point
  428. :editor/copy-embed
  429. :editor/paste-text-in-one-block-at-point
  430. :editor/insert-youtube-timestamp])
  431. (with-meta {:before m/enable-when-editing-mode!}))
  432. :shortcut.handler/editor-global
  433. (->
  434. (build-category-map [:graph/export-as-html
  435. :graph/open
  436. :graph/remove
  437. :graph/add
  438. :graph/save
  439. :graph/re-index
  440. :editor/cycle-todo
  441. :editor/up
  442. :editor/down
  443. :editor/left
  444. :editor/right
  445. :editor/select-up
  446. :editor/select-down
  447. :editor/move-block-up
  448. :editor/move-block-down
  449. :editor/open-edit
  450. :editor/select-block-up
  451. :editor/select-block-down
  452. :editor/select-parent
  453. :editor/delete-selection
  454. :editor/expand-block-children
  455. :editor/collapse-block-children
  456. :editor/indent
  457. :editor/outdent
  458. :editor/copy
  459. :editor/copy-text
  460. :editor/cut
  461. :command/toggle-favorite])
  462. (with-meta {:before m/enable-when-not-component-editing!}))
  463. :shortcut.handler/global-prevent-default
  464. (->
  465. (build-category-map [:editor/insert-link
  466. :editor/select-all-blocks
  467. :editor/zoom-in
  468. :editor/zoom-out
  469. :editor/toggle-undo-redo-mode
  470. :editor/undo
  471. :editor/redo
  472. :ui/toggle-brackets
  473. :go/search-in-page
  474. :go/search
  475. :go/electron-find-in-page
  476. :go/electron-jump-to-the-next
  477. :go/electron-jump-to-the-previous
  478. :go/backward
  479. :go/forward
  480. :search/re-index
  481. :sidebar/open-today-page
  482. :sidebar/clear
  483. :command/run
  484. :command-palette/toggle])
  485. (with-meta {:before m/prevent-default-behavior}))
  486. :shortcut.handler/misc
  487. ;; always overrides the copy due to "mod+c mod+s"
  488. {:misc/copy (:misc/copy all-default-keyboard-shortcuts)}
  489. :shortcut.handler/global-non-editing-only
  490. (->
  491. (build-category-map [:go/home
  492. :go/journals
  493. :go/all-pages
  494. :go/flashcards
  495. :go/graph-view
  496. :go/all-graphs
  497. :go/whiteboards
  498. :go/keyboard-shortcuts
  499. :go/tomorrow
  500. :go/next-journal
  501. :go/prev-journal
  502. :ui/toggle-document-mode
  503. :ui/toggle-settings
  504. :ui/toggle-right-sidebar
  505. :ui/toggle-left-sidebar
  506. :ui/toggle-help
  507. :ui/toggle-theme
  508. :ui/toggle-contents
  509. :editor/open-file-in-default-app
  510. :editor/open-file-in-directory
  511. :editor/copy-current-file
  512. :editor/copy-page-url
  513. :editor/new-whiteboard
  514. :ui/toggle-wide-mode
  515. :ui/select-theme-color
  516. :ui/goto-plugins
  517. :ui/install-plugins-from-file
  518. :editor/toggle-open-blocks
  519. :ui/toggle-cards
  520. :ui/clear-all-notifications
  521. :git/commit
  522. :sidebar/close-top
  523. :dev/show-block-data
  524. :dev/show-block-ast
  525. :dev/show-page-data
  526. :dev/show-page-ast])
  527. (with-meta {:before m/enable-when-not-editing-mode!}))}))
  528. ;; To add a new entry to this map, first add it here and then
  529. ;; a description for it in frontend.modules.shortcut.dicts/category
  530. (def ^:large-vars/data-var category*
  531. "Full list of categories for docs purpose"
  532. {:shortcut.category/basics
  533. [:editor/new-block
  534. :editor/new-line
  535. :editor/indent
  536. :editor/outdent
  537. :editor/select-all-blocks
  538. :editor/select-parent
  539. :go/search
  540. :go/search-in-page
  541. :go/electron-find-in-page
  542. :go/electron-jump-to-the-next
  543. :go/electron-jump-to-the-previous
  544. :editor/undo
  545. :editor/redo
  546. :editor/copy
  547. :editor/copy-text
  548. :editor/cut]
  549. :shortcut.category/formatting
  550. [:editor/bold
  551. :editor/insert-link
  552. :editor/italics
  553. :editor/strike-through
  554. :editor/highlight]
  555. :shortcut.category/navigating
  556. [:editor/up
  557. :editor/down
  558. :editor/left
  559. :editor/right
  560. :editor/zoom-in
  561. :editor/zoom-out
  562. :editor/collapse-block-children
  563. :editor/expand-block-children
  564. :editor/toggle-open-blocks
  565. :go/backward
  566. :go/forward
  567. :go/home
  568. :go/journals
  569. :go/all-pages
  570. :go/graph-view
  571. :go/all-graphs
  572. :go/whiteboards
  573. :go/flashcards
  574. :go/tomorrow
  575. :go/next-journal
  576. :go/prev-journal
  577. :go/keyboard-shortcuts]
  578. :shortcut.category/block-editing
  579. [:editor/backspace
  580. :editor/delete
  581. :editor/indent
  582. :editor/outdent
  583. :editor/new-block
  584. :editor/new-line
  585. :editor/zoom-in
  586. :editor/zoom-out
  587. :editor/cycle-todo
  588. :editor/follow-link
  589. :editor/open-link-in-sidebar
  590. :editor/move-block-up
  591. :editor/move-block-down
  592. :editor/escape-editing]
  593. :shortcut.category/block-command-editing
  594. [:editor/backspace
  595. :editor/clear-block
  596. :editor/kill-line-before
  597. :editor/kill-line-after
  598. :editor/beginning-of-block
  599. :editor/end-of-block
  600. :editor/forward-word
  601. :editor/backward-word
  602. :editor/forward-kill-word
  603. :editor/backward-kill-word
  604. :editor/replace-block-reference-at-point
  605. :editor/copy-embed
  606. :editor/paste-text-in-one-block-at-point
  607. :editor/select-up
  608. :editor/select-down]
  609. :shortcut.category/block-selection
  610. [:editor/open-edit
  611. :editor/select-all-blocks
  612. :editor/select-parent
  613. :editor/select-block-up
  614. :editor/select-block-down
  615. :editor/delete-selection]
  616. :shortcut.category/toggle
  617. [:ui/toggle-help
  618. :editor/toggle-open-blocks
  619. :editor/toggle-undo-redo-mode
  620. :ui/toggle-wide-mode
  621. :ui/toggle-cards
  622. :ui/toggle-document-mode
  623. :ui/toggle-brackets
  624. :ui/toggle-theme
  625. :ui/toggle-left-sidebar
  626. :ui/toggle-right-sidebar
  627. :ui/toggle-settings
  628. :ui/toggle-contents]
  629. :shortcut.category/whiteboard
  630. [:whiteboard/lock
  631. :whiteboard/unlock
  632. :whiteboard/group
  633. :whiteboard/ungroup]
  634. :shortcut.category/others
  635. [:pdf/previous-page
  636. :pdf/next-page
  637. :pdf/close
  638. :pdf/find
  639. :command/toggle-favorite
  640. :command/run
  641. :command-palette/toggle
  642. :graph/export-as-html
  643. :graph/open
  644. :graph/remove
  645. :graph/add
  646. :graph/save
  647. :graph/re-index
  648. :sidebar/close-top
  649. :sidebar/clear
  650. :sidebar/open-today-page
  651. :search/re-index
  652. :editor/insert-youtube-timestamp
  653. :editor/open-file-in-default-app
  654. :editor/open-file-in-directory
  655. :editor/copy-page-url
  656. :editor/new-whiteboard
  657. :auto-complete/prev
  658. :auto-complete/next
  659. :auto-complete/complete
  660. :auto-complete/shift-complete
  661. :auto-complete/open-link
  662. :date-picker/prev-day
  663. :date-picker/next-day
  664. :date-picker/prev-week
  665. :date-picker/next-week
  666. :date-picker/complete
  667. :git/commit
  668. :dev/show-block-data
  669. :dev/show-block-ast
  670. :dev/show-page-data
  671. :dev/show-page-ast
  672. :ui/clear-all-notifications]})
  673. (let [category-maps {::category (set (keys category*))
  674. ::dicts/category (set (keys dicts/category))}]
  675. (assert (= (::category category-maps) (::dicts/category category-maps))
  676. (str "Keys for category maps must be the same "
  677. (data/diff (::category category-maps) (::dicts/category category-maps)))))
  678. (def category
  679. "Active list of categories for docs purpose"
  680. (update-vals
  681. category*
  682. (fn [v]
  683. (vec (remove #(:inactive (get all-default-keyboard-shortcuts %)) v)))))
  684. (defn add-shortcut!
  685. [handler-id id shortcut-map]
  686. (swap! config assoc-in [handler-id id] shortcut-map))
  687. (defn remove-shortcut!
  688. [handler-id id]
  689. (swap! config medley/dissoc-in [handler-id id]))