Add back fix from #6147 along with its test cases

Also fix testing sexp and reset state
pull/7395/head^2
Gabriel Horner 2022-11-22 14:43:29 -05:00 committed by Tienson Qin
parent 674022d4fb
commit 3440a3d433
2 changed files with 35 additions and 12 deletions

View File

@ -1859,7 +1859,9 @@
(state/clear-editor-action!)
;; Open "Search page or New page" auto-complete
(= last-input-char commands/hashtag)
(and (= last-input-char commands/hashtag)
;; Only trigger at beginning of line or before whitespace
(or (= 1 pos) (contains? #{" " "\t"} (get (.-value input) (- pos 2)))))
(do
(state/set-editor-action-data! {:pos (cursor/get-caret-pos input)})
(state/set-editor-last-pos! pos)

View File

@ -96,24 +96,45 @@
(handle-last-input-handler {:value "first \nfoo::bar"
:cursor-pos (dec (count "first "))})
(is (= nil (state/get-editor-action))
"Don't autocomplete properties if typing in a block where properties already exist")
"Don't autocomplete properties if typing in a block where properties already exist"))
(testing "Tag autocompletion"
(handle-last-input-handler {:value "#"
:cursor-pos 1})
(is (= :page-search-hashtag (state/get-editor-action))
"Page search if only hashtags has been typed")
(handle-last-input-handler {:value "foo bar#"
:cursor-pos 8})
(is (= :page-search-hashtag (state/get-editor-action))
"Page search if hashtags has been typed as EOL")
"Page search if only hashtag has been typed")
(handle-last-input-handler {:value "foo #"
:cursor-pos 5})
(is (= :page-search-hashtag (state/get-editor-action))
"Page search if hashtags has been typed after a space")
"Page search if hashtag has been typed at EOL")
(handle-last-input-handler {:value "foo#bar"
:cursor-pos 4})
(handle-last-input-handler {:value "#Some words"
:cursor-pos 1})
(is (= :page-search-hashtag (state/get-editor-action))
"Page search if hashtags has been typed in the middle of a line")))
"Page search if hashtag is at start of line and there are existing words")
(handle-last-input-handler {:value "foo #"
:cursor-pos 5})
(is (= :page-search-hashtag (state/get-editor-action))
"Page search if hashtag is at EOL and after a space")
(handle-last-input-handler {:value "foo #bar"
:cursor-pos 5})
(is (= :page-search-hashtag (state/get-editor-action))
"Page search if hashtag is in middle of line and after a space")
(handle-last-input-handler {:value "String#" :cursor-pos 7})
(is (= nil (state/get-editor-action))
"No page search if hashtag has been typed at end of a word")
(handle-last-input-handler {:value "foo#bar" :cursor-pos 4})
(is (= nil (state/get-editor-action))
"No page search if hashtag is in middle of word")
(handle-last-input-handler {:value "`String#gsub and String#`"
:cursor-pos (dec (count "`String#gsub and String#`"))})
(is (= nil (state/get-editor-action))
"No page search within backticks"))
;; Reset state
(state/set-editor-action! nil))