From b7c3b113ddb10ab2dcca374e87f7c5d635a12e62 Mon Sep 17 00:00:00 2001 From: Jon Noronha Date: Thu, 24 Mar 2022 12:25:38 -0700 Subject: [PATCH] Update findSuggestionMatch.ts --- packages/suggestion/src/findSuggestionMatch.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/suggestion/src/findSuggestionMatch.ts b/packages/suggestion/src/findSuggestionMatch.ts index 17dd3894..888f4b6e 100644 --- a/packages/suggestion/src/findSuggestionMatch.ts +++ b/packages/suggestion/src/findSuggestionMatch.ts @@ -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