diff --git a/src/main/frontend/components/editor.cljs b/src/main/frontend/components/editor.cljs index c9007757cc..84a59e272a 100644 --- a/src/main/frontend/components/editor.cljs +++ b/src/main/frontend/components/editor.cljs @@ -38,7 +38,7 @@ [react-draggable] [rum.core :as rum])) -(defonce no-matched-coomands [["No matched commands" [[:editor/move-cursor-to-end]]]]) +(defonce no-matched-commands [["No matched commands" [[:editor/move-cursor-to-end]]]]) (defn filter-commands [page? commands] @@ -58,7 +58,7 @@ _ (when (state/get-editor-action) (reset! *matched matched')) page? (db/page? (db/entity (:db/id (state/get-edit-block)))) - matched (or (filter-commands page? @*matched) no-matched-coomands) + matched (or (filter-commands page? @*matched) no-matched-commands) filtered? (not= matched @commands/*initial-commands)] (ui/auto-complete matched diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index b1542c1bf2..8f17022f35 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -3212,7 +3212,7 @@ matched-commands (get-matched-commands command)] (if (seq matched-commands) (commands/set-matched-commands! command matched-commands) - (if (> (- (count command) (count @commands/*latest-matched-command)) 1) + (if (> (- (count command) (count @commands/*latest-matched-command)) 2) (state/clear-editor-action!) (reset! commands/*matched-commands nil))))) diff --git a/src/test/frontend/handler/editor_test.cljs b/src/test/frontend/handler/editor_test.cljs index f330141b51..885b8b71de 100644 --- a/src/test/frontend/handler/editor_test.cljs +++ b/src/test/frontend/handler/editor_test.cljs @@ -93,20 +93,26 @@ #js {:key (subs value (dec (count value)))} nil)))) -(deftest keyup-handler-test +(deftest ^:focus keyup-handler-test (testing "Command autocompletion" ;; default last matching command is "" (keyup-handler {:value "/z" :action :commands :commands []}) (is (= :commands (state/get-editor-action)) - "Completion stays open if no matches but differs by 1 character from last matching command") + "Completion stays open if no matches but differs from last success by <= 2 chars") (keyup-handler {:value "/zz" :action :commands :commands []}) + (is (= :commands (state/get-editor-action)) + "Completion stays open if no matches but differs from last success by <= 2 chars") + + (keyup-handler {:value "/zzz" + :action :commands + :commands []}) (is (= nil (state/get-editor-action)) - "Completion closed if there no matching commands") + "Completion closed if no matches and > 2 chars form last success") (keyup-handler {:value "/b" :action :commands