From 7909b5c72f01bc9c4be48530aa3e5286c1713224 Mon Sep 17 00:00:00 2001 From: fundon Date: Mon, 16 Feb 2015 00:37:47 +0800 Subject: [PATCH] Fix open-minimap-quick-settings and minimap-scroll-indicator's positin on HiDPI displays --- lib/minimap-element.coffee | 4 ++-- spec/minimap-element-spec.coffee | 15 ++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/minimap-element.coffee b/lib/minimap-element.coffee index 706bb1f8..ada74a4f 100644 --- a/lib/minimap-element.coffee +++ b/lib/minimap-element.coffee @@ -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 diff --git a/spec/minimap-element-spec.coffee b/spec/minimap-element-spec.coffee index e939031f..66ccb918 100644 --- a/spec/minimap-element-spec.coffee +++ b/spec/minimap-element-spec.coffee @@ -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 @@ -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() @@ -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 -> @@ -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() @@ -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()