mirror of https://github.com/logseq/logseq
fix: disable toggle shortcuts when not in editing mode
parent
70c3c6d653
commit
8bacca8a9d
|
@ -110,23 +110,22 @@
|
||||||
|
|
||||||
(defn toggle-between-page-and-file!
|
(defn toggle-between-page-and-file!
|
||||||
[state e]
|
[state e]
|
||||||
(when-not (state/editing?)
|
(let [current-route (state/get-current-route)]
|
||||||
(let [current-route (state/get-current-route)]
|
(case current-route
|
||||||
(case current-route
|
:home
|
||||||
:home
|
(redirect-to-file! (date/today))
|
||||||
(redirect-to-file! (date/today))
|
|
||||||
|
|
||||||
:all-journals
|
:all-journals
|
||||||
(redirect-to-file! (date/today))
|
(redirect-to-file! (date/today))
|
||||||
|
|
||||||
:page
|
:page
|
||||||
(when-let [page-name (get-in (state/get-route-match) [:path-params :name])]
|
(when-let [page-name (get-in (state/get-route-match) [:path-params :name])]
|
||||||
(redirect-to-file! page-name))
|
(redirect-to-file! page-name))
|
||||||
|
|
||||||
:file
|
:file
|
||||||
(when-let [path (get-in (state/get-route-match) [:path-params :path])]
|
(when-let [path (get-in (state/get-route-match) [:path-params :path])]
|
||||||
(when-let [page (db/get-file-page path)]
|
(when-let [page (db/get-file-page path)]
|
||||||
(redirect! {:to :page
|
(redirect! {:to :page
|
||||||
:path-params {:name page}})))
|
:path-params {:name page}})))
|
||||||
|
|
||||||
nil))))
|
nil)))
|
||||||
|
|
|
@ -22,43 +22,58 @@
|
||||||
;; and stop event from bubbling
|
;; and stop event from bubbling
|
||||||
false))
|
false))
|
||||||
|
|
||||||
|
(defn enable-when-not-editing-mode!
|
||||||
|
[f]
|
||||||
|
(fn [state e]
|
||||||
|
(when-not (state/editing?)
|
||||||
|
(f state e))))
|
||||||
|
|
||||||
|
(def shortcut state/get-shortcut)
|
||||||
|
|
||||||
(defonce chords
|
(defonce chords
|
||||||
{
|
{
|
||||||
(or (state/get-shortcut :editor/toggle-document-mode) "t d") state/toggle-document-mode!
|
;; non-editing mode
|
||||||
(or (state/get-shortcut :ui/toggle-theme) "t t") state/toggle-theme!
|
(or (shortcut :editor/toggle-document-mode) "t d")
|
||||||
(or (state/get-shortcut :ui/toggle-right-sidebar) "t r") ui-handler/toggle-right-sidebar!
|
(enable-when-not-editing-mode! state/toggle-document-mode!)
|
||||||
(or (state/get-shortcut :ui/toggle-new-block) "t e") state/toggle-new-block-shortcut!
|
(or (shortcut :ui/toggle-theme) "t t")
|
||||||
(or (state/get-shortcut :ui/toggle-between-page-and-file) "s") route-handler/toggle-between-page-and-file!
|
(enable-when-not-editing-mode! state/toggle-theme!)
|
||||||
|
(or (shortcut :ui/toggle-right-sidebar) "t r")
|
||||||
|
(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/toggle-between-page-and-file) "s")
|
||||||
|
(enable-when-not-editing-mode! route-handler/toggle-between-page-and-file!)
|
||||||
|
|
||||||
"tab" (editor-handler/on-tab :right)
|
"tab" (editor-handler/on-tab :right)
|
||||||
"shift+tab" (editor-handler/on-tab :left)
|
"shift+tab" (editor-handler/on-tab :left)
|
||||||
(or (state/get-shortcut :editor/undo) "mod+z") [history-handler/undo! true]
|
(or (shortcut :editor/undo) "mod+z") [history-handler/undo! true]
|
||||||
(or (state/get-shortcut :editor/redo) "mod+y") [history-handler/redo! true]
|
(or (shortcut :editor/redo) "mod+y") [history-handler/redo! true]
|
||||||
(or (state/get-shortcut :go/search) "mod+u") [route-handler/go-to-search! true]
|
(or (shortcut :go/search) "mod+u") [route-handler/go-to-search! true]
|
||||||
(or (state/get-shortcut :go/journals) "alt+j") [route-handler/go-to-journals! true]
|
(or (shortcut :go/journals) "alt+j") [route-handler/go-to-journals! true]
|
||||||
(or (state/get-shortcut :editor/zoom-in)
|
(or (shortcut :editor/zoom-in)
|
||||||
(if util/mac? "alt+." "alt+right")) [editor-handler/zoom-in! true]
|
(if util/mac? "alt+." "alt+right")) [editor-handler/zoom-in! true]
|
||||||
(or (state/get-shortcut :editor/zoom-out)
|
(or (shortcut :editor/zoom-out)
|
||||||
(if util/mac? "alt+," "alt+left")) [editor-handler/zoom-out! true]
|
(if util/mac? "alt+," "alt+left")) [editor-handler/zoom-out! true]
|
||||||
(or (state/get-shortcut :editor/cycle-todo)
|
(or (shortcut :editor/cycle-todo)
|
||||||
"mod+enter") [editor-handler/cycle-todo! true]
|
"mod+enter") [editor-handler/cycle-todo! true]
|
||||||
(or (state/get-shortcut :editor/expand-block-children) "mod+down") [editor-handler/expand! true]
|
(or (shortcut :editor/expand-block-children) "mod+down") [editor-handler/expand! true]
|
||||||
(or (state/get-shortcut :editor/collapse-block-children) "mod+up") [editor-handler/collapse! true]
|
(or (shortcut :editor/collapse-block-children) "mod+up") [editor-handler/collapse! true]
|
||||||
(or (state/get-shortcut :editor/follow-link) "mod+o") [editor-handler/follow-link-under-cursor! true]
|
(or (shortcut :editor/follow-link) "mod+o") [editor-handler/follow-link-under-cursor! true]
|
||||||
(or (state/get-shortcut :editor/open-link-in-sidebar) "mod+shift+o") [editor-handler/open-link-in-sidebar! true]
|
(or (shortcut :editor/open-link-in-sidebar) "mod+shift+o") [editor-handler/open-link-in-sidebar! true]
|
||||||
(or (state/get-shortcut :editor/bold) "mod+b") [editor-handler/bold-format! true]
|
(or (shortcut :editor/bold) "mod+b") [editor-handler/bold-format! true]
|
||||||
(or (state/get-shortcut :editor/italics) "mod+i") [editor-handler/italics-format! true]
|
(or (shortcut :editor/italics) "mod+i") [editor-handler/italics-format! true]
|
||||||
(or (state/get-shortcut :editor/highlight) "mod+h") [editor-handler/highlight-format! true]
|
(or (shortcut :editor/highlight) "mod+h") [editor-handler/highlight-format! true]
|
||||||
(or (state/get-shortcut :editor/insert-link) "mod+k") [editor-handler/html-link-format! true]
|
(or (shortcut :editor/insert-link) "mod+k") [editor-handler/html-link-format! true]
|
||||||
(or (state/get-shortcut :editor/select-all-blocks) "mod+shift+a") [editor-handler/select-all-blocks! true]
|
(or (shortcut :editor/select-all-blocks) "mod+shift+a") [editor-handler/select-all-blocks! true]
|
||||||
(or (state/get-shortcut :editor/move-block-up) "alt+shift+up") [(fn [state e] (editor-handler/move-up-down e true)) true]
|
(or (shortcut :editor/move-block-up) "alt+shift+up") [(fn [state e] (editor-handler/move-up-down e true)) true]
|
||||||
(or (state/get-shortcut :editor/move-block-down) "alt+shift+down") [(fn [state e] (editor-handler/move-up-down e false)) true]
|
(or (shortcut :editor/move-block-down) "alt+shift+down") [(fn [state e] (editor-handler/move-up-down e false)) true]
|
||||||
(or (state/get-shortcut :editor/save) "mod+s") [editor-handler/save! true]
|
(or (shortcut :editor/save) "mod+s") [editor-handler/save! true]
|
||||||
|
|
||||||
(or (state/get-shortcut :editor/next) "down") (fn [state e] (editor-handler/open-block! true))
|
(or (shortcut :editor/next) "down") (fn [state e] (editor-handler/open-block! true))
|
||||||
(or (state/get-shortcut :editor/prev) "up") (fn [state e] (editor-handler/open-block! false))
|
(or (shortcut :editor/prev) "up") (fn [state e] (editor-handler/open-block! false))
|
||||||
|
|
||||||
(or (state/get-shortcut :search/re-index) "mod+c mod+s") [search-handler/rebuild-indices! true]
|
(or (shortcut :search/re-index) "mod+c mod+s") [search-handler/rebuild-indices! true]
|
||||||
(or (state/get-shortcut :ui/toggle-brackets) "mod+c mod+b") [config-handler/toggle-ui-show-brackets! true]})
|
(or (shortcut :ui/toggle-brackets) "mod+c mod+b") [config-handler/toggle-ui-show-brackets! true]})
|
||||||
|
|
||||||
(defonce bind! (gobj/get mousetrap "bind"))
|
(defonce bind! (gobj/get mousetrap "bind"))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue