Skip to content

Commit

Permalink
fix(editor): move hashtag page search from keyup to :did-update
Browse files Browse the repository at this point in the history
  • Loading branch information
andelf authored and tiensonqin committed Nov 23, 2022
1 parent 27fbd33 commit 664e98c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/main/frontend/commands.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
;; TODO: move to frontend.handler.editor.commands

(defonce angle-bracket "<")
(defonce hashtag "#")
(defonce colon ":")
(defonce *current-command (atom nil))

Expand Down
22 changes: 12 additions & 10 deletions src/main/frontend/handler/editor.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1771,7 +1771,7 @@

(handle-command-input-close id))

(defn close-autocomplete-if-outside
(defn- close-autocomplete-if-outside
[input]
(when (and input
(contains? #{:page-search :page-search-hashtag :block-search} (state/get-editor-action))
Expand Down Expand Up @@ -1825,7 +1825,9 @@
;; TODO: is it cross-browser compatible?
;; (not= (gobj/get native-e "inputType") "insertFromPaste")
(cond
(= last-input-char (state/get-editor-command-trigger))
;; By default, "/" is also used as namespace separator in Logseq.
(and (= last-input-char (state/get-editor-command-trigger))
(not (contains? #{:page-search-hashtag} (state/sub :editor/action))))
(do
(state/set-editor-action-data! {:pos (cursor/get-caret-pos input)})
(commands/reinit-matched-commands!)
Expand Down Expand Up @@ -1856,6 +1858,13 @@
(and (= last-input-char commands/colon) (= :property-search (state/get-editor-action)))
(state/clear-editor-action!)

;; Open "Search page or New page" auto-complete
(= last-input-char commands/hashtag)
(do
(state/set-editor-action-data! {:pos (cursor/get-caret-pos input)})
(state/set-editor-last-pos! pos)
(state/set-editor-action! :page-search-hashtag))

:else
nil)))

Expand Down Expand Up @@ -2671,6 +2680,7 @@
nil))

(defn ^:large-vars/cleanup-todo keydown-not-matched-handler
"NOTE: Keydown cannot be used on Android platform"
[format]
(fn [e _key-code]
(let [input-id (state/get-edit-input-id)
Expand Down Expand Up @@ -2751,14 +2761,6 @@
(cursor/move-cursor-forward input)
(autopair input-id key format nil)))

(and hashtag? (or (zero? pos) (re-matches #"\s" (get value (dec pos)))))
(do
(commands/handle-step [:editor/search-page-hashtag])
(if (= key "#")
(state/set-editor-last-pos! (inc (cursor/pos input))) ;; In keydown handler, the `#` is not inserted yet.
(state/set-editor-last-pos! (cursor/pos input)))
(state/set-editor-action-data! {:pos (cursor/get-caret-pos input)}))

(let [sym "$"]
(and (= key sym)
(>= (count value) 1)
Expand Down

0 comments on commit 664e98c

Please sign in to comment.