command input tolerance threshold set to 2

This commit is contained in:
Mega Yu
2025-04-17 23:00:22 +08:00
parent 2f5625818c
commit 3a6888d48a
3 changed files with 12 additions and 6 deletions

View File

@@ -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

View File

@@ -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)))))

View File

@@ -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