fix: tag autocomplete

pull/1872/head
Tienson Qin 2021-05-16 11:05:02 +08:00
parent ac5de8b087
commit 91ce40242a
4 changed files with 14 additions and 10 deletions

View File

@ -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)

View File

@ -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

View File

@ -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)]

View File

@ -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)]