Skip to content

Commit

Permalink
🐛 Prevent canvas resize when minimap become invisible
Browse files Browse the repository at this point in the history
  • Loading branch information
abe33 committed Dec 17, 2014
1 parent cc22681 commit 43ebe7b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/minimap-element.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ class MinimapElement extends HTMLElement
else
@width = @clientWidth

return unless @isVisible()

if @width isnt @canvas.width or @height isnt @canvas.height
@canvas.width = @width * devicePixelRatio
@canvas.height = (@height + @minimap.getLineHeight()) * devicePixelRatio
Expand Down Expand Up @@ -178,7 +180,7 @@ class MinimapElement extends HTMLElement
@requestUpdate()

update: ->
return unless @attached
return unless @attached and @isVisible()

if @adjustToSoftWrap
@style.width = @width + 'px'
Expand Down Expand Up @@ -211,6 +213,8 @@ class MinimapElement extends HTMLElement

@updateCanvas()

isVisible: -> @offsetWidth > 0 or @offsetHeight > 0

transformElement: (el, transform) ->
el.style.transform = transform

Expand Down
13 changes: 12 additions & 1 deletion spec/minimap-element-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ realOffsetLeft = (o) ->
transform = new WebKitCSSMatrix window.getComputedStyle(o).transform
o.offsetLeft + transform.m41

describe 'MinimapElement', ->
fdescribe 'MinimapElement', ->
[editor, minimap, largeSample, mediumSample, smallSample, jasmineContent, editorElement, minimapElement] = []

beforeEach ->
Expand Down Expand Up @@ -220,6 +220,17 @@ describe 'MinimapElement', ->
expect(minimapElement.drawLines.calls[1].args[1]).toEqual(100)
expect(minimapElement.drawLines.calls[1].args[2]).toEqual(101)

ffdescribe 'when the editor visibility change', ->
it 'does not modify the size of the canvas', ->
canvasWidth = minimapElement.canvas.width
canvasHeight = minimapElement.canvas.height
editorElement.style.display = 'none'
advanceClock(150)
nextAnimationFrame()

expect(minimapElement.canvas.width).toEqual(canvasWidth)
expect(minimapElement.canvas.height).toEqual(canvasHeight)

# ###### ####### ## ## ######## #### ######
# ## ## ## ## ### ## ## ## ## ##
# ## ## ## #### ## ## ## ##
Expand Down

0 comments on commit 43ebe7b

Please sign in to comment.