From a59b8631f991c002f9a6690318251e997bf9b75b Mon Sep 17 00:00:00 2001 From: Lukasz Stafiniak Date: Fri, 24 Nov 2023 16:51:05 +0100 Subject: [PATCH] Bug fix: `findOuterBracketRaw` on small documents --- src/extension.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index bd84b18..8e0f672 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -446,10 +446,9 @@ function findOuterBracketRaw( let nesting = 0; let delta = direction[side]; let skippedChars = 0; - for ( - let offset = cursor - delta * Math.max(closingRawMaxLength || 0, openingRawMaxLength || 0); - 0 <= offset && offset <= lastOffset; offset += delta - ) { + let offset = cursor - delta * Math.max(closingRawMaxLength || 0, openingRawMaxLength || 0); + offset = Math.max(0, Math.min(offset, lastOffset)); + for (; 0 <= offset && offset <= lastOffset; offset += delta) { // Reset to the default delta. delta = direction[side]; const offsetPos = doc.positionAt(offset);