From 3440a3d43399f023e52c0bc901dd0d752e753c6c Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Tue, 22 Nov 2022 14:43:29 -0500 Subject: [PATCH] Add back fix from #6147 along with its test cases Also fix testing sexp and reset state --- src/main/frontend/handler/editor.cljs | 4 +- src/test/frontend/handler/editor_test.cljs | 43 ++++++++++++++++------ 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index 97f6d67b7..1a139d93e 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -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) diff --git a/src/test/frontend/handler/editor_test.cljs b/src/test/frontend/handler/editor_test.cljs index 8f929e24c..83ceb5faf 100644 --- a/src/test/frontend/handler/editor_test.cljs +++ b/src/test/frontend/handler/editor_test.cljs @@ -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))