Skip to content

Commit

Permalink
Add ignore whitespaces in tokens setting
Browse files Browse the repository at this point in the history
Closes #465
  • Loading branch information
abe33 committed Apr 16, 2016
1 parent 5ac833e commit 68c9826
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
5 changes: 5 additions & 0 deletions lib/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}
6 changes: 6 additions & 0 deletions lib/minimap-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
},
Expand Down
35 changes: 21 additions & 14 deletions lib/mixins/canvas-drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down

0 comments on commit 68c9826

Please sign in to comment.