From 65e1a404e502e625a8f216c8b00a221160ec827c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Mon, 6 Sep 2021 22:33:16 +0200 Subject: [PATCH] refactoring --- packages/suggestion/src/findSuggestionMatch.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/suggestion/src/findSuggestionMatch.ts b/packages/suggestion/src/findSuggestionMatch.ts index fcbc2087..fe7be2b9 100644 --- a/packages/suggestion/src/findSuggestionMatch.ts +++ b/packages/suggestion/src/findSuggestionMatch.ts @@ -47,11 +47,12 @@ export function findSuggestionMatch(config: Trigger): SuggestionMatch { return null } - // JavaScript doesn't have lookbehinds; this hacks a check that first character is " " - // or the line beginning + // JavaScript doesn't have lookbehinds. This hacks a check that first character + // is a space or the start of the line const matchPrefix = match.input.slice(Math.max(0, match.index - 1), match.index) + const matchPrefixIsSpace = /^[\s\0]?$/.test(matchPrefix) - if (prefixSpace && !/^[\s\0]?$/.test(matchPrefix)) { + if (prefixSpace && !matchPrefixIsSpace) { return null }