« get me outta code hell

sugar: matchMultiline: fix start of line offsetting - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-01-06 10:42:26 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-01-06 12:50:31 -0400
commit78f37e7420efe6be6ea20c609363cee9a7b2af9f (patch)
tree6c56a646f46fde8ea6ebaed992250cb3994a5cb1 /src
parent6a4461498377cbd3097b49afb2011609950e9e7d (diff)
sugar: matchMultiline: fix start of line offsetting
Diffstat (limited to 'src')
-rw-r--r--src/util/sugar.js10
1 files changed, 6 insertions, 4 deletions
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) {