From 78f37e7420efe6be6ea20c609363cee9a7b2af9f Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 6 Jan 2024 10:42:26 -0400 Subject: sugar: matchMultiline: fix start of line offsetting --- src/util/sugar.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/util') diff --git a/src/util/sugar.js b/src/util/sugar.js index 9435aecf..d4558653 100644 --- a/src/util/sugar.js +++ b/src/util/sugar.js @@ -280,16 +280,18 @@ export function* matchMultiline(content, matchRegexp, { let startOfLine = 0; let previousIndex = 0; - const countLineBreaks = range => { + const countLineBreaks = (offset, range) => { const lineBreaks = Array.from(range.matchAll(lineRegexp)); if (!empty(lineBreaks)) { lineNumber += lineBreaks.length; - startOfLine = lineBreaks.at(-1).index + 1; + startOfLine = offset + lineBreaks.at(-1).index + 1; } }; for (const match of content.matchAll(matchRegexp)) { - countLineBreaks(content.slice(previousIndex, match.index)); + countLineBreaks( + previousIndex, + content.slice(previousIndex, match.index)); const matchStartOfLine = startOfLine; @@ -306,7 +308,7 @@ export function* matchMultiline(content, matchRegexp, { : `pos: ${match.index}`)); } - countLineBreaks(match[0]); + countLineBreaks(match.index, match[0]); let containingLine = null; if (getContainingLine) { -- cgit 1.3.0-6-gf8a5