Skip to content

Commit bffd277

Browse files
committed
fix: move the consts out of updateTokensLayer
So it can be shared by other update functions
1 parent 436f4b7 commit bffd277

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

lib/mixins/canvas-drawer.js

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,19 @@ export default class CanvasDrawer extends Mixin {
122122
const firstRow = this.minimap.getFirstVisibleScreenRow()
123123
const lastRow = this.minimap.getLastVisibleScreenRow()
124124

125-
this.updateTokensLayer(firstRow, lastRow)
125+
const devicePixelRatio = this.minimap.getDevicePixelRatio()
126+
const lineHeight = this.minimap.getLineHeight() * devicePixelRatio
127+
const charHeight = this.minimap.getCharHeight() * devicePixelRatio
128+
const charWidth = this.minimap.getCharWidth() * devicePixelRatio
129+
const canvasWidth = this.tokensLayer.getSize().width
130+
const context = this.tokensLayer.context
131+
const editor = this.minimap.getTextEditor()
132+
const editorElement = this.minimap.getTextEditorElement()
133+
const displayCodeHighlights = this.displayCodeHighlights
134+
const ignoreWhitespacesInTokens = this.ignoreWhitespacesInTokens
135+
const maxTokensInOneLine = this.maxTokensInOneLine
136+
137+
this.updateTokensLayer(firstRow, lastRow, lineHeight, charHeight, charWidth, canvasWidth, context, editor, editorElement, displayCodeHighlights, ignoreWhitespacesInTokens, maxTokensInOneLine)
126138
this.updateBackDecorationsLayer(firstRow, lastRow)
127139
this.updateFrontDecorationsLayer(firstRow, lastRow)
128140

@@ -149,27 +161,26 @@ export default class CanvasDrawer extends Mixin {
149161
*
150162
* @param {number} firstRow firstRow the first row of the range to update
151163
* @param {number} lastRow lastRow the last row of the range to update
164+
165+
* @param {number} lineHeight this.minimap.getLineHeight() * devicePixelRatio
166+
* @param {number} charHeight this.minimap.getCharHeight() * devicePixelRatio
167+
* @param {number} charWidth this.minimap.getCharWidth() * devicePixelRatio
168+
* @param {number} canvasWidth this.tokensLayer.getSize().width
169+
* @param {CanvasRenderingContext2D} context this.tokensLayer.context
170+
* @param {TextEditor} editor this.minimap.getTextEditor()
171+
* @param {TextEditorElement} editorElement this.minimap.getTextEditorElement()
172+
* @param {boolean} displayCodeHighlights this.displayCodeHighlights
173+
* @param {boolean} ignoreWhitespacesInTokens this.ignoreWhitespacesInTokens
174+
* @param {number} maxTokensInOneLine this.maxTokensInOneLine
152175
* @access private
153176
*/
154-
updateTokensLayer (firstRow, lastRow) {
177+
updateTokensLayer (firstRow, lastRow, lineHeight, charHeight, charWidth, canvasWidth, context, editor, editorElement, displayCodeHighlights, ignoreWhitespacesInTokens, maxTokensInOneLine) {
155178
const intactRanges = computeIntactRanges(firstRow, lastRow, this.pendingChanges, this.offscreenFirstRow, this.offscreenLastRow)
156179

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

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

161-
const devicePixelRatio = this.minimap.getDevicePixelRatio()
162-
const lineHeight = this.minimap.getLineHeight() * devicePixelRatio
163-
const charHeight = this.minimap.getCharHeight() * devicePixelRatio
164-
const charWidth = this.minimap.getCharWidth() * devicePixelRatio
165-
const canvasWidth = this.tokensLayer.getSize().width
166-
const context = this.tokensLayer.context
167-
const editor = this.minimap.getTextEditor()
168-
const editorElement = this.minimap.getTextEditorElement()
169-
const displayCodeHighlights = this.displayCodeHighlights
170-
const ignoreWhitespacesInTokens = this.ignoreWhitespacesInTokens
171-
const maxTokensInOneLine = this.maxTokensInOneLine
172-
173184
this.tokensLayer.clearCanvas()
174185

175186
if (intactRanges.length === 0) {

0 commit comments

Comments
 (0)