Skip to content

Commit

Permalink
fix: move the consts out of updateTokensLayer
Browse files Browse the repository at this point in the history
So it can be shared by other update functions
  • Loading branch information
aminya committed Jan 2, 2021
1 parent 436f4b7 commit bffd277
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions lib/mixins/canvas-drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,19 @@ export default class CanvasDrawer extends Mixin {
const firstRow = this.minimap.getFirstVisibleScreenRow()
const lastRow = this.minimap.getLastVisibleScreenRow()

this.updateTokensLayer(firstRow, lastRow)
const devicePixelRatio = this.minimap.getDevicePixelRatio()
const lineHeight = this.minimap.getLineHeight() * devicePixelRatio
const charHeight = this.minimap.getCharHeight() * devicePixelRatio
const charWidth = this.minimap.getCharWidth() * devicePixelRatio
const canvasWidth = this.tokensLayer.getSize().width
const context = this.tokensLayer.context
const editor = this.minimap.getTextEditor()
const editorElement = this.minimap.getTextEditorElement()
const displayCodeHighlights = this.displayCodeHighlights
const ignoreWhitespacesInTokens = this.ignoreWhitespacesInTokens
const maxTokensInOneLine = this.maxTokensInOneLine

this.updateTokensLayer(firstRow, lastRow, lineHeight, charHeight, charWidth, canvasWidth, context, editor, editorElement, displayCodeHighlights, ignoreWhitespacesInTokens, maxTokensInOneLine)
this.updateBackDecorationsLayer(firstRow, lastRow)
this.updateFrontDecorationsLayer(firstRow, lastRow)

Expand All @@ -149,27 +161,26 @@ 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 {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 {CanvasRenderingContext2D} context this.tokensLayer.context
* @param {TextEditor} editor this.minimap.getTextEditor()
* @param {TextEditorElement} editorElement this.minimap.getTextEditorElement()
* @param {boolean} displayCodeHighlights this.displayCodeHighlights
* @param {boolean} ignoreWhitespacesInTokens this.ignoreWhitespacesInTokens
* @param {number} maxTokensInOneLine this.maxTokensInOneLine
* @access private
*/
updateTokensLayer (firstRow, lastRow) {
updateTokensLayer (firstRow, lastRow, lineHeight, charHeight, charWidth, canvasWidth, context, editor, editorElement, displayCodeHighlights, ignoreWhitespacesInTokens, maxTokensInOneLine) {
const intactRanges = computeIntactRanges(firstRow, lastRow, this.pendingChanges, this.offscreenFirstRow, this.offscreenLastRow)

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

// redrawRangesOnLayer inlined (this.redrawRangesOnLayer(this.tokensLayer, intactRanges, firstRow, lastRow, this.drawLines))

const devicePixelRatio = this.minimap.getDevicePixelRatio()
const lineHeight = this.minimap.getLineHeight() * devicePixelRatio
const charHeight = this.minimap.getCharHeight() * devicePixelRatio
const charWidth = this.minimap.getCharWidth() * devicePixelRatio
const canvasWidth = this.tokensLayer.getSize().width
const context = this.tokensLayer.context
const editor = this.minimap.getTextEditor()
const editorElement = this.minimap.getTextEditorElement()
const displayCodeHighlights = this.displayCodeHighlights
const ignoreWhitespacesInTokens = this.ignoreWhitespacesInTokens
const maxTokensInOneLine = this.maxTokensInOneLine

this.tokensLayer.clearCanvas()

if (intactRanges.length === 0) {
Expand Down

0 comments on commit bffd277

Please sign in to comment.