@@ -18,6 +18,8 @@ class Context {
1818 this . doc = doc
1919 this . line = line
2020 this . maxLookAhead = lookAhead || 0
21+ this . baseTokens = null
22+ this . baseTokenPos = 1
2123 }
2224
2325 lookAhead ( n ) {
@@ -26,6 +28,15 @@ class Context {
2628 return line
2729 }
2830
31+ baseToken ( n ) {
32+ if ( ! this . baseTokens ) return null
33+ while ( this . baseTokens [ this . baseTokenPos ] >= n )
34+ this . baseTokenPos += 2
35+ let type = this . baseTokens [ this . baseTokenPos + 1 ]
36+ return { type : type && type . replace ( / ( | ^ ) o v e r l a y .* / , "" ) ,
37+ size : this . baseTokens [ this . baseTokenPos ] - n }
38+ }
39+
2940 nextLine ( ) {
3041 this . line ++
3142 if ( this . maxLookAhead > 0 ) this . maxLookAhead --
@@ -60,6 +71,7 @@ export function highlightLine(cm, line, context, forceToEnd) {
6071
6172 // Run overlays, adjust style array.
6273 for ( let o = 0 ; o < cm . state . overlays . length ; ++ o ) {
74+ context . baseTokens = st
6375 let overlay = cm . state . overlays [ o ] , i = 1 , at = 0
6476 context . state = true
6577 runMode ( cm , line . text , overlay . mode , context , ( end , style ) => {
@@ -83,8 +95,10 @@ export function highlightLine(cm, line, context, forceToEnd) {
8395 }
8496 }
8597 } , lineClasses )
98+ context . state = state
99+ context . baseTokens = null
100+ context . baseTokenPos = 1
86101 }
87- context . state = state
88102
89103 return { styles : st , classes : lineClasses . bgClass || lineClasses . textClass ? lineClasses : null }
90104}
0 commit comments