From f3b6856562918efa508505e99777117de2d5ae9b Mon Sep 17 00:00:00 2001 From: abe33 Date: Mon, 15 Dec 2014 15:00:51 +0100 Subject: [PATCH] Add support for visible area scroll in minimap element update --- lib/minimap-element.coffee | 2 ++ spec/minimap-element-spec.coffee | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/minimap-element.coffee b/lib/minimap-element.coffee index 09bc2d30..66bc719e 100644 --- a/lib/minimap-element.coffee +++ b/lib/minimap-element.coffee @@ -60,6 +60,8 @@ class MinimapElement extends HTMLElement update: -> @visibleArea.style.width = @clientWidth + 'px' @visibleArea.style.height = @minimap.getTextEditorHeight() + 'px' + @visibleArea.style.top = (@minimap.getTextEditorScrollTop() - @minimap.getMinimapScrollTop()) + 'px' + @visibleArea.style.left = (@minimap.getTextEditorScrollLeft()) + 'px' # ######## ## ######## ## ## ######## ## ## ######## # ## ## ## ### ### ## ### ## ## diff --git a/spec/minimap-element-spec.coffee b/spec/minimap-element-spec.coffee index b5c643e7..ab670f72 100644 --- a/spec/minimap-element-spec.coffee +++ b/spec/minimap-element-spec.coffee @@ -11,8 +11,6 @@ describe 'MinimapElement', -> [editor, minimap, largeSample, smallSample, jasmineContent, editorElement, minimapElement] = [] beforeEach -> - jasmineContent = document.body.querySelector('#jasmine-content') - atom.config.set 'minimap.charHeight', 4 atom.config.set 'minimap.charWidth', 2 atom.config.set 'minimap.interline', 1 @@ -48,6 +46,8 @@ describe 'MinimapElement', -> [nextAnimationFrame, canvas, visibleArea] = [] beforeEach -> + jasmineContent = document.body.querySelector('#jasmine-content') + spyOn(window, "setInterval").andCallFake window.fakeSetInterval spyOn(window, "clearInterval").andCallFake window.fakeClearInterval @@ -63,6 +63,14 @@ describe 'MinimapElement', -> styleNode = document.createElement('style') styleNode.textContent = """ #{stylesheet} + + atom-text-editor atom-text-editor-minimap, atom-text-editor::shadow atom-text-editor-minimap { + background: red; + } + + atom-text-editor atom-text-editor-minimap::shadow .minimap-visible-area, atom-text-editor::shadow atom-text-editor-minimap::shadow .minimap-visible-area { + background: green; + } """ jasmineContent.appendChild(styleNode) @@ -71,7 +79,10 @@ describe 'MinimapElement', -> canvas = minimapElement.shadowRoot.querySelector('canvas') editorElement.style.width = '200px' editorElement.style.height = '50px' + jasmineContent.appendChild(editorElement) + editor.setScrollTop(1000) + editor.setScrollLeft(200) minimapElement.attach() it 'takes the height of the editor', -> @@ -96,3 +107,8 @@ describe 'MinimapElement', -> it 'sets the visible area width and height', -> expect(visibleArea.offsetWidth).toEqual(minimapElement.clientWidth) expect(visibleArea.offsetHeight).toBeCloseTo(minimap.getTextEditorHeight(), 0) + + it 'sets the visible visible area offset', -> + + expect(visibleArea.offsetTop).toBeCloseTo(minimap.getTextEditorScrollTop() - minimap.getMinimapScrollTop(), 0) + expect(visibleArea.offsetLeft).toBeCloseTo(minimap.getTextEditorScrollLeft(), 0)