Browse Source

command input tolerance threshold set to 2

Mega Yu 6 months ago
parent
commit
3a6888d48a

+ 2 - 2
src/main/frontend/components/editor.cljs

@@ -38,7 +38,7 @@
             [react-draggable]
             [react-draggable]
             [rum.core :as rum]))
             [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
 (defn filter-commands
   [page? commands]
   [page? commands]
@@ -58,7 +58,7 @@
         _ (when (state/get-editor-action)
         _ (when (state/get-editor-action)
             (reset! *matched matched'))
             (reset! *matched matched'))
         page? (db/page? (db/entity (:db/id (state/get-edit-block))))
         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)]
         filtered? (not= matched @commands/*initial-commands)]
     (ui/auto-complete
     (ui/auto-complete
      matched
      matched

+ 1 - 1
src/main/frontend/handler/editor.cljs

@@ -3212,7 +3212,7 @@
                   matched-commands (get-matched-commands command)]
                   matched-commands (get-matched-commands command)]
               (if (seq matched-commands)
               (if (seq matched-commands)
                 (commands/set-matched-commands! command 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!)
                   (state/clear-editor-action!)
                   (reset! commands/*matched-commands nil)))))
                   (reset! commands/*matched-commands nil)))))
 
 

+ 9 - 3
src/test/frontend/handler/editor_test.cljs

@@ -93,20 +93,26 @@
        #js {:key (subs value (dec (count value)))}
        #js {:key (subs value (dec (count value)))}
        nil))))
        nil))))
 
 
-(deftest keyup-handler-test
+(deftest ^:focus keyup-handler-test
   (testing "Command autocompletion"
   (testing "Command autocompletion"
     ;; default last matching command is ""
     ;; default last matching command is ""
     (keyup-handler {:value "/z"
     (keyup-handler {:value "/z"
                     :action :commands
                     :action :commands
                     :commands []})
                     :commands []})
     (is (= :commands (state/get-editor-action))
     (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"
     (keyup-handler {:value "/zz"
                     :action :commands
                     :action :commands
                     :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))
     (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"
     (keyup-handler {:value "/b"
                     :action :commands
                     :action :commands