Update findSuggestionMatch.ts

This commit is contained in:
Jon Noronha
2022-03-24 12:25:38 -07:00
committed by bdbch
parent 297461f4a0
commit b7c3b113dd

View File

@@ -31,12 +31,9 @@ export function findSuggestionMatch(config: Trigger): SuggestionMatch {
? new RegExp(`${prefix}${escapedChar}.*?(?=\\s${escapedChar}|$)`, 'gm')
: new RegExp(`${prefix}(?:^)?${escapedChar}[^\\s${escapedChar}]*`, 'gm')
const isTopLevelNode = $position.depth <= 0
const textFrom = isTopLevelNode
? 0
: $position.before()
const textTo = $position.pos
const text = $position.doc.textBetween(textFrom, textTo, '\0', '\0')
const text = $position.nodeBefore?.isText && $position.nodeBefore.text
if (!text) return null
const textFrom = $position.pos - text.length
const match = Array.from(text.matchAll(regexp)).pop()
if (!match || match.input === undefined || match.index === undefined) {
@@ -53,7 +50,7 @@ export function findSuggestionMatch(config: Trigger): SuggestionMatch {
}
// The absolute position of the match in the document
const from = match.index + $position.start()
const from = textFrom + match.index
let to = from + match[0].length
// Edge case handling; if spaces are allowed and we're directly in between