From a56f7dc372a76f406a0efee67e84cc2b1a6fe1fe Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Fri, 29 Nov 2024 08:32:35 +0100 Subject: [PATCH] Fix another out-of-range issue in StreamLanguage FIX: Fix a crash in `StreamLanguage` when the input range is entirely before the editor viewport. Issue https://github.com/codemirror/dev/issues/1476 --- src/stream-parser.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/stream-parser.ts b/src/stream-parser.ts index 2770187..8a71f55 100644 --- a/src/stream-parser.ts +++ b/src/stream-parser.ts @@ -201,14 +201,15 @@ class Parse implements PartialParse { readonly ranges: readonly {from: number, to: number}[]) { this.to = ranges[ranges.length - 1].to let context = ParseContext.get(), from = ranges[0].from - let {state, tree} = findStartInFragments(lang, fragments, from, ranges[ranges.length - 1].to, context?.state) + let {state, tree} = findStartInFragments(lang, fragments, from, this.to, context?.state) this.state = state this.parsedPos = this.chunkStart = from + tree.length for (let i = 0; i < tree.children.length; i++) { this.chunks.push(tree.children[i] as Tree) this.chunkPos.push(tree.positions[i]) } - if (context && this.parsedPos < context.viewport.from - C.MaxDistanceBeforeViewport) { + if (context && this.parsedPos < context.viewport.from - C.MaxDistanceBeforeViewport && + ranges.some(r => r.from <= context!.viewport.from && r.to >= context!.viewport.from)) { this.state = this.lang.streamParser.startState(getIndentUnit(context.state)) context.skipUntilInView(this.parsedPos, context.viewport.from) this.parsedPos = context.viewport.from