fix: can't switch between modals by shortcuts

pull/7820/head
Tienson Qin 2022-12-21 06:05:18 +08:00
parent b6abd05a97
commit 3a0fa79611
7 changed files with 35 additions and 34 deletions

View File

@ -36,9 +36,6 @@
(rum/defcs command-palette <
(shortcut/disable-all-shortcuts)
(rum/local "" ::input)
{:will-unmount (fn [state]
(state/set-state! :ui/command-palette-open? false)
state)}
[state {:keys [commands limit]
:or {limit 100}}]
(let [input (::input state)]
@ -59,13 +56,3 @@
{:item-render render-command
:class "cp__palette-results"
:on-chosen (fn [cmd] (cp/invoke-command cmd))})]]))
(rum/defc command-palette-modal < rum/reactive
[]
(let [open? (state/sub :ui/command-palette-open?)]
(when open?
(state/set-modal!
#(command-palette {:commands (cp/get-commands)})
{:fullscreen? false
:close-btn? false}))
nil))

View File

@ -411,7 +411,7 @@
:theme "monospace"}
[:a.flex.fade-link.items-center
{:style {:margin-left 12}
:on-click #(state/toggle! :ui/command-palette-open?)}
:on-click #(state/pub-event! :modal/command-palette)}
(ui/icon "command" {:style {:font-size 20}})])])]]
(let [recent-search (mapv (fn [q] {:type :search :data q}) (db/get-key-value :recent/search))
pages (->> (db/get-key-value :recent/pages)

View File

@ -804,7 +804,6 @@
(ui/notification)
(ui/modal)
(ui/sub-modal)
(command-palette/command-palette-modal)
(select/select-modal)
(custom-context-menu)
(plugins/custom-js-installer {:t t

View File

@ -52,7 +52,6 @@
(defn invoke-command [{:keys [action] :as cmd}]
(add-history cmd)
(state/set-state! :ui/command-palette-open? false)
(state/close-modal!)
(action))

View File

@ -15,6 +15,7 @@
[frontend.components.plugins :as plugin]
[frontend.components.search :as component-search]
[frontend.components.shell :as shell]
[frontend.components.command-palette :as command-palette]
[frontend.config :as config]
[frontend.context.i18n :refer [t]]
[frontend.db :as db]
@ -42,6 +43,7 @@
[frontend.handler.user :as user-handler]
[frontend.handler.shell :as shell-handler]
[frontend.handler.web.nfs :as nfs-handler]
[frontend.handler.command-palette :as cp]
[frontend.mobile.core :as mobile]
[frontend.mobile.util :as mobile-util]
[frontend.mobile.graph-picker :as graph-picker]
@ -708,6 +710,12 @@
opts))
{:center? true :close-btn? false :close-backdrop? false}))
(defmethod handle :modal/command-palette [_]
(state/set-modal!
#(command-palette/command-palette {:commands (cp/get-commands)})
{:fullscreen? false
:close-btn? false}))
(defmethod handle :journal/insert-template [[_ page-name]]
(let [page-name (util/page-name-sanity-lc page-name)]
(when-let [page (db/pull [:block/name page-name])]

View File

@ -257,7 +257,7 @@
:go/search {:binding "mod+k"
:fn #(do
(editor-handler/escape-editing)
(editor-handler/escape-editing false)
(route-handler/go-to-search! :global))}
:go/electron-find-in-page {:binding "mod+f"
@ -301,7 +301,7 @@
:command-palette/toggle {:binding "mod+shift+p"
:fn #(do
(editor-handler/escape-editing)
(state/toggle! :ui/command-palette-open?))}
(state/pub-event! [:modal/command-palette]))}
:graph/export-as-html {:fn #(export-handler/export-repo-as-html!
(state/get-current-repo))
@ -499,8 +499,7 @@
:shortcut.handler/editor-global
(->
(build-category-map [:command/run
:command-palette/toggle
(build-category-map [
:graph/export-as-html
:graph/open
:graph/remove
@ -548,7 +547,9 @@
:go/forward
:search/re-index
:sidebar/open-today-page
:sidebar/clear])
:sidebar/clear
:command/run
:command-palette/toggle])
(with-meta {:before m/prevent-default-behavior}))
:shortcut.handler/misc

View File

@ -94,7 +94,6 @@
:ui/file-component nil
:ui/custom-query-components {}
:ui/show-recent? false
:ui/command-palette-open? false
:ui/developer-mode? (or (= (storage/get "developer-mode") "true")
false)
;; remember scroll positions of visited paths
@ -1338,16 +1337,24 @@ Similar to re-frame subscriptions"
{:fullscreen? false
:close-btn? true}))
([modal-panel-content {:keys [id label fullscreen? close-btn? close-backdrop? center?]}]
(when (seq (get-sub-modals))
(close-sub-modal! true))
(swap! state assoc
:modal/id id
:modal/label (or label (if center? "ls-modal-align-center" ""))
:modal/show? (boolean modal-panel-content)
:modal/panel-content modal-panel-content
:modal/fullscreen? fullscreen?
:modal/close-btn? close-btn?
:modal/close-backdrop? (if (boolean? close-backdrop?) close-backdrop? true)) nil))
(let [opened? (modal-opened?)]
(when opened?
(close-modal!))
(when (seq (get-sub-modals))
(close-sub-modal! true))
(async/go
(when opened?
(<! (async/timeout 100)))
(swap! state assoc
:modal/id id
:modal/label (or label (if center? "ls-modal-align-center" ""))
:modal/show? (boolean modal-panel-content)
:modal/panel-content modal-panel-content
:modal/fullscreen? fullscreen?
:modal/close-btn? close-btn?
:modal/close-backdrop? (if (boolean? close-backdrop?) close-backdrop? true))))
nil))
(defn close-modal!
[]