Skip to content

Commit 396019f

Browse files
committed
Merge adjacent tokens created by stream parsers
FIX: Join adjacent tokens of the same type into a single token in . See https://discuss.codemirror.net/t/streamparser-can-produce-excess-markup/8770
1 parent 308d5f4 commit 396019f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/stream-parser.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ class Parse<State> implements PartialParse {
278278
while (this.ranges[this.rangeIndex].to < this.parsedPos) this.rangeIndex++
279279
}
280280

281-
emitToken(id: number, from: number, to: number, size: number, offset: number) {
281+
emitToken(id: number, from: number, to: number, offset: number) {
282+
let size = 4
282283
if (this.ranges.length > 1) {
283284
offset = this.skipGapsTo(from, offset, 1)
284285
from += offset
@@ -287,7 +288,11 @@ class Parse<State> implements PartialParse {
287288
to += offset
288289
size += this.chunk.length - len0
289290
}
290-
this.chunk.push(id, from, to, size)
291+
let last = this.chunk.length - 4
292+
if (size == 4 && last >= 0 && this.chunk[last] == id && this.chunk[last + 2] == from)
293+
this.chunk[last + 2] = to
294+
else
295+
this.chunk.push(id, from, to, size)
291296
return offset
292297
}
293298

@@ -301,7 +306,7 @@ class Parse<State> implements PartialParse {
301306
let token = readToken(streamParser.token, stream, this.state)
302307
if (token)
303308
offset = this.emitToken(this.lang.tokenTable.resolve(token), this.parsedPos + stream.start,
304-
this.parsedPos + stream.pos, 4, offset)
309+
this.parsedPos + stream.pos, offset)
305310
if (stream.start > C.MaxLineLength) break
306311
}
307312
}

0 commit comments

Comments
 (0)