mirror of https://github.com/logseq/logseq
Fix command completion firing too often
Only fire at the beginning of a line or when starting a new wordpull/8598/head
parent
9d2055f8b9
commit
475d4ce7d9
|
@ -311,7 +311,7 @@
|
|||
block (merge block
|
||||
(block/parse-title-and-body uuid format pre-block? (:block/content block)))
|
||||
properties (:block/properties block)
|
||||
properties (if (and (= format :markdown)
|
||||
properties (if (and (= format :markdown)
|
||||
(number? (:heading properties)))
|
||||
(dissoc properties :heading)
|
||||
properties)
|
||||
|
@ -1810,6 +1810,10 @@
|
|||
(state/set-editor-op! nil)))
|
||||
500))))
|
||||
|
||||
(defn- start-of-new-word?
|
||||
[input pos]
|
||||
(contains? #{" " "\t"} (get (.-value input) (- pos 2))))
|
||||
|
||||
(defn handle-last-input []
|
||||
(let [input (state/get-input)
|
||||
pos (cursor/pos input)
|
||||
|
@ -1822,8 +1826,10 @@
|
|||
(cond
|
||||
;; By default, "/" is also used as namespace separator in Logseq.
|
||||
(and (= last-input-char (state/get-editor-command-trigger))
|
||||
(not (contains? #{:page-search-hashtag} (state/sub :editor/action))))
|
||||
#_(not (contains? #{:page-search-hashtag} (state/sub :editor/action)))
|
||||
(or (= 1 pos) (start-of-new-word? input pos)))
|
||||
(do
|
||||
(prn :NEW-WORD? (or (= 1 pos) (start-of-new-word? input pos)))
|
||||
(state/set-editor-action-data! {:pos (cursor/get-caret-pos input)})
|
||||
(commands/reinit-matched-commands!)
|
||||
(state/set-editor-show-commands!))
|
||||
|
@ -1856,7 +1862,7 @@
|
|||
;; Open "Search page or New page" auto-complete
|
||||
(and (= last-input-char commands/hashtag)
|
||||
;; Only trigger at beginning of line or before whitespace
|
||||
(or (= 1 pos) (contains? #{" " "\t"} (get (.-value input) (- pos 2)))))
|
||||
(or (= 1 pos) (start-of-new-word? input pos)))
|
||||
(do
|
||||
(state/set-editor-action-data! {:pos (cursor/get-caret-pos input)})
|
||||
(state/set-editor-last-pos! pos)
|
||||
|
|
|
@ -98,6 +98,24 @@
|
|||
(is (= nil (state/get-editor-action))
|
||||
"Don't autocomplete properties if typing in a block where properties already exist"))
|
||||
|
||||
(testing "Command autocompletion"
|
||||
(handle-last-input-handler {:value "/"})
|
||||
(is (= :commands (state/get-editor-action))
|
||||
"Command search if only / has been typed")
|
||||
|
||||
(handle-last-input-handler {:value "some words /"})
|
||||
(is (= :commands (state/get-editor-action))
|
||||
"Command search on start of new word")
|
||||
|
||||
(handle-last-input-handler {:value "https://"})
|
||||
(is (= nil (state/get-editor-action))
|
||||
"No command search in middle of a word")
|
||||
|
||||
(handle-last-input-handler {:value "#blah/"})
|
||||
(is (= nil (state/get-editor-action))
|
||||
"No command search after a tag search to allow for namespace completion")
|
||||
)
|
||||
|
||||
(testing "Tag autocompletion"
|
||||
(handle-last-input-handler {:value "#"
|
||||
:cursor-pos 1})
|
||||
|
|
Loading…
Reference in New Issue