Skip to content

Commit a56f7dc

Browse files
committed
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 codemirror/dev#1476
1 parent 7f67688 commit a56f7dc

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/stream-parser.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,15 @@ class Parse<State> implements PartialParse {
201201
readonly ranges: readonly {from: number, to: number}[]) {
202202
this.to = ranges[ranges.length - 1].to
203203
let context = ParseContext.get(), from = ranges[0].from
204-
let {state, tree} = findStartInFragments(lang, fragments, from, ranges[ranges.length - 1].to, context?.state)
204+
let {state, tree} = findStartInFragments(lang, fragments, from, this.to, context?.state)
205205
this.state = state
206206
this.parsedPos = this.chunkStart = from + tree.length
207207
for (let i = 0; i < tree.children.length; i++) {
208208
this.chunks.push(tree.children[i] as Tree)
209209
this.chunkPos.push(tree.positions[i])
210210
}
211-
if (context && this.parsedPos < context.viewport.from - C.MaxDistanceBeforeViewport) {
211+
if (context && this.parsedPos < context.viewport.from - C.MaxDistanceBeforeViewport &&
212+
ranges.some(r => r.from <= context!.viewport.from && r.to >= context!.viewport.from)) {
212213
this.state = this.lang.streamParser.startState(getIndentUnit(context.state))
213214
context.skipUntilInView(this.parsedPos, context.viewport.from)
214215
this.parsedPos = context.viewport.from

0 commit comments

Comments
 (0)