Skip to content

Commit

Permalink
fix: make drawHighlightDecoration a free function
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jan 2, 2021
1 parent cd4af73 commit 404393d
Showing 1 changed file with 32 additions and 33 deletions.
65 changes: 32 additions & 33 deletions lib/mixins/canvas-drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ export default class CanvasDrawer extends Mixin {

this.drawDecorations(screenRow, decorations, renderData, {
line: this.drawLineDecoration,
'highlight-under': this.drawHighlightDecoration,
'highlight-under': drawHighlightDecoration,
'background-custom': this.drawCustomDecoration
})
}
Expand Down Expand Up @@ -392,7 +392,7 @@ export default class CanvasDrawer extends Mixin {

this.drawDecorations(screenRow, decorations, renderData, {
gutter: this.drawGutterDecoration,
'highlight-over': this.drawHighlightDecoration,
'highlight-over': drawHighlightDecoration,
'highlight-outline': drawHighlightOutlineDecoration,
'foreground-custom': this.drawCustomDecoration
})
Expand Down Expand Up @@ -524,37 +524,6 @@ export default class CanvasDrawer extends Mixin {
data.context.fillRect(0, data.yRow, 1, data.lineHeight)
}

/**
* Draws a highlight 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
*/
drawHighlightDecoration (decoration, data, decorationColor) {
const range = decoration.getMarker().getScreenRange()
const rowSpan = range.end.row - range.start.row

data.context.fillStyle = decorationColor

if (rowSpan === 0) {
const colSpan = range.end.column - range.start.column
data.context.fillRect(range.start.column * data.charWidth, data.yRow, colSpan * data.charWidth, data.lineHeight)
} else if (data.screenRow === range.start.row) {
const x = range.start.column * data.charWidth
data.context.fillRect(x, data.yRow, data.canvasWidth - x, data.lineHeight)
} else if (data.screenRow === range.end.row) {
data.context.fillRect(0, data.yRow, range.end.column * data.charWidth, data.lineHeight)
} else {
data.context.fillRect(0, data.yRow, data.canvasWidth, data.lineHeight)
}
}


/**
* Draws a custom decoration.
*
Expand All @@ -579,6 +548,7 @@ export default class CanvasDrawer extends Mixin {
const SPEC_MODE = atom.inSpecMode()
if (SPEC_MODE) {
// class methods only used for spying the calls
CanvasDrawer.drawHighlightDecoration = drawHighlightDecoration
CanvasDrawer.drawHighlightOutlineDecoration = drawHighlightOutlineDecoration
}

Expand Down Expand Up @@ -685,6 +655,35 @@ function getInvisibleRegExp (editor) {
}
}

/**
* Draws a highlight 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
*/
function drawHighlightDecoration (decoration, data, decorationColor) {
const range = decoration.getMarker().getScreenRange()
const rowSpan = range.end.row - range.start.row

data.context.fillStyle = decorationColor

if (rowSpan === 0) {
const colSpan = range.end.column - range.start.column
data.context.fillRect(range.start.column * data.charWidth, data.yRow, colSpan * data.charWidth, data.lineHeight)
} else if (data.screenRow === range.start.row) {
const x = range.start.column * data.charWidth
data.context.fillRect(x, data.yRow, data.canvasWidth - x, data.lineHeight)
} else if (data.screenRow === range.end.row) {
data.context.fillRect(0, data.yRow, range.end.column * data.charWidth, data.lineHeight)
} else {
data.context.fillRect(0, data.yRow, data.canvasWidth, data.lineHeight)
}
}

/**
* Draws a highlight outline decoration.
Expand Down

0 comments on commit 404393d

Please sign in to comment.