From 6b8da7fd72aa5a02d73ecf40e6b86d12a386c52f Mon Sep 17 00:00:00 2001 From: nsrCodes Date: Wed, 22 Jan 2025 22:03:50 +0530 Subject: [PATCH] feat: only work with the last match in case where the regular expression contains a global flag --- src/completion.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/completion.ts b/src/completion.ts index 978bf22..0d62a5e 100644 --- a/src/completion.ts +++ b/src/completion.ts @@ -123,7 +123,15 @@ export class CompletionContext { let line = this.state.doc.lineAt(this.pos) let start = Math.max(line.from, this.pos - 250) let str = line.text.slice(start - line.from, this.pos - line.from) - let found = str.search(ensureAnchor(expr, false)) + let found = -1 + if (expr.global) { + let match + /// Use the last match in case of a global expression. + while ((match = expr.exec(str)) !== null) found = match.index + } else { + found = str.search(ensureAnchor(expr, false)) + } + return found < 0 ? null : {from: start + found, to: this.pos, text: str.slice(found)} }