mirror of
https://github.com/logseq/logseq.git
synced 2026-05-23 12:14:06 +00:00
command input tolerance threshold set to 2
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)))))
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user