Skip to content

Commit

Permalink
fix: make drawCustomDecoration a free function
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jan 2, 2021
1 parent 2c768cb commit 4848aef
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions lib/mixins/canvas-drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ export default class CanvasDrawer extends Mixin {
}
const editorElement = this.minimap.getTextEditorElement()

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

for (let screenRow = firstRow; screenRow <= lastRow; screenRow++) {
renderData.row = offsetRow + (screenRow - firstRow)
renderData.yRow = renderData.row * lineHeight
Expand All @@ -348,7 +350,7 @@ export default class CanvasDrawer extends Mixin {
this.drawDecorations(screenRow, decorations, renderData, {
line: drawLineDecoration,
'highlight-under': drawHighlightDecoration,
'background-custom': this.drawCustomDecoration
'background-custom': drawCustomDecorationLambda
}, editorElement)
}

Expand Down Expand Up @@ -388,6 +390,8 @@ export default class CanvasDrawer extends Mixin {

const editorElement = this.minimap.getTextEditorElement()

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

for (let screenRow = firstRow; screenRow <= lastRow; screenRow++) {
renderData.row = offsetRow + (screenRow - firstRow)
renderData.yRow = renderData.row * lineHeight
Expand All @@ -397,7 +401,7 @@ export default class CanvasDrawer extends Mixin {
gutter: drawGutterDecoration,
'highlight-over': drawHighlightDecoration,
'highlight-outline': drawHighlightOutlineDecoration,
'foreground-custom': this.drawCustomDecoration
'foreground-custom': drawCustomDecorationLambda
}, editorElement)
}

Expand Down Expand Up @@ -501,25 +505,6 @@ export default class CanvasDrawer extends Mixin {
}
}

/**
* Draws a custom decoration.
*
* It renders only the part of the highlight corresponding to the specified
* row.
*
* @param {Decoration} decoration the decoration to render
* @param {Object} data the data need to perform the render
* @param {string} decorationColor decoration color
* @access private
*/
drawCustomDecoration (decoration, data, decorationColor) {
const renderRoutine = decoration.getProperties().render

if (renderRoutine) {
data.color = decorationColor
renderRoutine(decoration, data, /* editorElement */ this.minimap.getTextEditorElement()) // TODO editorElement is called every time
}
}
}

const SPEC_MODE = atom.inSpecMode()
Expand Down Expand Up @@ -771,6 +756,27 @@ function drawHighlightOutlineDecoration (decoration, data, decorationColor) {
}
}

/**
* Draws a custom decoration.
*
* It renders only the part of the highlight corresponding to the specified
* row.
*
* @param {Decoration} decoration the decoration to render
* @param {Object} data the data need to perform the render
* @param {string} decorationColor decoration color
* @param {TextEditorElement} editorElement
* @access private
*/
function drawCustomDecoration (decoration, data, decorationColor, editorElement) {
const renderRoutine = decoration.getProperties().render

if (renderRoutine) {
data.color = decorationColor
renderRoutine(decoration, data, editorElement)
}
}

// ###### ####### ## ####### ######## ######
// ## ## ## ## ## ## ## ## ## ## ##
// ## ## ## ## ## ## ## ## ##
Expand Down

0 comments on commit 4848aef

Please sign in to comment.