Skip to content

Commit

Permalink
fix: drawToken: use simple comparison instead of regex
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jan 7, 2021
1 parent fe56545 commit 1f4b9f1
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions lib/mixins/canvas-drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,30 +627,17 @@ const oneOrMoreWhiteSpaceRegexp = /\s+/
*/
function drawToken (context, text, color, x, y, charWidth, charHeight, ignoreWhitespacesInTokens) {
context.fillStyle = color

if (ignoreWhitespacesInTokens) {
const length = text.length * charWidth
context.fillRect(x, y, length, charHeight)

return x + length
} else {
let chars = 0
for (let j = 0, len = text.length; j < len; j++) {
const char = text[j]
if (char === ' ') {
if (chars > 0) {
context.fillRect(x - (chars * charWidth), y, chars * charWidth, charHeight)
}
chars = 0
} else {
chars++
}
x += charWidth
}
if (chars > 0) {
context.fillRect(x - (chars * charWidth), y, chars * charWidth, charHeight)
}
return x
context.font = `3px sans-serif`;
context.textAlign = 'start'
context.testBaseline = 'top'
const length = text.length * charWidth
context.fillText(text, x, y + charHeight, length)
return x + length
}
}

Expand Down

0 comments on commit 1f4b9f1

Please sign in to comment.