Skip to content

Commit dacf546

Browse files
committed
fix: inline updateFrontDecorationsLayer
1 parent a05bca0 commit dacf546

File tree

1 file changed

+51
-11
lines changed

1 file changed

+51
-11
lines changed

lib/mixins/canvas-drawer.js

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export default class CanvasDrawer extends Mixin {
126126
const lineHeight = this.minimap.getLineHeight() * devicePixelRatio
127127
const charHeight = this.minimap.getCharHeight() * devicePixelRatio
128128
const charWidth = this.minimap.getCharWidth() * devicePixelRatio
129-
const canvasWidth = this.tokensLayer.getSize().width
129+
const { width: canvasWidth, height: canvasHeight } = this.tokensLayer.getSize()
130130
const context = this.tokensLayer.context
131131
const editor = this.minimap.getTextEditor()
132132
const editorElement = this.minimap.getTextEditorElement()
@@ -273,12 +273,52 @@ export default class CanvasDrawer extends Mixin {
273273
*
274274
* @param {number} firstRow firstRow the first row of the range to update
275275
* @param {number} lastRow lastRow the last row of the range to update
276+
*
277+
* @param {number} lineHeight this.minimap.getLineHeight() * devicePixelRatio
278+
* @param {number} charHeight this.minimap.getCharHeight() * devicePixelRatio
279+
* @param {number} charWidth this.minimap.getCharWidth() * devicePixelRatio
280+
* @param {number} canvasWidth this.tokensLayer.getSize().width
281+
* @param {number} canvasHeight this.tokensLayer.getSize().height
282+
* @param {TextEditorElement} editorElement this.minimap.getTextEditorElement()
276283
* @access private
277284
*/
278-
updateFrontDecorationsLayer (firstRow, lastRow) {
285+
updateFrontDecorationsLayer (firstRow, lastRow, lineHeight, charHeight, charWidth, canvasWidth, canvasHeight, editorElement) {
279286
const intactRanges = computeIntactRanges(firstRow, lastRow, this.pendingFrontDecorationChanges, this.offscreenFirstRow, this.offscreenLastRow)
280287

281-
this.redrawRangesOnLayer(this.frontLayer, intactRanges, firstRow, lastRow, this.drawFrontDecorationsForLines)
288+
// NOTE: this method is the hot function of Minimap. Do not refactor. The code is inlined delibarately.
289+
290+
// redrawRangesOnLayer inlined (this.frontLayer(this.frontLayer, intactRanges, firstRow, lastRow, this.drawFrontDecorationsForLines)
291+
292+
this.frontLayer.clearCanvas()
293+
294+
if (intactRanges.length === 0) {
295+
this.drawFrontDecorationsForLines(firstRow, lastRow, 0, lineHeight, charHeight, charWidth, canvasWidth, canvasHeight, editorElement)
296+
} else {
297+
for (let j = 0, len = intactRanges.length; j < len; j++) {
298+
const intact = intactRanges[j]
299+
300+
this.frontLayer.copyPartFromOffscreen(
301+
intact.offscreenRow * lineHeight,
302+
(intact.start - firstRow) * lineHeight,
303+
(intact.end - intact.start) * lineHeight
304+
)
305+
}
306+
// drawLinesForRanges inlined
307+
let currentRow = firstRow
308+
for (let i = 0, len = intactRanges.length; i < len; i++) {
309+
const range = intactRanges[i]
310+
311+
this.drawFrontDecorationsForLines(currentRow, range.start, currentRow - firstRow, lineHeight, charHeight, charWidth, canvasWidth, canvasHeight, editorElement)
312+
313+
currentRow = range.end
314+
}
315+
if (currentRow <= lastRow) {
316+
this.drawFrontDecorationsForLines(currentRow, lastRow, currentRow - firstRow, lineHeight, charHeight, charWidth, canvasWidth, canvasHeight, editorElement)
317+
}
318+
}
319+
320+
this.frontLayer.resetOffscreenSize()
321+
this.frontLayer.copyToOffscreen()
282322
}
283323

284324
// ###### ####### ## ####### ######## ######
@@ -472,17 +512,19 @@ export default class CanvasDrawer extends Mixin {
472512
* @param {number} lastRow the last row to render
473513
* @param {number} offsetRow the relative offset to apply to rows when
474514
* rendering them
515+
*
516+
* @param {number} lineHeight this.minimap.getLineHeight() * devicePixelRatio
517+
* @param {number} charHeight this.minimap.getCharHeight() * devicePixelRatio
518+
* @param {number} charWidth this.minimap.getCharWidth() * devicePixelRatio
519+
* @param {number} canvasWidth this.tokensLayer.getSize().width
520+
* @param {number} canvasHeight this.tokensLayer.getSize().height
521+
* @param {TextEditorElement} editorElement this.minimap.getTextEditorElement()
475522
* @access private
476523
*/
477-
drawFrontDecorationsForLines (firstRow, lastRow, offsetRow) {
524+
drawFrontDecorationsForLines (firstRow, lastRow, offsetRow, lineHeight, charHeight, charWidth, canvasWidth, canvasHeight, editorElement) {
478525
if (firstRow > lastRow) { return }
479526

480-
const devicePixelRatio = this.minimap.getDevicePixelRatio()
481-
const lineHeight = this.minimap.getLineHeight() * devicePixelRatio
482-
const charHeight = this.minimap.getCharHeight() * devicePixelRatio
483-
const charWidth = this.minimap.getCharWidth() * devicePixelRatio
484527
const decorations = this.minimap.decorationsByTypeThenRows(firstRow, lastRow)
485-
const { width: canvasWidth, height: canvasHeight } = this.tokensLayer.getSize()
486528
const renderData = {
487529
context: this.frontLayer.context,
488530
canvasWidth,
@@ -493,8 +535,6 @@ export default class CanvasDrawer extends Mixin {
493535
orders: Main.getPluginsOrder()
494536
}
495537

496-
const editorElement = this.minimap.getTextEditorElement()
497-
498538
const drawCustomDecorationLambda = (decoration, data, decorationColor) => drawCustomDecoration(decoration, data, decorationColor, editorElement)
499539
frontDecorationDispatcher['foreground-custom'] = drawCustomDecorationLambda
500540

0 commit comments

Comments
 (0)