Преглед изворни кода

Tag menu should stay open for multiple tags

Fixes #6805 and #8175
Gabriel Horner пре 3 година
родитељ
комит
818e735d7c
2 измењених фајлова са 17 додато и 2 уклоњено
  1. 3 1
      src/main/frontend/handler/editor.cljs
  2. 14 1
      src/test/frontend/handler/editor_test.cljs

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

@@ -1772,7 +1772,9 @@
              (contains? #{:page-search :page-search-hashtag :block-search} (state/get-editor-action))
              (not (wrapped-by? input page-ref/left-brackets page-ref/right-brackets))
              (not (wrapped-by? input block-ref/left-parens block-ref/right-parens))
-             (not (wrapped-by? input "#" "")))
+             ;; wrapped-by? doesn't detect multiple beginnings when ending with "" so
+             ;; use subs to correctly detect current hashtag
+             (not (text-util/wrapped-by? (subs (.-value input) 0 (cursor/pos input)) (cursor/pos input) commands/hashtag "")))
     (state/clear-editor-action!)))
 
 (defn resize-image!

+ 14 - 1
src/test/frontend/handler/editor_test.cljs

@@ -78,13 +78,15 @@
   (let [pos (or cursor-pos (count value))
         input #js {:value value}]
     (with-redefs [editor/get-matched-commands (constantly commands)
+                  ;; Ignore as none of its behaviors are tested
+                  editor/default-case-for-keyup-handler (constantly nil)
                   cursor/pos (constantly pos)]
       ((editor/keyup-handler nil input nil)
        #js {:key (subs value (dec (count value)))}
        nil))))
 
 (deftest keyup-handler-test
-  (testing "Command completion"
+  (testing "Command autocompletion"
     (keyup-handler {:value "/b"
                     :action :commands
                     :commands [:fake-command]})
@@ -104,6 +106,17 @@
     (keyup-handler {:value "/block " :action :commands})
     (is (= :commands (state/get-editor-action))
         "Completion stays open if space is part of the search term for /"))
+
+  (testing "Tag autocompletion"
+    (keyup-handler {:value "foo #b" :action :page-search-hashtag})
+    (is (= :page-search-hashtag (state/get-editor-action))
+        "Completion stays open for one tag")
+
+    (keyup-handler {:value "text # #bar"
+                    :action :page-search-hashtag
+                    :cursor-pos 6})
+    (is (= :page-search-hashtag (state/get-editor-action))
+        "Completion stays open when typing tag before another tag"))
   ;; Reset state
   (state/set-editor-action! nil))