Skip to content

Commit

Permalink
fix: factor out dispatchers and lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jan 2, 2021
1 parent caf596f commit aca84c0
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lib/mixins/canvas-drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ export default class CanvasDrawer extends Mixin {
orders: Main.getPluginsOrder()
}

const drawCustomDecorationLambda = (decoration, data, decorationColor) => drawCustomDecoration(decoration, data, decorationColor, editorElement)
backgroundDecorationDispatcher['background-custom'] = drawCustomDecorationLambda
frontDecorationDispatcher['foreground-custom'] = drawCustomDecorationLambda

this.updateBackDecorationsLayer(firstRow, lastRow, renderData, lineHeight, editorElement, decorations)

renderData.context = this.frontLayer.context
Expand Down Expand Up @@ -485,9 +489,6 @@ export default class CanvasDrawer extends Mixin {
drawBackDecorationsForLines (firstRow, lastRow, offsetRow, renderData, lineHeight, editorElement, decorations) {
if (firstRow > lastRow) { return }

const drawCustomDecorationLambda = (decoration, data, decorationColor) => drawCustomDecoration(decoration, data, decorationColor, editorElement)
backgroundDecorationDispatcher['background-custom'] = drawCustomDecorationLambda

for (let screenRow = firstRow; screenRow <= lastRow; screenRow++) {
renderData.row = offsetRow + (screenRow - firstRow)
renderData.yRow = renderData.row * lineHeight
Expand Down Expand Up @@ -519,9 +520,6 @@ export default class CanvasDrawer extends Mixin {
drawFrontDecorationsForLines (firstRow, lastRow, offsetRow, renderData, lineHeight, editorElement, decorations) {
if (firstRow > lastRow) { return }

const drawCustomDecorationLambda = (decoration, data, decorationColor) => drawCustomDecoration(decoration, data, decorationColor, editorElement)
frontDecorationDispatcher['foreground-custom'] = drawCustomDecorationLambda

for (let screenRow = firstRow; screenRow <= lastRow; screenRow++) {
renderData.row = offsetRow + (screenRow - firstRow)
renderData.yRow = renderData.row * lineHeight
Expand Down Expand Up @@ -747,13 +745,21 @@ function getInvisibleRegExp (editor) {
}
}

// dispatchers for decoration drawing (custom decoration drawer added dynamically)

/**
* dispatchers for decoration drawing (custom decoration drawer added dynamically)
* @param {Object} backgroundDecorationDispatcher an object with the type to render as key and the
* render method as value
*/
const backgroundDecorationDispatcher = {
line: drawLineDecoration,
'highlight-under': drawHighlightDecoration
}

/**
* dispatchers for decoration drawing (custom decoration drawer added dynamically)
* @param {Object} frontDecorationDispatcher an object with the type to render as key and the
* render method as value
*/
const frontDecorationDispatcher = {
gutter: drawGutterDecoration,
'highlight-over': drawHighlightDecoration,
Expand Down

0 comments on commit aca84c0

Please sign in to comment.