config.cljs 30 KB

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