Skip to content

Commit

Permalink
fix: tag autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
tiensonqin committed May 16, 2021
1 parent ac5de8b commit 91ce402
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/main/frontend/commands.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/components/editor.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions src/main/frontend/handler/editor.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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))))))
Expand Down Expand Up @@ -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)]
Expand Down
10 changes: 5 additions & 5 deletions src/main/frontend/handler/page.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit 91ce402

Please sign in to comment.