@@ -134,7 +134,7 @@ export default class CanvasDrawer extends Mixin {
134134 // TODO avoid closure: https://stackoverflow.com/a/46256398/7910299
135135 const getTokenColor = this . displayCodeHighlights ? ( t ) => this . getTokenColor ( t , editorElement ) : ( ) => this . getDefaultColor ( editorElement )
136136
137- this . updateTokensLayer ( firstRow , lastRow , lineHeight , charHeight , charWidth , canvasWidth , this . tokensLayer . context , editor , getTokenColor , this . ignoreWhitespacesInTokens , this . maxTokensInOneLine )
137+ this . updateTokensLayer ( firstRow , lastRow , lineHeight , charHeight , charWidth , canvasWidth , this . tokensLayer . context , editor , editor . getScreenLineCount ( ) , getInvisibleRegExp ( editor ) , getTokenColor , this . ignoreWhitespacesInTokens , this . maxTokensInOneLine )
138138
139139 const decorations = this . minimap . decorationsByTypeThenRows ( firstRow , lastRow )
140140
@@ -193,7 +193,7 @@ export default class CanvasDrawer extends Mixin {
193193 * @param {number } maxTokensInOneLine this.maxTokensInOneLine
194194 * @access private
195195 */
196- updateTokensLayer ( firstRow , lastRow , lineHeight , charHeight , charWidth , canvasWidth , context , editor , getTokenColor , ignoreWhitespacesInTokens , maxTokensInOneLine ) {
196+ updateTokensLayer ( firstRow , lastRow , lineHeight , charHeight , charWidth , canvasWidth , context , editor , editorScreenLineCount , invisibleRegExp , getTokenColor , ignoreWhitespacesInTokens , maxTokensInOneLine ) {
197197 const intactRanges = computeIntactRanges ( firstRow , lastRow , this . pendingChanges , this . offscreenFirstRow , this . offscreenLastRow )
198198
199199 // NOTE: this method is the hot function of Minimap. Do not refactor. The code is inlined delibarately.
@@ -208,7 +208,7 @@ export default class CanvasDrawer extends Mixin {
208208 }
209209
210210 if ( intactRanges . length === 0 ) {
211- drawLines ( firstRow , lastRow , 0 , lineHeight , charHeight , charWidth , canvasWidth , context , editor , getTokenColor , ignoreWhitespacesInTokens , maxTokensInOneLine )
211+ drawLines ( firstRow , lastRow , 0 , lineHeight , charHeight , charWidth , canvasWidth , context , editor , editorScreenLineCount , invisibleRegExp , getTokenColor , ignoreWhitespacesInTokens , maxTokensInOneLine )
212212 } else {
213213 for ( let j = 0 , len = intactRanges . length ; j < len ; j ++ ) {
214214 const intact = intactRanges [ j ]
@@ -224,12 +224,12 @@ export default class CanvasDrawer extends Mixin {
224224 for ( let i = 0 , len = intactRanges . length ; i < len ; i ++ ) {
225225 const range = intactRanges [ i ]
226226
227- drawLines ( currentRow , range . start , currentRow - firstRow , lineHeight , charHeight , charWidth , canvasWidth , context , editor , getTokenColor , ignoreWhitespacesInTokens , maxTokensInOneLine )
227+ drawLines ( currentRow , range . start , currentRow - firstRow , lineHeight , charHeight , charWidth , canvasWidth , context , editor , editorScreenLineCount , invisibleRegExp , getTokenColor , ignoreWhitespacesInTokens , maxTokensInOneLine )
228228
229229 currentRow = range . end
230230 }
231231 if ( currentRow <= lastRow ) {
232- drawLines ( currentRow , lastRow , currentRow - firstRow , lineHeight , charHeight , charWidth , canvasWidth , context , editor , getTokenColor , ignoreWhitespacesInTokens , maxTokensInOneLine )
232+ drawLines ( currentRow , lastRow , currentRow - firstRow , lineHeight , charHeight , charWidth , canvasWidth , context , editor , editorScreenLineCount , invisibleRegExp , getTokenColor , ignoreWhitespacesInTokens , maxTokensInOneLine )
233233 }
234234 }
235235
@@ -401,7 +401,7 @@ export default class CanvasDrawer extends Mixin {
401401 if ( properties . color ) { return properties . color }
402402
403403 if ( properties . scope ) {
404- const scopeString = properties . scope . split ( / \s + / )
404+ const scopeString = properties . scope . split ( whiteSpaceRegexp )
405405 return this . DOMStylesReader . retrieveStyleFromDom ( scopeString , 'background-color' , editorElement , true )
406406 } else {
407407 return this . getDefaultColor ( editorElement )
@@ -605,6 +605,9 @@ export default class CanvasDrawer extends Mixin {
605605// ## ## ## ## ## ## ## ## ##
606606// ######## ## ## ## ## ### ###
607607
608+ const emptyLineRegexp = / ^ \s + $ /
609+ const whiteSpaceRegexp = / \s + /
610+
608611/**
609612 * Draws a single token on the given context.
610613 *
@@ -654,13 +657,14 @@ function drawToken (context, text, color, x, y, charWidth, charHeight, ignoreWhi
654657 * @param {number } startRow The start row
655658 * @param {number } endRow The end row
656659 * @param {TextEditor } editor
660+ * @param {number } editorScreenLineCount
661+ * @param {RegExp } invisibleRegExp
657662 * @param {number } maxTokensInOneLine the maximum number of tokens to render in one line
658663 * @return {Array<Array> } An array of tokens by line
659664 * @access private
660665 */
661- function eachTokenForScreenRows ( startRow , endRow , editor , maxTokensInOneLine , callback ) {
662- const invisibleRegExp = getInvisibleRegExp ( editor )
663- endRow = Math . min ( endRow , editor . getScreenLineCount ( ) )
666+ function eachTokenForScreenRows ( startRow , endRow , editor , editorScreenLineCount , invisibleRegExp , maxTokensInOneLine , callback ) {
667+ endRow = Math . min ( endRow , editorScreenLineCount )
664668
665669 for ( let row = startRow ; row < endRow ; row ++ ) {
666670 const editorTokensForScreenRow = editor . tokensForScreenRow ( row )
@@ -692,19 +696,21 @@ function eachTokenForScreenRows (startRow, endRow, editor, maxTokensInOneLine, c
692696 * @param {number } canvasWidth this.tokensLayer.getSize().width
693697 * @param {CanvasRenderingContext2D } context this.tokensLayer.context
694698 * @param {TextEditor } editor this.minimap.getTextEditor()
699+ * @param {number } editorScreenLineCount
700+ * @param {RegExp } invisibleRegExp
695701 * @param {(t: Token) => string } getTokenColor
696702 * @param {boolean } ignoreWhitespacesInTokens this.ignoreWhitespacesInTokens
697703 * @param {number } maxTokensInOneLine this.maxTokensInOneLine
698704 * @access private
699705 */
700- function drawLines ( firstRow , lastRow , offsetRow , lineHeight , charHeight , charWidth , canvasWidth , context , editor , getTokenColor , ignoreWhitespacesInTokens , maxTokensInOneLine ) {
706+ function drawLines ( firstRow , lastRow , offsetRow , lineHeight , charHeight , charWidth , canvasWidth , context , editor , editorScreenLineCount , invisibleRegExp , getTokenColor , ignoreWhitespacesInTokens , maxTokensInOneLine ) {
701707 // NOTE: this method is the hot function of Minimap. Do not refactor. The code is inlined delibarately.
702708
703709 if ( firstRow > lastRow ) { return }
704710
705711 let lastLine , x
706712 let y = ( offsetRow * lineHeight ) - lineHeight
707- eachTokenForScreenRows ( firstRow , lastRow , editor , maxTokensInOneLine , ( line , token ) => {
713+ eachTokenForScreenRows ( firstRow , lastRow , editor , editorScreenLineCount , invisibleRegExp , maxTokensInOneLine , ( line , token ) => {
708714 if ( lastLine !== line ) {
709715 x = 0
710716 y += lineHeight
@@ -713,7 +719,7 @@ function drawLines (firstRow, lastRow, offsetRow, lineHeight, charHeight, charWi
713719 }
714720 if ( x > canvasWidth ) { return }
715721
716- if ( / ^ \s + $ / . test ( token . text ) ) {
722+ if ( emptyLineRegexp . test ( token . text ) ) {
717723 x += token . text . length * charWidth
718724 } else {
719725 x = drawToken (
0 commit comments