Skip to content

Commit

Permalink
fix: call getTextEditorElement only once in drawDecorations
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jan 2, 2021
1 parent 739a561 commit 94a3064
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions lib/mixins/canvas-drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ export default class CanvasDrawer extends Mixin {
*/
drawDecorations (screenRow, decorations, renderData, types) {
let decorationsToRender = []
const editorElement = this.minimap.getTextEditorElement()

renderData.context.clearRect(
0, renderData.yRow,
Expand All @@ -487,7 +488,7 @@ export default class CanvasDrawer extends Mixin {

if (decorationsToRender != null ? decorationsToRender.length : undefined) {
for (let i = 0, len = decorationsToRender.length; i < len; i++) {
types[decorationsToRender[i].properties.type].call(this, decorationsToRender[i], renderData)
types[decorationsToRender[i].properties.type].call(this, decorationsToRender[i], renderData, editorElement)
}
}
}
Expand All @@ -497,10 +498,11 @@ export default class CanvasDrawer extends Mixin {
*
* @param {Decoration} decoration the decoration to render
* @param {Object} data the data need to perform the render
* @param {TextEditorElement} editorElement
* @access private
*/
drawLineDecoration (decoration, data) {
data.context.fillStyle = this.getDecorationColor(decoration, this.minimap.getTextEditorElement())
drawLineDecoration (decoration, data, editorElement) {
data.context.fillStyle = this.getDecorationColor(decoration, editorElement)
data.context.fillRect(0, data.yRow, data.canvasWidth, data.lineHeight)
}

Expand All @@ -509,10 +511,11 @@ export default class CanvasDrawer extends Mixin {
*
* @param {Decoration} decoration the decoration to render
* @param {Object} data the data need to perform the render
* @param {TextEditorElement} editorElement
* @access private
*/
drawGutterDecoration (decoration, data) {
data.context.fillStyle = this.getDecorationColor(decoration, this.minimap.getTextEditorElement())
drawGutterDecoration (decoration, data, editorElement) {
data.context.fillStyle = this.getDecorationColor(decoration, editorElement)
data.context.fillRect(0, data.yRow, 1, data.lineHeight)
}

Expand All @@ -524,13 +527,14 @@ export default class CanvasDrawer extends Mixin {
*
* @param {Decoration} decoration the decoration to render
* @param {Object} data the data need to perform the render
* @param {TextEditorElement} editorElement
* @access private
*/
drawHighlightDecoration (decoration, data) {
drawHighlightDecoration (decoration, data, editorElement) {
const range = decoration.getMarker().getScreenRange()
const rowSpan = range.end.row - range.start.row

data.context.fillStyle = this.getDecorationColor(decoration, this.minimap.getTextEditorElement())
data.context.fillStyle = this.getDecorationColor(decoration, editorElement)

if (rowSpan === 0) {
const colSpan = range.end.column - range.start.column
Expand All @@ -553,17 +557,18 @@ export default class CanvasDrawer extends Mixin {
*
* @param {Decoration} decoration the decoration to render
* @param {Object} data the data need to perform the render
* @param {TextEditorElement} editorElement
* @access private
*/
drawHighlightOutlineDecoration (decoration, data) {
drawHighlightOutlineDecoration (decoration, data, editorElement) {
let bottomWidth, colSpan, width, xBottomStart, xEnd, xStart
const { lineHeight, charWidth, canvasWidth, screenRow } = data
const range = decoration.getMarker().getScreenRange()
const rowSpan = range.end.row - range.start.row
const yStart = data.yRow
const yEnd = yStart + lineHeight

data.context.fillStyle = this.getDecorationColor(decoration, this.minimap.getTextEditorElement())
data.context.fillStyle = this.getDecorationColor(decoration, editorElement)

if (rowSpan === 0) {
colSpan = range.end.column - range.start.column
Expand Down Expand Up @@ -633,14 +638,15 @@ export default class CanvasDrawer extends Mixin {
*
* @param {Decoration} decoration the decoration to render
* @param {Object} data the data need to perform the render
* @param {TextEditorElement} editorElement
* @access private
*/
drawCustomDecoration (decoration, data) {
drawCustomDecoration (decoration, data, editorElement) {
const renderRoutine = decoration.getProperties().render

if (renderRoutine) {
data.color = this.getDecorationColor(decoration, this.minimap.getTextEditorElement())
renderRoutine(decoration, data)
data.color = this.getDecorationColor(decoration, editorElement)
renderRoutine(decoration, data, editorElement)
}
}
}
Expand Down

0 comments on commit 94a3064

Please sign in to comment.