diff --git a/lib/minimap-element.coffee b/lib/minimap-element.coffee index fd0ee8d9..29bd6819 100644 --- a/lib/minimap-element.coffee +++ b/lib/minimap-element.coffee @@ -1,3 +1,4 @@ +{debounce} = require 'underscore-plus' {CompositeDisposable} = require 'event-kit' DOMStylesReader = require './mixins/dom-styles-reader' CanvasDrawer = require './mixins/canvas-drawer' @@ -6,6 +7,10 @@ class MinimapElement extends HTMLElement DOMStylesReader.includeInto(this) CanvasDrawer.includeInto(this) + domPollingInterval: 100 + domPollingIntervalId: null + domPollingPaused: false + createdCallback: -> @subscriptions = new CompositeDisposable @initializeContent() @@ -14,6 +19,7 @@ class MinimapElement extends HTMLElement @getTextEditorElementRoot().appendChild(this) attachedCallback: -> + @domPollingIntervalId = setInterval((=> @pollDOM()), @domPollingInterval) @measureHeightAndWidth() @requestUpdate() @@ -40,6 +46,23 @@ class MinimapElement extends HTMLElement @visibleArea.classList.add('minimap-visible-area') @shadowRoot.appendChild(@visibleArea) + pauseDOMPolling: -> + @domPollingPaused = true + @resumeDOMPollingAfterDelay ?= debounce(@resumeDOMPolling, 100) + @resumeDOMPollingAfterDelay() + + resumeDOMPolling: -> + @domPollingPaused = false + + resumeDOMPollingAfterDelay: null + + pollDOM: -> + return if @domPollingPaused or @updateRequested + + if @width isnt @clientWidth or @height isnt @clientHeight + @measureHeightAndWidth() + @requestUpdate() + measureHeightAndWidth: -> @width = @clientWidth @height = @clientHeight diff --git a/spec/minimap-element-spec.coffee b/spec/minimap-element-spec.coffee index 59b3ee1b..24323062 100644 --- a/spec/minimap-element-spec.coffee +++ b/spec/minimap-element-spec.coffee @@ -128,3 +128,22 @@ describe 'MinimapElement', -> it 'updates the visible area', -> expect(visibleArea.offsetTop).toBeCloseTo(minimap.getTextEditorScrollTop() - minimap.getMinimapScrollTop(), 0) expect(visibleArea.offsetLeft).toBeCloseTo(minimap.getTextEditorScrollLeft(), 0) + + describe 'when the editor is resized to a greater size', -> + beforeEach -> + height = editor.getHeight() + editorElement.style.width = '300px' + editorElement.style.height = '300px' + + waitsFor -> editor.getHeight() isnt height + + runs -> + advanceClock(150) + nextAnimationFrame() + + it 'detect the resize and adjust itself', -> + expect(minimapElement.offsetWidth).toBeCloseTo(editorElement.offsetWidth / 11, 0) + expect(minimapElement.offsetHeight).toEqual(editorElement.offsetHeight) + + expect(canvas.offsetWidth).toEqual(minimapElement.offsetWidth) + expect(canvas.offsetHeight).toEqual(minimapElement.offsetHeight + minimap.getLineHeight())