From: Ardis Lu Date: Fri, 23 Feb 2024 05:27:41 +0000 (-0800) Subject: Fix issue where multi-line definitions with the same name but different types were... X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=6aa970645dce82153c6cbe2b959bab1c406727ad;p=event-hashes Fix issue where multi-line definitions with the same name but different types were dropped Occurs because .indexOf(line) returns the first instance of this line, but there may be multiple instances. Need to track the correct offset to begin the search. --- diff --git a/index.html b/index.html index e52a15b..f364fdd 100644 --- a/index.html +++ b/index.html @@ -260,8 +260,11 @@ function getEvents(code) { const events = new Set(); + let position = 0; let strict = false; for (let line of code.split('\n')) { + const originalLineLength = line.length; + position += originalLineLength; line = line.trim(); if (line === '') { continue; @@ -272,7 +275,7 @@ } // Basic lookahead for event definitions that span multiple lines if ((line.match(/\(/g)?.length ?? 0) > (line.match(/\)/g)?.length ?? 0)) { - const start = code.indexOf(line); + const start = code.indexOf(line, position - originalLineLength - 1); const end = code.indexOf(')', start); const lookaheadLine = code.substring(start, end + 1).replaceAll('\n', ''); try {