浏览代码

fix: tag autocomplete

Tienson Qin 4 年之前
父节点
当前提交
91ce40242a

+ 3 - 0
src/main/frontend/commands.cljs

@@ -284,6 +284,9 @@
                                (string/ends-with? s "(")
                                (or (string/starts-with? last-pattern "((")
                                    (string/starts-with? last-pattern "[["))))))
+          space? (if (and space? (string/starts-with? last-pattern "#[["))
+                   false
+                   space?)
           prefix (if (string/blank? last-pattern)
                    (if space?
                      (util/concat-without-spaces prefix value)

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

@@ -77,7 +77,7 @@
           input (gdom/getElement id)]
       (when input
         (let [current-pos (:pos (util/get-caret-pos input))
-              edit-content (state/sub [:editor/content id])
+              edit-content (or (state/sub [:editor/content id]) "")
               edit-block (state/sub :editor/block)
               q (or
                  @editor-handler/*selected-text

+ 5 - 4
src/main/frontend/handler/editor.cljs

@@ -1734,7 +1734,7 @@
     (when-let [input (gdom/getElement id)]
       (let [current-pos (:pos (util/get-caret-pos input))
             pos (:editor/last-saved-cursor @state/state)
-            edit-content (state/sub [:editor/content id])]
+            edit-content (or (state/sub [:editor/content id]) "")]
         (or
          @*selected-text
          (util/safe-subs edit-content pos current-pos))))))
@@ -2392,9 +2392,10 @@
           value (gobj/get input "value")
           c (util/nth-safe value (dec current-pos))]
       (when-not (state/get-editor-show-input)
-        (when (and (= c " ")
-                   (not (state/get-editor-show-page-search?)))
-          (state/set-editor-show-page-search-hashtag! false))
+        (when (= c " ")
+          (when (or (= (util/nth-safe value (dec (dec current-pos))) "#")
+                    (not (state/get-editor-show-page-search?)))
+            (state/set-editor-show-page-search-hashtag! false)))
 
         (when (and @*show-commands (not= key-code 191)) ; not /
           (let [matched-commands (get-matched-commands input)]

+ 5 - 5
src/main/frontend/handler/page.cljs

@@ -453,16 +453,16 @@
     (if (state/sub :editor/show-page-search-hashtag?)
       (fn [chosen _click?]
         (state/set-editor-show-page-search! false)
-        (let [chosen (if (re-find #"\s+" chosen)
+        (let [wrapped? (= "[[" (util/safe-subs edit-content (- pos 2) pos))
+              chosen (if (and (re-find #"\s+" chosen) (not wrapped?))
                        (util/format "[[%s]]" chosen)
                        chosen)]
           (editor-handler/insert-command! id
-                                          (str "#" chosen)
+                                          (str "#" (when wrapped? "[[") chosen)
                                           format
                                           {:last-pattern (let [q (if @editor-handler/*selected-text "" q)]
-                                                           (if (and q (string/starts-with? q "#"))
-                                                             q
-                                                             (str "#" q)))})))
+                                                           (str "#" (when wrapped? "[[") q))
+                                           :forward-pos (if wrapped? 3 2)})))
       (fn [chosen _click?]
         (state/set-editor-show-page-search! false)
         (let [page-ref-text (get-page-ref-text chosen)]