diff --git a/lib/mixins/canvas-drawer.js b/lib/mixins/canvas-drawer.js index cd35a9f8..4afdc268 100644 --- a/lib/mixins/canvas-drawer.js +++ b/lib/mixins/canvas-drawer.js @@ -431,6 +431,7 @@ export default class CanvasDrawer extends Mixin { let tokens = [] let scopes = [] let textIndex = 0 + // console.log(lineText, invisibleRegExp, lineText.replace(invisibleRegExp, ' ')) for (let tagCode of tagCodes) { if (displayLayer.isOpenTagCode(tagCode)) { scopes.push(displayLayer.tagForCode(tagCode)) @@ -503,13 +504,15 @@ export default class CanvasDrawer extends Mixin { */ getInvisibleRegExp () { let invisibles = this.getTextEditor().getInvisibles() - let regexp = '' - if (invisibles.cr != null) { regexp += invisibles.cr + '|' } - if (invisibles.eol != null) { regexp += invisibles.eol + '|' } - if (invisibles.space != null) { regexp += invisibles.space + '|' } - if (invisibles.tab != null) { regexp += invisibles.tab + '|' } - - return new RegExp(_.escapeRegExp(regexp.slice(0, -1)), 'g') + let regexp = [] + if (invisibles.cr != null) { regexp.push(invisibles.cr) } + if (invisibles.eol != null) { regexp.push(invisibles.eol) } + if (invisibles.space != null) { regexp.push(invisibles.space) } + if (invisibles.tab != null) { regexp.push(invisibles.tab) } + + return RegExp(regexp.filter((s) => { + return typeof s === 'string' + }).map(_.escapeRegExp).join('|'), 'g') } /**