Skip to content

Commit

Permalink
fix: make updateBackDecorationsLayer a free function
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jan 12, 2021
1 parent b2e238a commit 8ae5fa4
Showing 1 changed file with 56 additions and 53 deletions.
109 changes: 56 additions & 53 deletions lib/mixins/canvas-drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export default class CanvasDrawer extends Mixin {
backgroundDecorationDispatcher['background-custom'] = drawCustomDecorationLambda
frontDecorationDispatcher['foreground-custom'] = drawCustomDecorationLambda

this.updateBackDecorationsLayer(firstRow, lastRow, renderData, lineHeight, editorElement, decorations)
updateBackDecorationsLayer(this.backLayer, firstRow, lastRow, this.offscreenFirstRow, this.offscreenLastRow, this.pendingBackDecorationChanges, renderData, lineHeight, editorElement, decorations)

renderData.context = this.frontLayer.context

Expand All @@ -180,58 +180,6 @@ export default class CanvasDrawer extends Mixin {
this.offscreenLastRow = lastRow
}

/**
* Performs an update of the back decorations layer using the pending back
* decorations changes arrays.
*
* @param {number} firstRow firstRow the first row of the range to update
* @param {number} lastRow lastRow the last row of the range to update
*
* @param {Object} renderData
* @param {number} lineHeight this.minimap.getLineHeight() * devicePixelRatio
* @param {TextEditorElement} editorElement this.minimap.getTextEditorElement()
* @param {Array<Decoration>} decorations
* @access private
*/
updateBackDecorationsLayer (firstRow, lastRow, renderData, lineHeight, editorElement, decorations) {
const intactRanges = computeIntactRanges(firstRow, lastRow, this.pendingBackDecorationChanges, this.offscreenFirstRow, this.offscreenLastRow)

// NOTE: this method is the hot function of Minimap. Do not refactor. The code is inlined delibarately.

// redrawRangesOnLayer

this.backLayer.clearCanvas()

if (intactRanges.length === 0) {
drawBackDecorationsForLines(firstRow, lastRow, 0, renderData, lineHeight, editorElement, decorations)
} else {
for (let j = 0, len = intactRanges.length; j < len; j++) {
const intact = intactRanges[j]

this.backLayer.copyPartFromOffscreen(
intact.offscreenRow * lineHeight,
(intact.start - firstRow) * lineHeight,
(intact.end - intact.start) * lineHeight
)
}
// drawLinesForRanges
let currentRow = firstRow
for (let i = 0, len = intactRanges.length; i < len; i++) {
const range = intactRanges[i]

drawBackDecorationsForLines(currentRow, range.start, currentRow - firstRow, renderData, lineHeight, editorElement, decorations)

currentRow = range.end
}
if (currentRow <= lastRow) {
drawBackDecorationsForLines(currentRow, lastRow, currentRow - firstRow, renderData, lineHeight, editorElement, decorations)
}
}

this.backLayer.resetOffscreenSize()
this.backLayer.copyToOffscreen()
}

/**
* Performs an update of the front decorations layer using the pending front
* decorations changes arrays.
Expand Down Expand Up @@ -421,6 +369,61 @@ function updateTokensLayer (tokensLayer, firstRow, lastRow, offscreenFirstRow, o
tokensLayer.copyToOffscreen()
}

/**
* Performs an update of the back decorations layer using the pending back
* decorations changes arrays.
* @param {CanvasLayer} backLayer
* @param {number} firstRow firstRow the first row of the range to update
* @param {number} lastRow lastRow the last row of the range to update
*
* @param {number} offscreenFirstRow
* @param {number} offscreenLastRow
* @param {Array<>} pendingBackDecorationChanges
* @param {Object} renderData
* @param {number} lineHeight this.minimap.getLineHeight() * devicePixelRatio
* @param {TextEditorElement} editorElement this.minimap.getTextEditorElement()
* @param {Array<Decoration>} decorations
* @access private
*/
function updateBackDecorationsLayer (backLayer, firstRow, lastRow, offscreenFirstRow, offscreenLastRow, pendingBackDecorationChanges, renderData, lineHeight, editorElement, decorations) {
const intactRanges = computeIntactRanges(firstRow, lastRow, pendingBackDecorationChanges, offscreenFirstRow, offscreenLastRow)

// NOTE: this method is the hot function of Minimap. Do not refactor. The code is inlined delibarately.

// redrawRangesOnLayer

backLayer.clearCanvas()

if (intactRanges.length === 0) {
drawBackDecorationsForLines(firstRow, lastRow, 0, renderData, lineHeight, editorElement, decorations)
} else {
for (let j = 0, len = intactRanges.length; j < len; j++) {
const intact = intactRanges[j]

backLayer.copyPartFromOffscreen(
intact.offscreenRow * lineHeight,
(intact.start - firstRow) * lineHeight,
(intact.end - intact.start) * lineHeight
)
}
// drawLinesForRanges
let currentRow = firstRow
for (let i = 0, len = intactRanges.length; i < len; i++) {
const range = intactRanges[i]

drawBackDecorationsForLines(currentRow, range.start, currentRow - firstRow, renderData, lineHeight, editorElement, decorations)

currentRow = range.end
}
if (currentRow <= lastRow) {
drawBackDecorationsForLines(currentRow, lastRow, currentRow - firstRow, renderData, lineHeight, editorElement, decorations)
}
}

backLayer.resetOffscreenSize()
backLayer.copyToOffscreen()
}

const whitespaceTokenRegex = /^\s+$/
const oneOrMoreWhiteSpaceRegexp = /\s+/

Expand Down

0 comments on commit 8ae5fa4

Please sign in to comment.