@@ -135,8 +135,8 @@ export default class CanvasDrawer extends Mixin {
135135 const maxTokensInOneLine = this . maxTokensInOneLine
136136
137137 this . updateTokensLayer ( firstRow , lastRow , lineHeight , charHeight , charWidth , canvasWidth , context , editor , editorElement , displayCodeHighlights , ignoreWhitespacesInTokens , maxTokensInOneLine )
138- this . updateBackDecorationsLayer ( firstRow , lastRow )
139- this . updateFrontDecorationsLayer ( firstRow , lastRow )
138+ this . updateBackDecorationsLayer ( firstRow , lastRow , lineHeight , charHeight , charWidth , canvasWidth , canvasHeight , editorElement )
139+ this . updateFrontDecorationsLayer ( firstRow , lastRow , lineHeight , charHeight , charWidth , canvasWidth , canvasHeight , editorElement )
140140
141141 this . pendingChanges = [ ]
142142 this . pendingBackDecorationChanges = [ ]
@@ -161,7 +161,7 @@ export default class CanvasDrawer extends Mixin {
161161 *
162162 * @param {number } firstRow firstRow the first row of the range to update
163163 * @param {number } lastRow lastRow the last row of the range to update
164-
164+ *
165165 * @param {number } lineHeight this.minimap.getLineHeight() * devicePixelRatio
166166 * @param {number } charHeight this.minimap.getCharHeight() * devicePixelRatio
167167 * @param {number } charWidth this.minimap.getCharWidth() * devicePixelRatio
@@ -219,12 +219,52 @@ export default class CanvasDrawer extends Mixin {
219219 *
220220 * @param {number } firstRow firstRow the first row of the range to update
221221 * @param {number } lastRow lastRow the last row of the range to update
222+ *
223+ * @param {number } lineHeight this.minimap.getLineHeight() * devicePixelRatio
224+ * @param {number } charHeight this.minimap.getCharHeight() * devicePixelRatio
225+ * @param {number } charWidth this.minimap.getCharWidth() * devicePixelRatio
226+ * @param {number } canvasWidth this.tokensLayer.getSize().width
227+ * @param {number } canvasHeight this.tokensLayer.getSize().height
228+ * @param {TextEditorElement } editorElement this.minimap.getTextEditorElement()
222229 * @access private
223230 */
224- updateBackDecorationsLayer ( firstRow , lastRow ) {
231+ updateBackDecorationsLayer ( firstRow , lastRow , lineHeight , charHeight , charWidth , canvasWidth , canvasHeight , editorElement ) {
225232 const intactRanges = computeIntactRanges ( firstRow , lastRow , this . pendingBackDecorationChanges , this . offscreenFirstRow , this . offscreenLastRow )
226233
227- this . redrawRangesOnLayer ( this . backLayer , intactRanges , firstRow , lastRow , this . drawBackDecorationsForLines )
234+ // NOTE: this method is the hot function of Minimap. Do not refactor. The code is inlined delibarately.
235+
236+ // redrawRangesOnLayer inlined (this.redrawRangesOnLayer(this.backLayer, intactRanges, firstRow, lastRow, this.drawBackDecorationsForLines)
237+
238+ this . backLayer . clearCanvas ( )
239+
240+ if ( intactRanges . length === 0 ) {
241+ this . drawBackDecorationsForLines ( firstRow , lastRow , 0 , lineHeight , charHeight , charWidth , canvasWidth , canvasHeight , editorElement )
242+ } else {
243+ for ( let j = 0 , len = intactRanges . length ; j < len ; j ++ ) {
244+ const intact = intactRanges [ j ]
245+
246+ this . backLayer . copyPartFromOffscreen (
247+ intact . offscreenRow * lineHeight ,
248+ ( intact . start - firstRow ) * lineHeight ,
249+ ( intact . end - intact . start ) * lineHeight
250+ )
251+ }
252+ // drawLinesForRanges inlined
253+ let currentRow = firstRow
254+ for ( let i = 0 , len = intactRanges . length ; i < len ; i ++ ) {
255+ const range = intactRanges [ i ]
256+
257+ this . drawBackDecorationsForLines ( currentRow , range . start , currentRow - firstRow , lineHeight , charHeight , charWidth , canvasWidth , canvasHeight , editorElement )
258+
259+ currentRow = range . end
260+ }
261+ if ( currentRow <= lastRow ) {
262+ this . drawBackDecorationsForLines ( currentRow , lastRow , currentRow - firstRow , lineHeight , charHeight , charWidth , canvasWidth , canvasHeight , editorElement )
263+ }
264+ }
265+
266+ this . backLayer . resetOffscreenSize ( )
267+ this . backLayer . copyToOffscreen ( )
228268 }
229269
230270 /**
@@ -385,17 +425,19 @@ export default class CanvasDrawer extends Mixin {
385425 * @param {number } lastRow the last row to render
386426 * @param {number } offsetRow the relative offset to apply to rows when
387427 * rendering them
428+ *
429+ * @param {number } lineHeight this.minimap.getLineHeight() * devicePixelRatio
430+ * @param {number } charHeight this.minimap.getCharHeight() * devicePixelRatio
431+ * @param {number } charWidth this.minimap.getCharWidth() * devicePixelRatio
432+ * @param {number } canvasWidth this.tokensLayer.getSize().width
433+ * @param {number } canvasHeight this.tokensLayer.getSize().height
434+ * @param {TextEditorElement } editorElement this.minimap.getTextEditorElement()
388435 * @access private
389436 */
390- drawBackDecorationsForLines ( firstRow , lastRow , offsetRow ) {
437+ drawBackDecorationsForLines ( firstRow , lastRow , offsetRow , lineHeight , charHeight , charWidth , canvasWidth , canvasHeight , editorElement ) {
391438 if ( firstRow > lastRow ) { return }
392439
393- const devicePixelRatio = this . minimap . getDevicePixelRatio ( )
394- const lineHeight = this . minimap . getLineHeight ( ) * devicePixelRatio
395- const charHeight = this . minimap . getCharHeight ( ) * devicePixelRatio
396- const charWidth = this . minimap . getCharWidth ( ) * devicePixelRatio
397440 const decorations = this . minimap . decorationsByTypeThenRows ( firstRow , lastRow )
398- const { width : canvasWidth , height : canvasHeight } = this . tokensLayer . getSize ( )
399441 const renderData = {
400442 context : this . backLayer . context ,
401443 canvasWidth,
@@ -405,7 +447,6 @@ export default class CanvasDrawer extends Mixin {
405447 charHeight,
406448 orders : Main . getPluginsOrder ( )
407449 }
408- const editorElement = this . minimap . getTextEditorElement ( )
409450
410451 const drawCustomDecorationLambda = ( decoration , data , decorationColor ) => drawCustomDecoration ( decoration , data , decorationColor , editorElement )
411452 backgroundDecorationDispatcher [ 'background-custom' ] = drawCustomDecorationLambda
0 commit comments