Skip to content

Commit 8e704b0

Browse files
committed
fix: factor emptyLineRegexp and whiteSpaceRegexp out of the loop
1 parent 9359279 commit 8e704b0

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/mixins/canvas-drawer.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ export default class CanvasDrawer extends Mixin {
401401
if (properties.color) { return properties.color }
402402

403403
if (properties.scope) {
404-
const scopeString = properties.scope.split(/\s+/)
404+
const scopeString = properties.scope.split(whiteSpaceRegexp)
405405
return this.DOMStylesReader.retrieveStyleFromDom(scopeString, 'background-color', editorElement, true)
406406
} else {
407407
return this.getDefaultColor(editorElement)
@@ -605,6 +605,9 @@ export default class CanvasDrawer extends Mixin {
605605
// ## ## ## ## ## ## ## ## ##
606606
// ######## ## ## ## ## ### ###
607607

608+
const emptyLineRegexp = /^\s+$/
609+
const whiteSpaceRegexp = /\s+/
610+
608611
/**
609612
* Draws a single token on the given context.
610613
*
@@ -716,7 +719,7 @@ function drawLines (firstRow, lastRow, offsetRow, lineHeight, charHeight, charWi
716719
}
717720
if (x > canvasWidth) { return }
718721

719-
if (/^\s+$/.test(token.text)) {
722+
if (emptyLineRegexp.test(token.text)) {
720723
x += token.text.length * charWidth
721724
} else {
722725
x = drawToken(

0 commit comments

Comments
 (0)