From 0d9e48883641d1c4aeeb9c9aa941e2e6419b2e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Tue, 18 May 2021 19:25:20 +0200 Subject: [PATCH] fix: add support for using suggestions at top level, fix #1340 --- packages/suggestion/src/findSuggestionMatch.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/suggestion/src/findSuggestionMatch.ts b/packages/suggestion/src/findSuggestionMatch.ts index 717a2eef..d5a3a6de 100644 --- a/packages/suggestion/src/findSuggestionMatch.ts +++ b/packages/suggestion/src/findSuggestionMatch.ts @@ -22,11 +22,6 @@ export function findSuggestionMatch(config: Trigger): SuggestionMatch { $position, } = config - // cancel if top level node - if ($position.depth <= 0) { - return null - } - // Matching expressions used for later const escapedChar = `\\${char}` const suffix = new RegExp(`\\s${escapedChar}$`) @@ -35,7 +30,10 @@ export function findSuggestionMatch(config: Trigger): SuggestionMatch { ? new RegExp(`${prefix}${escapedChar}.*?(?=\\s${escapedChar}|$)`, 'gm') : new RegExp(`${prefix}(?:^)?${escapedChar}[^\\s${escapedChar}]*`, 'gm') - const textFrom = $position.before() + 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 match = Array.from(text.matchAll(regexp)).pop()