diff --git a/lib/config-schema.json b/lib/config-schema.json index 93fd004f..67870b89 100644 --- a/lib/config-schema.json +++ b/lib/config-schema.json @@ -97,5 +97,10 @@ "type":"boolean", "default":false, "description":"When enabled the text editor content will be able to flow below the minimap." + }, + "ignoreWhitespacesInTokens": { + "type":"boolean", + "default":false, + "description":"When enabled, text editor tokens are rendered as plain blocks, with no regards to the whitespaces they contains." } } diff --git a/lib/minimap-element.js b/lib/minimap-element.js index 6883e06c..099191ab 100644 --- a/lib/minimap-element.js +++ b/lib/minimap-element.js @@ -276,6 +276,12 @@ export default class MinimapElement { return this.classList.toggle('absolute', this.absoluteMode) }, + 'minimap.ignoreWhitespacesInTokens': (ignoreWhitespacesInTokens) => { + this.ignoreWhitespacesInTokens = ignoreWhitespacesInTokens + + this.requestForcedUpdate() + }, + 'editor.preferredLineLength': () => { if (this.attached) { this.measureHeightAndWidth() } }, diff --git a/lib/mixins/canvas-drawer.js b/lib/mixins/canvas-drawer.js index 1542d320..15d41ce8 100644 --- a/lib/mixins/canvas-drawer.js +++ b/lib/mixins/canvas-drawer.js @@ -497,23 +497,30 @@ export default class CanvasDrawer extends Mixin { drawToken (context, text, color, x, y, charWidth, charHeight) { context.fillStyle = color - let chars = 0 - for (let j = 0, len = text.length; j < len; j++) { - const char = text[j] - if (/\s/.test(char)) { - if (chars > 0) { - context.fillRect(x - (chars * charWidth), y, chars * charWidth, charHeight) + if (this.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 (/\s/.test(char)) { + if (chars > 0) { + context.fillRect(x - (chars * charWidth), y, chars * charWidth, charHeight) + } + chars = 0 + } else { + chars++ } - chars = 0 - } else { - chars++ + x += charWidth } - x += charWidth - } - if (chars > 0) { - context.fillRect(x - (chars * charWidth), y, chars * charWidth, charHeight) + if (chars > 0) { + context.fillRect(x - (chars * charWidth), y, chars * charWidth, charHeight) + } + return x } - return x } /**