Skip to content

Commit

Permalink
fix: factor out renderData from updateFrontDecorationsLayer
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jan 2, 2021
1 parent 3b3dec1 commit 5e94c91
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions lib/mixins/canvas-drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export default class CanvasDrawer extends Mixin {

const decorations = this.minimap.decorationsByTypeThenRows(firstRow, lastRow)

let renderData = {
const renderData = {
context: this.backLayer.context,
canvasWidth,
canvasHeight,
Expand All @@ -149,7 +149,10 @@ export default class CanvasDrawer extends Mixin {
}

this.updateBackDecorationsLayer(firstRow, lastRow, renderData, lineHeight, editorElement, decorations)
this.updateFrontDecorationsLayer(firstRow, lastRow, lineHeight, charHeight, charWidth, canvasWidth, canvasHeight, editorElement, decorations)

renderData.context = this.frontLayer.context

this.updateFrontDecorationsLayer(firstRow, lastRow, renderData, lineHeight, editorElement, decorations)

this.pendingChanges = []
this.pendingBackDecorationChanges = []
Expand Down Expand Up @@ -285,16 +288,13 @@ export default class CanvasDrawer extends Mixin {
* @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 {number} charHeight this.minimap.getCharHeight() * devicePixelRatio
* @param {number} charWidth this.minimap.getCharWidth() * devicePixelRatio
* @param {number} canvasWidth this.tokensLayer.getSize().width
* @param {number} canvasHeight this.tokensLayer.getSize().height
* @param {TextEditorElement} editorElement this.minimap.getTextEditorElement()
* @param {Array<Decoration>} decorations
* @access private
*/
updateFrontDecorationsLayer (firstRow, lastRow, lineHeight, charHeight, charWidth, canvasWidth, canvasHeight, editorElement, decorations) {
updateFrontDecorationsLayer (firstRow, lastRow, renderData, lineHeight, editorElement, decorations) {
const intactRanges = computeIntactRanges(firstRow, lastRow, this.pendingFrontDecorationChanges, this.offscreenFirstRow, this.offscreenLastRow)

// NOTE: this method is the hot function of Minimap. Do not refactor. The code is inlined delibarately.
Expand All @@ -304,7 +304,7 @@ export default class CanvasDrawer extends Mixin {
this.frontLayer.clearCanvas()

if (intactRanges.length === 0) {
this.drawFrontDecorationsForLines(firstRow, lastRow, 0, lineHeight, charHeight, charWidth, canvasWidth, canvasHeight, editorElement, decorations)
this.drawFrontDecorationsForLines(firstRow, lastRow, 0, renderData, lineHeight, editorElement, decorations)
} else {
for (let j = 0, len = intactRanges.length; j < len; j++) {
const intact = intactRanges[j]
Expand All @@ -320,12 +320,12 @@ export default class CanvasDrawer extends Mixin {
for (let i = 0, len = intactRanges.length; i < len; i++) {
const range = intactRanges[i]

this.drawFrontDecorationsForLines(currentRow, range.start, currentRow - firstRow, lineHeight, charHeight, charWidth, canvasWidth, canvasHeight, editorElement, decorations)
this.drawFrontDecorationsForLines(currentRow, range.start, currentRow - firstRow, renderData, lineHeight, editorElement, decorations)

currentRow = range.end
}
if (currentRow <= lastRow) {
this.drawFrontDecorationsForLines(currentRow, lastRow, currentRow - firstRow, lineHeight, charHeight, charWidth, canvasWidth, canvasHeight, editorElement, decorations)
this.drawFrontDecorationsForLines(currentRow, lastRow, currentRow - firstRow, renderData, lineHeight, editorElement, decorations)
}
}

Expand Down Expand Up @@ -514,16 +514,13 @@ export default class CanvasDrawer extends Mixin {
* @param {number} offsetRow the relative offset to apply to rows when
* rendering them
*
* @param {Object} renderData
* @param {number} lineHeight this.minimap.getLineHeight() * devicePixelRatio
* @param {number} charHeight this.minimap.getCharHeight() * devicePixelRatio
* @param {number} charWidth this.minimap.getCharWidth() * devicePixelRatio
* @param {number} canvasWidth this.tokensLayer.getSize().width
* @param {number} canvasHeight this.tokensLayer.getSize().height
* @param {TextEditorElement} editorElement this.minimap.getTextEditorElement()
* @param {Array<Decoration>} decorations
* @access private
*/
drawFrontDecorationsForLines (firstRow, lastRow, offsetRow, lineHeight, charHeight, charWidth, canvasWidth, canvasHeight, editorElement, decorations) {
drawFrontDecorationsForLines (firstRow, lastRow, offsetRow, renderData, lineHeight, editorElement, decorations) {
if (firstRow > lastRow) { return }

const drawCustomDecorationLambda = (decoration, data, decorationColor) => drawCustomDecoration(decoration, data, decorationColor, editorElement)
Expand Down

0 comments on commit 5e94c91

Please sign in to comment.