Skip to content

Commit

Permalink
fix: CodeMirror shortcuts cause page routing
Browse files Browse the repository at this point in the history
  • Loading branch information
situ2001 authored and logseq-cldwalker committed Jan 24, 2023
1 parent 6ad521a commit e2ff4b9
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/frontend/extensions/code.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,18 @@
{:editor editor
:config config
:state state})))

(.addEventListener element "keydown" (fn [e]
(let [key-code (.-code e)
meta-or-ctrl-pressed? (or (.-ctrlKey e) (.-metaKey e))]
(when meta-or-ctrl-pressed?
;; prevent default behavior of browser
;; Cmd + [ => Go back in browser, outdent in CodeMirror
;; Cmd + ] => Go forward in browser, indent in CodeMirror
(case key-code
"BracketLeft" (util/stop e)
"BracketRight" (util/stop e)
nil)))))
(.addEventListener element "mousedown"
(fn [e]
(util/stop e)
Expand Down

0 comments on commit e2ff4b9

Please sign in to comment.