From: Ardis Lu Date: Thu, 4 Apr 2024 05:43:28 +0000 (-0700) Subject: Skip lookahead if no closing parenthesis is found X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=66bd0f428fc4790725d8deeac8f7fde2937e58f6;p=event-hashes Skip lookahead if no closing parenthesis is found Fixes issue where an extra event is found while a user is typing an event, because substring(start, -1) captures the entire input and re-captures the first event in the input. --- diff --git a/index.html b/index.html index 210fb50..bdc7021 100644 --- a/index.html +++ b/index.html @@ -321,6 +321,9 @@ if ((line.match(/\(/g)?.length ?? 0) > (line.match(/\)/g)?.length ?? 0)) { const start = code.indexOf(line, position - originalLineLength - 1); const end = code.indexOf(')', start); + if (end === -1) { // No closing parenthesis found + continue; + } const lookaheadLine = code.substring(start, end + 1).replaceAll('\n', ''); try { const normalizedEvent = normalizeEvent(lookaheadLine, strict);