Skip to content

Commit aca84c0

Browse files
committed
fix: factor out dispatchers and lambda
1 parent caf596f commit aca84c0

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

lib/mixins/canvas-drawer.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ export default class CanvasDrawer extends Mixin {
144144
orders: Main.getPluginsOrder()
145145
}
146146

147+
const drawCustomDecorationLambda = (decoration, data, decorationColor) => drawCustomDecoration(decoration, data, decorationColor, editorElement)
148+
backgroundDecorationDispatcher['background-custom'] = drawCustomDecorationLambda
149+
frontDecorationDispatcher['foreground-custom'] = drawCustomDecorationLambda
150+
147151
this.updateBackDecorationsLayer(firstRow, lastRow, renderData, lineHeight, editorElement, decorations)
148152

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

488-
const drawCustomDecorationLambda = (decoration, data, decorationColor) => drawCustomDecoration(decoration, data, decorationColor, editorElement)
489-
backgroundDecorationDispatcher['background-custom'] = drawCustomDecorationLambda
490-
491492
for (let screenRow = firstRow; screenRow <= lastRow; screenRow++) {
492493
renderData.row = offsetRow + (screenRow - firstRow)
493494
renderData.yRow = renderData.row * lineHeight
@@ -519,9 +520,6 @@ export default class CanvasDrawer extends Mixin {
519520
drawFrontDecorationsForLines (firstRow, lastRow, offsetRow, renderData, lineHeight, editorElement, decorations) {
520521
if (firstRow > lastRow) { return }
521522

522-
const drawCustomDecorationLambda = (decoration, data, decorationColor) => drawCustomDecoration(decoration, data, decorationColor, editorElement)
523-
frontDecorationDispatcher['foreground-custom'] = drawCustomDecorationLambda
524-
525523
for (let screenRow = firstRow; screenRow <= lastRow; screenRow++) {
526524
renderData.row = offsetRow + (screenRow - firstRow)
527525
renderData.yRow = renderData.row * lineHeight
@@ -747,13 +745,21 @@ function getInvisibleRegExp (editor) {
747745
}
748746
}
749747

750-
// dispatchers for decoration drawing (custom decoration drawer added dynamically)
751-
748+
/**
749+
* dispatchers for decoration drawing (custom decoration drawer added dynamically)
750+
* @param {Object} backgroundDecorationDispatcher an object with the type to render as key and the
751+
* render method as value
752+
*/
752753
const backgroundDecorationDispatcher = {
753754
line: drawLineDecoration,
754755
'highlight-under': drawHighlightDecoration
755756
}
756757

758+
/**
759+
* dispatchers for decoration drawing (custom decoration drawer added dynamically)
760+
* @param {Object} frontDecorationDispatcher an object with the type to render as key and the
761+
* render method as value
762+
*/
757763
const frontDecorationDispatcher = {
758764
gutter: drawGutterDecoration,
759765
'highlight-over': drawHighlightDecoration,

0 commit comments

Comments
 (0)