fix: safe check string before inserting when autocomplete

also, enables two consecutive spaces to exit autocomplete
This commit is contained in:
Tienson Qin
2022-07-05 21:46:25 +08:00
parent 7172784504
commit 7b92360889
2 changed files with 12 additions and 7 deletions

View File

@@ -281,7 +281,6 @@
(p/let [_ (draw/create-draw-with-default-content path)]
(println "draw file created, " path))
text)) "Draw a graph with Excalidraw"]
["Embed HTML " (->inline "html")]
["Embed Video URL" [[:editor/input "{{video }}" {:last-pattern (state/get-editor-command-trigger)
@@ -372,12 +371,13 @@
(str prefix postfix))
new-pos (- (count prefix)
(or backward-pos 0))]
(state/set-block-content-and-last-pos! id new-value new-pos)
(cursor/move-cursor-to input
(if (and (or backward-pos forward-pos)
(not= end-pattern "]]"))
new-pos
(inc new-pos))))))
(when-not (string/blank? new-value)
(state/set-block-content-and-last-pos! id new-value new-pos)
(cursor/move-cursor-to input
(if (and (or backward-pos forward-pos)
(not= end-pattern "]]"))
new-pos
(inc new-pos)))))))
(defn simple-insert!
[id value

View File

@@ -2809,6 +2809,11 @@
(reset! commands/*angle-bracket-caret-pos (cursor/get-caret-pos input))
(reset! commands/*show-block-commands true))
;; Exit autocomplete if user inputs two consecutive spaces
(and @*show-commands
(= c (util/nth-safe value (dec (dec current-pos))) " "))
(reset! *show-commands false)
(and (= c " ")
(or (= (util/nth-safe value (dec (dec current-pos))) "#")
(not (state/get-editor-show-page-search?))