Skip to content

Commit

Permalink
fix: pressing alt prevent search modal close
Browse files Browse the repository at this point in the history
Fix #10577
  • Loading branch information
tiensonqin committed Nov 30, 2023
1 parent 5418e6b commit 77880cd
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions src/main/frontend/components/cmdk.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,10 @@
(load-results :files state)
(load-results :recents state))))

(defn close-unless-alt! [state]
(when-not (some-> state ::alt? deref)
(state/close-modal!)))

(defn- copy-block-ref [state]
(when-let [block-uuid (some-> state state->highlighted-item :source-block :block/uuid uuid)]
(editor-handler/copy-block-ref! block-uuid block-ref/->block-ref)
(close-unless-alt! state)))
(state/close-modal!)))

(defmulti handle-action (fn [action _state _event] action))

Expand All @@ -336,7 +332,7 @@
(if (= (:block/type page) "whiteboard")
(route-handler/redirect-to-whiteboard! original-name)
(route-handler/redirect-to-page! original-name)))
(close-unless-alt! state)))
(state/close-modal!)))

(defmethod handle-action :open-block [_ state _event]
(let [block-id (some-> state state->highlighted-item :source-block :block/uuid uuid)
Expand All @@ -346,20 +342,20 @@
(if (= (:block/type page) "whiteboard")
(route-handler/redirect-to-whiteboard! page-name {:block-id block-id})
(route-handler/redirect-to-page! page-name {:anchor (str "ls-block-" block-id)})))
(close-unless-alt! state))))
(state/close-modal!))))

(defmethod handle-action :open-page-right [_ state _event]
(when-let [page-name (some-> state state->highlighted-item :source-page)]
(let [redirect-page-name (model/get-redirect-page-name page-name)
page (db/entity [:block/name (util/page-name-sanity-lc redirect-page-name)])]
(when page
(editor-handler/open-block-in-sidebar! (:block/uuid page))))
(close-unless-alt! state)))
(state/close-modal!)))

(defmethod handle-action :open-block-right [_ state _event]
(when-let [block-uuid (some-> state state->highlighted-item :source-block :block/uuid uuid)]
(editor-handler/open-block-in-sidebar! block-uuid)
(close-unless-alt! state)))
(state/close-modal!)))

(defmethod handle-action :open [_ state event]
(when-let [item (some-> state state->highlighted-item)]
Expand Down Expand Up @@ -392,20 +388,17 @@
(when-let [action (:action command)]
(action)
(when-not (contains? #{:graph/open :graph/remove :ui/toggle-settings :go/flashcards} (:id command))
(close-unless-alt! state)))))
(state/close-modal!)))))

(defmethod handle-action :create [_ state _event]
(let [item (state->highlighted-item state)
create-whiteboard? (= :whiteboard (:source-create item))
create-page? (= :page (:source-create item))
alt? (some-> state ::alt deref)
!input (::input state)]
(cond
(and create-whiteboard? alt?) (whiteboard-handler/create-new-whiteboard-page! @!input)
(and create-whiteboard? (not alt?)) (whiteboard-handler/create-new-whiteboard-and-redirect! @!input)
(and create-page? alt?) (page-handler/create! @!input {:redirect? false})
(and create-page? (not alt?)) (page-handler/create! @!input {:redirect? true}))
(close-unless-alt! state)))
create-whiteboard? (whiteboard-handler/create-new-whiteboard-and-redirect! @!input)
create-page? (page-handler/create! @!input {:redirect? true}))
(state/close-modal!)))

(defn- get-filter-user-input
[input]
Expand Down Expand Up @@ -564,7 +557,6 @@
[state e]
(let [shift? (.-shiftKey e)
meta? (util/meta-key? e)
alt? (.-altKey e)
ctrl? (.-ctrlKey e)
keyname (.-key e)
enter? (= keyname "Enter")
Expand All @@ -578,7 +570,6 @@
as-keyup? (or (= keyname "ArrowUp") (and ctrl? (= keyname "p")))]
(reset! (::shift? state) shift?)
(reset! (::meta? state) meta?)
(reset! (::alt? state) alt?)
(when (or as-keydown? as-keyup?)
(.preventDefault e))

Expand Down Expand Up @@ -611,10 +602,8 @@
(defn- keyup-handler
[state e]
(let [shift? (.-shiftKey e)
meta? (util/meta-key? e)
alt? (.-altKey e)]
meta? (util/meta-key? e)]
(reset! (::shift? state) shift?)
(reset! (::alt? state) alt?)
(reset! (::meta? state) meta?)))

(defn- input-placeholder
Expand Down Expand Up @@ -790,7 +779,6 @@
(keyup-handler state e))))))
(rum/local false ::shift?)
(rum/local false ::meta?)
(rum/local false ::alt?)
(rum/local nil ::highlighted-group)
(rum/local nil ::highlighted-item)
(rum/local default-results ::results)
Expand Down

0 comments on commit 77880cd

Please sign in to comment.