Skip to content

Commit

Permalink
Fix open-minimap-quick-settings and minimap-scroll-indicator's positi…
Browse files Browse the repository at this point in the history
…n on HiDPI displays
  • Loading branch information
fundon committed Feb 16, 2015
1 parent 14b32d0 commit 7909b5c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/minimap-element.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,12 @@ class MinimapElement extends HTMLElement
transform: @makeTranslate(visibleAreaLeft, visibleAreaTop)

@applyStyles @controls,
width: Math.min(@canvas.width, @width) + 'px'
width: Math.min(@canvas.width / devicePixelRatio, @width) + 'px'

canvasTop = @minimap.getFirstVisibleScreenRow() * @minimap.getLineHeight() - @minimap.getScrollTop()

canvasTransform = @makeTranslate(0, canvasTop)
canvasTransform += " " + @makeScale(1/devicePixelRatio) if devicePixelRatio isnt 1
canvasTransform += " " + @makeScale(1 / devicePixelRatio) if devicePixelRatio isnt 1
@applyStyles @canvas, transform: canvasTransform

if @minimapScrollIndicator and @minimap.canScroll() and not @scrollIndicator
Expand Down
15 changes: 8 additions & 7 deletions spec/minimap-element-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ realOffsetLeft = (o) ->
transform = new WebKitCSSMatrix window.getComputedStyle(o).transform
o.offsetLeft + transform.m41

devicePixelRatio = window.devicePixelRatio || 1
# Modify the global `devicePixelRatio` variable.
window.devicePixelRatio = 2

sleep = (duration) ->
t = new Date
Expand Down Expand Up @@ -127,8 +128,8 @@ describe 'MinimapElement', ->
expect(minimapElement.offsetWidth).toBeCloseTo(editorElement.clientWidth / 11, 0)

it 'resizes the canvas to fit the minimap', ->
expect(canvas.offsetHeight / devicePixelRatio).toEqual(minimapElement.offsetHeight + minimap.getLineHeight())
expect(canvas.offsetWidth / devicePixelRatio).toEqual(minimapElement.offsetWidth)
expect(canvas.offsetHeight / devicePixelRatio).toBeCloseTo(minimapElement.offsetHeight + minimap.getLineHeight(), 0)
expect(canvas.offsetWidth / devicePixelRatio).toBeCloseTo(minimapElement.offsetWidth, 0)

it 'requests an update', ->
expect(minimapElement.frameRequested).toBeTruthy()
Expand Down Expand Up @@ -210,8 +211,8 @@ describe 'MinimapElement', ->
expect(minimapElement.offsetWidth).toBeCloseTo(editorElement.offsetWidth / 11, 0)
expect(minimapElement.offsetHeight).toEqual(editorElement.offsetHeight)

expect(canvas.offsetWidth / devicePixelRatio).toEqual(minimapElement.offsetWidth)
expect(canvas.offsetHeight / devicePixelRatio).toEqual(minimapElement.offsetHeight + minimap.getLineHeight())
expect(canvas.offsetWidth / devicePixelRatio).toBeCloseTo(minimapElement.offsetWidth, 0)
expect(canvas.offsetHeight / devicePixelRatio).toBeCloseTo(minimapElement.offsetHeight + minimap.getLineHeight(), 0)

describe 'when the editor visible content is changed', ->
beforeEach ->
Expand Down Expand Up @@ -719,7 +720,7 @@ describe 'MinimapElement', ->
runs -> nextAnimationFrame()

it 'adjusts the size of the control div to fit in the minimap', ->
expect(controls.clientWidth).toEqual(minimapElement.canvas.clientWidth)
expect(controls.clientWidth).toEqual(minimapElement.canvas.clientWidth / devicePixelRatio)

it 'positions the controls div over the canvas', ->
controlsRect = controls.getBoundingClientRect()
Expand All @@ -733,7 +734,7 @@ describe 'MinimapElement', ->
nextAnimationFrame()

it 'adjusts the size of the control div to fit in the minimap', ->
expect(controls.clientWidth).toEqual(minimapElement.canvas.clientWidth)
expect(controls.clientWidth).toEqual(minimapElement.canvas.clientWidth / devicePixelRatio)

it 'positions the controls div over the canvas', ->
controlsRect = controls.getBoundingClientRect()
Expand Down

0 comments on commit 7909b5c

Please sign in to comment.