mirror of https://github.com/logseq/logseq
parent
0fbd639007
commit
818e735d7c
|
@ -1772,7 +1772,9 @@
|
|||
(contains? #{:page-search :page-search-hashtag :block-search} (state/get-editor-action))
|
||||
(not (wrapped-by? input page-ref/left-brackets page-ref/right-brackets))
|
||||
(not (wrapped-by? input block-ref/left-parens block-ref/right-parens))
|
||||
(not (wrapped-by? input "#" "")))
|
||||
;; wrapped-by? doesn't detect multiple beginnings when ending with "" so
|
||||
;; use subs to correctly detect current hashtag
|
||||
(not (text-util/wrapped-by? (subs (.-value input) 0 (cursor/pos input)) (cursor/pos input) commands/hashtag "")))
|
||||
(state/clear-editor-action!)))
|
||||
|
||||
(defn resize-image!
|
||||
|
|
|
@ -78,13 +78,15 @@
|
|||
(let [pos (or cursor-pos (count value))
|
||||
input #js {:value value}]
|
||||
(with-redefs [editor/get-matched-commands (constantly commands)
|
||||
;; Ignore as none of its behaviors are tested
|
||||
editor/default-case-for-keyup-handler (constantly nil)
|
||||
cursor/pos (constantly pos)]
|
||||
((editor/keyup-handler nil input nil)
|
||||
#js {:key (subs value (dec (count value)))}
|
||||
nil))))
|
||||
|
||||
(deftest keyup-handler-test
|
||||
(testing "Command completion"
|
||||
(testing "Command autocompletion"
|
||||
(keyup-handler {:value "/b"
|
||||
:action :commands
|
||||
:commands [:fake-command]})
|
||||
|
@ -104,6 +106,17 @@
|
|||
(keyup-handler {:value "/block " :action :commands})
|
||||
(is (= :commands (state/get-editor-action))
|
||||
"Completion stays open if space is part of the search term for /"))
|
||||
|
||||
(testing "Tag autocompletion"
|
||||
(keyup-handler {:value "foo #b" :action :page-search-hashtag})
|
||||
(is (= :page-search-hashtag (state/get-editor-action))
|
||||
"Completion stays open for one tag")
|
||||
|
||||
(keyup-handler {:value "text # #bar"
|
||||
:action :page-search-hashtag
|
||||
:cursor-pos 6})
|
||||
(is (= :page-search-hashtag (state/get-editor-action))
|
||||
"Completion stays open when typing tag before another tag"))
|
||||
;; Reset state
|
||||
(state/set-editor-action! nil))
|
||||
|
||||
|
|
Loading…
Reference in New Issue