Skip to content

Commit

Permalink
fix: factor emptyLineRegexp and whiteSpaceRegexp out of the loop
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jan 3, 2021
1 parent 9359279 commit 8e704b0
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/mixins/canvas-drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ export default class CanvasDrawer extends Mixin {
if (properties.color) { return properties.color }

if (properties.scope) {
const scopeString = properties.scope.split(/\s+/)
const scopeString = properties.scope.split(whiteSpaceRegexp)
return this.DOMStylesReader.retrieveStyleFromDom(scopeString, 'background-color', editorElement, true)
} else {
return this.getDefaultColor(editorElement)
Expand Down Expand Up @@ -605,6 +605,9 @@ export default class CanvasDrawer extends Mixin {
// ## ## ## ## ## ## ## ## ##
// ######## ## ## ## ## ### ###

const emptyLineRegexp = /^\s+$/
const whiteSpaceRegexp = /\s+/

/**
* Draws a single token on the given context.
*
Expand Down Expand Up @@ -716,7 +719,7 @@ function drawLines (firstRow, lastRow, offsetRow, lineHeight, charHeight, charWi
}
if (x > canvasWidth) { return }

if (/^\s+$/.test(token.text)) {
if (emptyLineRegexp.test(token.text)) {
x += token.text.length * charWidth
} else {
x = drawToken(
Expand Down

0 comments on commit 8e704b0

Please sign in to comment.