enhance: move appearance setting to the right corner

This commit is contained in:
Tienson Qin
2024-10-12 20:00:08 +08:00
parent 3f0222e74d
commit 18d005791b
4 changed files with 486 additions and 488 deletions

View File

@@ -577,7 +577,7 @@
:fn editor-handler/toggle-open!}
:ui/customize-appearance {:binding "c c"
:fn #(state/pub-event! [:modal/toggle-appearance-modal])}
:fn #(state/pub-event! [:ui/toggle-appearance])}
:git/commit {:binding "mod+g c"
:inactive (not (util/electron?))
@@ -607,8 +607,8 @@
{::commands (set (keys all-built-in-keyboard-shortcuts))
::dicts/commands dicts/abbreviated-commands}]
(assert (= (::commands keyboard-commands) (::dicts/commands keyboard-commands))
(str "Keyboard commands must have an english label"
(data/diff (::commands keyboard-commands) (::commands keyboard-commands)))))
(str "Keyboard commands must have an english label"
(data/diff (::commands keyboard-commands) (::commands keyboard-commands)))))
(defn- resolve-fn
"Converts a keyword fn to the actual fn. The fn to be resolved needs to be
@@ -616,7 +616,7 @@
[keyword-fn]
(fn []
(if-let [resolved-fn (some-> (find-ns-obj (namespace keyword-fn))
(aget (munge (name keyword-fn))))]
(aget (munge (name keyword-fn))))]
(resolved-fn)
(throw (ex-info (str "Unable to resolve " keyword-fn " to a fn") {})))))
@@ -633,376 +633,376 @@
(->> (if (sequential? ks)
ks (let [{:keys [ns includes excludes]} ks]
(->> (keys all-built-in-keyboard-shortcuts)
(filter (fn [k]
(and (or (and ns (keyword? k)
(contains? (->> (if (seqable? ns) (seq ns) [ns]) (map #(name %)) (set))
(namespace k)))
(and includes (contains? (set includes) k)))
(if (not (seq excludes)) true (not (contains? (set excludes) k)))))))))
(select-keys all-built-in-keyboard-shortcuts)
(remove (comp :inactive val))
(filter (fn [k]
(and (or (and ns (keyword? k)
(contains? (->> (if (seqable? ns) (seq ns) [ns]) (map #(name %)) (set))
(namespace k)))
(and includes (contains? (set includes) k)))
(if (not (seq excludes)) true (not (contains? (set excludes) k)))))))))
(select-keys all-built-in-keyboard-shortcuts)
(remove (comp :inactive val))
;; Convert keyword fns to real fns
(map (fn [[k v]]
[k (if (keyword? (:fn v))
(assoc v :fn (resolve-fn (:fn v)))
v)]))
(map (fn [[k v]]
[k (if (:file-graph? v)
(update v :fn wrap-fn-with-file-graph-only-warning)
v)]))
(into {})))
(map (fn [[k v]]
[k (if (keyword? (:fn v))
(assoc v :fn (resolve-fn (:fn v)))
v)]))
(map (fn [[k v]]
[k (if (:file-graph? v)
(update v :fn wrap-fn-with-file-graph-only-warning)
v)]))
(into {})))
;; This is the only var that should be publicly expose :fn functionality
(defonce ^:large-vars/data-var *config
(atom
{:shortcut.handler/date-picker
(build-category-map {:ns :date-picker})
{:shortcut.handler/date-picker
(build-category-map {:ns :date-picker})
:shortcut.handler/pdf
(-> (build-category-map {:ns :pdf})
(with-meta {:before m/enable-when-not-editing-mode!}))
:shortcut.handler/pdf
(-> (build-category-map {:ns :pdf})
(with-meta {:before m/enable-when-not-editing-mode!}))
:shortcut.handler/whiteboard
(-> (build-category-map {:ns :whiteboard})
(with-meta {:before m/enable-when-not-editing-mode!}))
:shortcut.handler/whiteboard
(-> (build-category-map {:ns :whiteboard})
(with-meta {:before m/enable-when-not-editing-mode!}))
:shortcut.handler/auto-complete
(build-category-map {:ns :auto-complete})
:shortcut.handler/auto-complete
(build-category-map {:ns :auto-complete})
:shortcut.handler/cards
(-> (build-category-map {:ns :cards})
(with-meta {:before m/enable-when-not-editing-mode!}))
:shortcut.handler/cards
(-> (build-category-map {:ns :cards})
(with-meta {:before m/enable-when-not-editing-mode!}))
:shortcut.handler/block-editing-only
(-> (build-category-map
[:editor/escape-editing
:editor/backspace
:editor/delete
:editor/zoom-in
:editor/zoom-out
:editor/new-block
:editor/new-line
:editor/follow-link
:editor/open-link-in-sidebar
:editor/bold
:editor/italics
:editor/highlight
:editor/strike-through
:editor/clear-block
:editor/kill-line-before
:editor/kill-line-after
:editor/beginning-of-block
:editor/end-of-block
:editor/forward-word
:editor/backward-word
:editor/forward-kill-word
:editor/backward-kill-word
:editor/replace-block-reference-at-point
:editor/copy-embed
:editor/paste-text-in-one-block-at-point
:editor/insert-youtube-timestamp])
(with-meta {:before m/enable-when-editing-mode!}))
:shortcut.handler/block-editing-only
(-> (build-category-map
[:editor/escape-editing
:editor/backspace
:editor/delete
:editor/zoom-in
:editor/zoom-out
:editor/new-block
:editor/new-line
:editor/follow-link
:editor/open-link-in-sidebar
:editor/bold
:editor/italics
:editor/highlight
:editor/strike-through
:editor/clear-block
:editor/kill-line-before
:editor/kill-line-after
:editor/beginning-of-block
:editor/end-of-block
:editor/forward-word
:editor/backward-word
:editor/forward-kill-word
:editor/backward-kill-word
:editor/replace-block-reference-at-point
:editor/copy-embed
:editor/paste-text-in-one-block-at-point
:editor/insert-youtube-timestamp])
(with-meta {:before m/enable-when-editing-mode!}))
:shortcut.handler/editor-global
(-> (build-category-map
[:graph/export-as-html
:graph/open
:graph/remove
:graph/add
:graph/db-add
:graph/db-save
:graph/re-index
:editor/cycle-todo
:editor/up
:editor/down
:editor/left
:editor/right
:editor/select-up
:editor/select-down
:editor/move-block-up
:editor/move-block-down
:editor/open-edit
:editor/select-block-up
:editor/select-block-down
:editor/select-parent
:editor/delete-selection
:editor/expand-block-children
:editor/collapse-block-children
:editor/toggle-block-children
:editor/indent
:editor/outdent
:editor/copy
:editor/copy-text
:editor/cut
:command/toggle-favorite
:editor/jump])
(with-meta {:before m/enable-when-not-component-editing!}))
:shortcut.handler/editor-global
(-> (build-category-map
[:graph/export-as-html
:graph/open
:graph/remove
:graph/add
:graph/db-add
:graph/db-save
:graph/re-index
:editor/cycle-todo
:editor/up
:editor/down
:editor/left
:editor/right
:editor/select-up
:editor/select-down
:editor/move-block-up
:editor/move-block-down
:editor/open-edit
:editor/select-block-up
:editor/select-block-down
:editor/select-parent
:editor/delete-selection
:editor/expand-block-children
:editor/collapse-block-children
:editor/toggle-block-children
:editor/indent
:editor/outdent
:editor/copy
:editor/copy-text
:editor/cut
:command/toggle-favorite
:editor/jump])
(with-meta {:before m/enable-when-not-component-editing!}))
:shortcut.handler/global-prevent-default
(-> (build-category-map
[:editor/insert-link
:editor/select-all-blocks
:editor/toggle-number-list
:editor/undo
:editor/redo
:ui/toggle-brackets
:go/search-in-page
:go/search
:go/search-themes
:go/electron-find-in-page
:go/electron-jump-to-the-next
:go/electron-jump-to-the-previous
:go/backward
:go/forward
:search/re-index
:sidebar/open-today-page
:sidebar/clear
:command/run
:command-palette/toggle
:editor/add-property
:window/close])
(with-meta {:before m/prevent-default-behavior}))
:shortcut.handler/global-prevent-default
(-> (build-category-map
[:editor/insert-link
:editor/select-all-blocks
:editor/toggle-number-list
:editor/undo
:editor/redo
:ui/toggle-brackets
:go/search-in-page
:go/search
:go/search-themes
:go/electron-find-in-page
:go/electron-jump-to-the-next
:go/electron-jump-to-the-previous
:go/backward
:go/forward
:search/re-index
:sidebar/open-today-page
:sidebar/clear
:command/run
:command-palette/toggle
:editor/add-property
:window/close])
(with-meta {:before m/prevent-default-behavior}))
:shortcut.handler/global-non-editing-only
(-> (build-category-map
[:go/home
:go/journals
:go/all-pages
:go/flashcards
:go/graph-view
:go/all-graphs
:go/whiteboards
:go/keyboard-shortcuts
:go/tomorrow
:go/next-journal
:go/prev-journal
:ui/toggle-document-mode
:ui/toggle-settings
:ui/toggle-right-sidebar
:ui/toggle-left-sidebar
:ui/toggle-help
:ui/toggle-theme
:ui/toggle-contents
:editor/open-file-in-default-app
:editor/open-file-in-directory
:editor/copy-current-file
:editor/copy-page-url
:editor/new-whiteboard
:editor/add-property-deadline
:editor/add-property-status
:editor/add-property-priority
:editor/add-property-icon
:editor/toggle-display-all-properties
:ui/toggle-wide-mode
:ui/select-theme-color
:ui/goto-plugins
:ui/install-plugins-from-file
:editor/toggle-open-blocks
:ui/clear-all-notifications
:git/commit
:sidebar/close-top
:dev/show-block-data
:dev/show-block-ast
:dev/show-page-data
:dev/show-page-ast
:dev/replace-graph-with-db-file
:ui/customize-appearance])
(with-meta {:before m/enable-when-not-editing-mode!}))
:shortcut.handler/global-non-editing-only
(-> (build-category-map
[:go/home
:go/journals
:go/all-pages
:go/flashcards
:go/graph-view
:go/all-graphs
:go/whiteboards
:go/keyboard-shortcuts
:go/tomorrow
:go/next-journal
:go/prev-journal
:ui/toggle-document-mode
:ui/toggle-settings
:ui/toggle-right-sidebar
:ui/toggle-left-sidebar
:ui/toggle-help
:ui/toggle-theme
:ui/toggle-contents
:editor/open-file-in-default-app
:editor/open-file-in-directory
:editor/copy-current-file
:editor/copy-page-url
:editor/new-whiteboard
:editor/add-property-deadline
:editor/add-property-status
:editor/add-property-priority
:editor/add-property-icon
:editor/toggle-display-all-properties
:ui/toggle-wide-mode
:ui/select-theme-color
:ui/goto-plugins
:ui/install-plugins-from-file
:editor/toggle-open-blocks
:ui/clear-all-notifications
:git/commit
:sidebar/close-top
:dev/show-block-data
:dev/show-block-ast
:dev/show-page-data
:dev/show-page-ast
:dev/replace-graph-with-db-file
:ui/customize-appearance])
(with-meta {:before m/enable-when-not-editing-mode!}))
:shortcut.handler/misc
:shortcut.handler/misc
;; always overrides the copy due to "mod+c mod+s"
{:misc/copy (:misc/copy all-built-in-keyboard-shortcuts)}}))
{:misc/copy (:misc/copy all-built-in-keyboard-shortcuts)}}))
;; To add a new entry to this map, first add it here and then
;; a description for it in frontend.dicts.en/dicts
;; Full list of categories for docs purpose
(defonce ^:large-vars/data-var *category
(atom
{:shortcut.category/basics
[:go/search
:go/search-themes
:editor/new-block
:editor/new-line
:editor/indent
:editor/outdent
:editor/select-all-blocks
:editor/select-parent
:go/search-in-page
:command-palette/toggle
:go/electron-find-in-page
:go/electron-jump-to-the-next
:go/electron-jump-to-the-previous
:editor/undo
:editor/redo
:editor/copy
:editor/copy-text
:editor/cut]
{:shortcut.category/basics
[:go/search
:go/search-themes
:editor/new-block
:editor/new-line
:editor/indent
:editor/outdent
:editor/select-all-blocks
:editor/select-parent
:go/search-in-page
:command-palette/toggle
:go/electron-find-in-page
:go/electron-jump-to-the-next
:go/electron-jump-to-the-previous
:editor/undo
:editor/redo
:editor/copy
:editor/copy-text
:editor/cut]
:shortcut.category/formatting
[:editor/bold
:editor/insert-link
:editor/italics
:editor/strike-through
:editor/highlight]
:shortcut.category/formatting
[:editor/bold
:editor/insert-link
:editor/italics
:editor/strike-through
:editor/highlight]
:shortcut.category/navigating
[:editor/up
:editor/down
:editor/left
:editor/right
:editor/collapse-block-children
:editor/expand-block-children
:editor/toggle-block-children
:editor/toggle-open-blocks
:editor/jump
:go/backward
:go/forward
:go/home
:go/journals
:go/all-pages
:go/graph-view
:go/all-graphs
:go/whiteboards
:go/flashcards
:go/tomorrow
:go/next-journal
:go/prev-journal
:go/keyboard-shortcuts]
:shortcut.category/navigating
[:editor/up
:editor/down
:editor/left
:editor/right
:editor/collapse-block-children
:editor/expand-block-children
:editor/toggle-block-children
:editor/toggle-open-blocks
:editor/jump
:go/backward
:go/forward
:go/home
:go/journals
:go/all-pages
:go/graph-view
:go/all-graphs
:go/whiteboards
:go/flashcards
:go/tomorrow
:go/next-journal
:go/prev-journal
:go/keyboard-shortcuts]
:shortcut.category/block-editing
[:editor/backspace
:editor/delete
:editor/indent
:editor/outdent
:editor/new-block
:editor/new-line
:editor/zoom-in
:editor/zoom-out
:editor/cycle-todo
:editor/follow-link
:editor/open-link-in-sidebar
:editor/move-block-up
:editor/move-block-down
:editor/escape-editing]
:shortcut.category/block-editing
[:editor/backspace
:editor/delete
:editor/indent
:editor/outdent
:editor/new-block
:editor/new-line
:editor/zoom-in
:editor/zoom-out
:editor/cycle-todo
:editor/follow-link
:editor/open-link-in-sidebar
:editor/move-block-up
:editor/move-block-down
:editor/escape-editing]
:shortcut.category/block-command-editing
[:editor/backspace
:editor/clear-block
:editor/kill-line-before
:editor/kill-line-after
:editor/beginning-of-block
:editor/end-of-block
:editor/forward-word
:editor/backward-word
:editor/forward-kill-word
:editor/backward-kill-word
:editor/replace-block-reference-at-point
:editor/copy-embed
:editor/paste-text-in-one-block-at-point
:editor/select-up
:editor/select-down]
:shortcut.category/block-command-editing
[:editor/backspace
:editor/clear-block
:editor/kill-line-before
:editor/kill-line-after
:editor/beginning-of-block
:editor/end-of-block
:editor/forward-word
:editor/backward-word
:editor/forward-kill-word
:editor/backward-kill-word
:editor/replace-block-reference-at-point
:editor/copy-embed
:editor/paste-text-in-one-block-at-point
:editor/select-up
:editor/select-down]
:shortcut.category/block-selection
[:editor/open-edit
:editor/select-all-blocks
:editor/select-parent
:editor/select-block-up
:editor/select-block-down
:editor/delete-selection
:editor/add-property
:editor/add-property-deadline
:editor/add-property-status
:editor/add-property-priority
:editor/add-property-icon
:editor/toggle-display-all-properties]
:shortcut.category/block-selection
[:editor/open-edit
:editor/select-all-blocks
:editor/select-parent
:editor/select-block-up
:editor/select-block-down
:editor/delete-selection
:editor/add-property
:editor/add-property-deadline
:editor/add-property-status
:editor/add-property-priority
:editor/add-property-icon
:editor/toggle-display-all-properties]
:shortcut.category/toggle
[:ui/toggle-help
:editor/toggle-open-blocks
:editor/toggle-number-list
:ui/toggle-wide-mode
:ui/toggle-document-mode
:ui/toggle-brackets
:ui/toggle-theme
:ui/toggle-left-sidebar
:ui/toggle-right-sidebar
:ui/toggle-settings
:ui/toggle-contents
:ui/customize-appearance]
:shortcut.category/toggle
[:ui/toggle-help
:editor/toggle-open-blocks
:editor/toggle-number-list
:ui/toggle-wide-mode
:ui/toggle-document-mode
:ui/toggle-brackets
:ui/toggle-theme
:ui/toggle-left-sidebar
:ui/toggle-right-sidebar
:ui/toggle-settings
:ui/toggle-contents
:ui/customize-appearance]
:shortcut.category/whiteboard
[:editor/new-whiteboard
:whiteboard/select
:whiteboard/pan
:whiteboard/portal
:whiteboard/pencil
:whiteboard/highlighter
:whiteboard/eraser
:whiteboard/connector
:whiteboard/text
:whiteboard/rectangle
:whiteboard/ellipse
:whiteboard/reset-zoom
:whiteboard/zoom-to-fit
:whiteboard/zoom-to-selection
:whiteboard/zoom-out
:whiteboard/zoom-in
:whiteboard/send-backward
:whiteboard/send-to-back
:whiteboard/bring-forward
:whiteboard/bring-to-front
:whiteboard/lock
:whiteboard/unlock
:whiteboard/group
:whiteboard/ungroup
:whiteboard/toggle-grid
:whiteboard/clone-left
:whiteboard/clone-right
:whiteboard/clone-top
:whiteboard/clone-bottom]
:shortcut.category/whiteboard
[:editor/new-whiteboard
:whiteboard/select
:whiteboard/pan
:whiteboard/portal
:whiteboard/pencil
:whiteboard/highlighter
:whiteboard/eraser
:whiteboard/connector
:whiteboard/text
:whiteboard/rectangle
:whiteboard/ellipse
:whiteboard/reset-zoom
:whiteboard/zoom-to-fit
:whiteboard/zoom-to-selection
:whiteboard/zoom-out
:whiteboard/zoom-in
:whiteboard/send-backward
:whiteboard/send-to-back
:whiteboard/bring-forward
:whiteboard/bring-to-front
:whiteboard/lock
:whiteboard/unlock
:whiteboard/group
:whiteboard/ungroup
:whiteboard/toggle-grid
:whiteboard/clone-left
:whiteboard/clone-right
:whiteboard/clone-top
:whiteboard/clone-bottom]
:shortcut.category/others
[:pdf/previous-page
:pdf/next-page
:pdf/close
:pdf/find
:command/toggle-favorite
:command/run
:graph/export-as-html
:graph/open
:graph/remove
:graph/add
:graph/re-index
:sidebar/close-top
:sidebar/clear
:sidebar/open-today-page
:search/re-index
:editor/insert-youtube-timestamp
:editor/open-file-in-default-app
:editor/open-file-in-directory
:editor/copy-page-url
:window/close
:auto-complete/prev
:auto-complete/next
:auto-complete/complete
:auto-complete/shift-complete
:auto-complete/meta-complete
:git/commit
:dev/show-block-data
:dev/show-block-ast
:dev/show-page-data
:dev/show-page-ast
:dev/replace-graph-with-db-file
:ui/clear-all-notifications]
:shortcut.category/others
[:pdf/previous-page
:pdf/next-page
:pdf/close
:pdf/find
:command/toggle-favorite
:command/run
:graph/export-as-html
:graph/open
:graph/remove
:graph/add
:graph/re-index
:sidebar/close-top
:sidebar/clear
:sidebar/open-today-page
:search/re-index
:editor/insert-youtube-timestamp
:editor/open-file-in-default-app
:editor/open-file-in-directory
:editor/copy-page-url
:window/close
:auto-complete/prev
:auto-complete/next
:auto-complete/complete
:auto-complete/shift-complete
:auto-complete/meta-complete
:git/commit
:dev/show-block-data
:dev/show-block-ast
:dev/show-page-data
:dev/show-page-ast
:dev/replace-graph-with-db-file
:ui/clear-all-notifications]
:shortcut.category/plugins
[]}))
:shortcut.category/plugins
[]}))
(let [category-maps {::category (set (keys @*category))
::dicts/category dicts/categories}]
(assert (= (::category category-maps) (::dicts/category category-maps))
(str "Keys for category maps must have an english label "
(data/diff (::category category-maps) (::dicts/category category-maps)))))
(str "Keys for category maps must have an english label "
(data/diff (::category category-maps) (::dicts/category category-maps)))))
(defn get-category-shortcuts
"Active list of categories for docs purpose"
@@ -1019,9 +1019,9 @@
(swap! *shortcut-cmds assoc id (:cmd shortcut-map))
(let [plugin? (str/starts-with? (str id) ":plugin.")
category (or (:category shortcut-map)
(if plugin?
:shortcut.category/plugins
:shortcut.category/others))]
(if plugin?
:shortcut.category/plugins
:shortcut.category/others))]
(swap! *category update category #(conj % id))))))
(defn remove-shortcut!