Skip to content

Commit

Permalink
🐛 Fix unescaped invisibles regexp breaking render
Browse files Browse the repository at this point in the history
Fixes #308
  • Loading branch information
abe33 committed Apr 2, 2015
1 parent 6a7be03 commit 882ed5d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
24 changes: 16 additions & 8 deletions lib/mixins/canvas-drawer.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
_ = require 'underscore-plus'
Mixin = require 'mixto'

# Public: The {CanvasDrawer} mixin is responsible for the rendering of a
Expand Down Expand Up @@ -153,13 +154,7 @@ class CanvasDrawer extends Mixin

# Whitespaces can be substituted by other characters so we need
# to replace them when that's the case.
if line? and line.invisibles?
re = ///
#{line.invisibles.cr}|
#{line.invisibles.eol}|
#{line.invisibles.space}|
#{line.invisibles.tab}
///g
invisibleRegExp = @getInvisibleRegExp(line)

for line, row in lines
x = 0
Expand Down Expand Up @@ -188,7 +183,7 @@ class CanvasDrawer extends Mixin
@getDefaultColor()

value = token.value
value = value.replace(re, ' ') if re?
value = value.replace(invisibleRegExp, ' ') if invisibleRegExp?

x = @drawToken(context, value, color, x, y0, charWidth, charHeight)
else
Expand All @@ -210,6 +205,19 @@ class CanvasDrawer extends Mixin

context.fill()

# Internal: Returns the regexp to replace invisibles substitution characters
# in editor lines.
#
# line - The screen line for which replacing the invisibles characters.
getInvisibleRegExp: (line) ->
if line? and line.invisibles?
///
#{_.escapeRegExp line.invisibles.cr}|
#{_.escapeRegExp line.invisibles.eol}|
#{_.escapeRegExp line.invisibles.space}|
#{_.escapeRegExp line.invisibles.tab}
///g

# Internal: Draws a single token on the given context.
#
# context - The canvas context object onto which draw the token.
Expand Down
6 changes: 6 additions & 0 deletions spec/minimap-element-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ describe 'MinimapElement', ->

expect(realOffsetTop(canvas)).toBeCloseTo(-2, -1)

it 'does not fail to update render the invisible char when modified', ->
atom.config.set 'editor.showInvisibles', true
atom.config.set 'editor.invisibles', cr: '*'

expect(-> nextAnimationFrame()).not.toThrow()

it 'renders the visible line decorations', ->
spyOn(minimapElement, 'drawLineDecorations').andCallThrough()

Expand Down

0 comments on commit 882ed5d

Please sign in to comment.