Parcourir la source

Fix command and hashtag not triggering at start of a multi-line

Gabriel Horner il y a 3 ans
Parent
commit
32d23a7f44

+ 3 - 6
src/main/frontend/handler/editor.cljs

@@ -1825,9 +1825,7 @@
     ;; (not= (gobj/get native-e "inputType") "insertFromPaste")
     ;; (not= (gobj/get native-e "inputType") "insertFromPaste")
     (cond
     (cond
       (and (= last-input-char (state/get-editor-command-trigger))
       (and (= last-input-char (state/get-editor-command-trigger))
-           ;; By default, "/" is also used as namespace separator in Logseq.
-           (not (contains? #{:page-search-hashtag} (state/sub :editor/action)))
-           (or (= 1 pos) (start-of-new-word? input pos)))
+           (or (re-find #"(?m)^/" (str (.-value input))) (start-of-new-word? input pos)))
       (do
       (do
         (state/set-editor-action-data! {:pos (cursor/get-caret-pos input)})
         (state/set-editor-action-data! {:pos (cursor/get-caret-pos input)})
         (commands/reinit-matched-commands!)
         (commands/reinit-matched-commands!)
@@ -1860,8 +1858,8 @@
 
 
       ;; Open "Search page or New page" auto-complete
       ;; Open "Search page or New page" auto-complete
       (and (= last-input-char commands/hashtag)
       (and (= last-input-char commands/hashtag)
-           ;; Only trigger at beginning of line or before whitespace
-           (or (= 1 pos) (start-of-new-word? input pos)))
+           ;; Only trigger at beginning of a line or before whitespace
+           (or (re-find #"(?m)^#" (str (.-value input))) (start-of-new-word? input pos)))
       (do
       (do
         (state/set-editor-action-data! {:pos (cursor/get-caret-pos input)})
         (state/set-editor-action-data! {:pos (cursor/get-caret-pos input)})
         (state/set-editor-last-pos! pos)
         (state/set-editor-last-pos! pos)
@@ -2910,7 +2908,6 @@
           (if (= (state/get-editor-command-trigger) (second (re-find #"(\S+)\s+$" value)))
           (if (= (state/get-editor-command-trigger) (second (re-find #"(\S+)\s+$" value)))
             (state/clear-editor-action!)
             (state/clear-editor-action!)
             (let [matched-commands (get-matched-commands input)]
             (let [matched-commands (get-matched-commands input)]
-              (prn :KEYUP {:k k :input input :value (gobj/get input "value")})
               (if (seq matched-commands)
               (if (seq matched-commands)
                 (reset! commands/*matched-commands matched-commands)
                 (reset! commands/*matched-commands matched-commands)
                 (state/clear-editor-action!))))
                 (state/clear-editor-action!))))

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

@@ -83,7 +83,7 @@
        #js {:key (subs value (dec (count value)))}
        #js {:key (subs value (dec (count value)))}
        nil))))
        nil))))
 
 
-(deftest ^:focus keyup-handler-test
+(deftest keyup-handler-test
   (testing "Command completion"
   (testing "Command completion"
     (keyup-handler {:value "/b"
     (keyup-handler {:value "/b"
                     :action :commands
                     :action :commands
@@ -148,14 +148,17 @@
     (is (= :commands (state/get-editor-action))
     (is (= :commands (state/get-editor-action))
         "Command search on start of new word")
         "Command search on start of new word")
 
 
+    (handle-last-input-handler {:value "a line\n/"})
+    (is (= :commands (state/get-editor-action))
+        "Command search on start of a new line")
+
     (handle-last-input-handler {:value "https://"})
     (handle-last-input-handler {:value "https://"})
     (is (= nil (state/get-editor-action))
     (is (= nil (state/get-editor-action))
         "No command search in middle of a word")
         "No command search in middle of a word")
 
 
     (handle-last-input-handler {:value "#blah/"})
     (handle-last-input-handler {:value "#blah/"})
     (is (= nil (state/get-editor-action))
     (is (= nil (state/get-editor-action))
-        "No command search after a tag search to allow for namespace completion")
-    )
+        "No command search after a tag search to allow for namespace completion"))
 
 
   (testing "Tag autocompletion"
   (testing "Tag autocompletion"
     (handle-last-input-handler {:value "#"
     (handle-last-input-handler {:value "#"