From 15a586a0cbb99ab70630820ad75084572cffb4ce Mon Sep 17 00:00:00 2001 From: abe33 Date: Tue, 16 Dec 2014 00:49:45 +0100 Subject: [PATCH] Implement minimap on left config support in minimap element --- lib/minimap-element.coffee | 33 ++++++++++++++++++++++++++++++-- spec/minimap-element-spec.coffee | 8 ++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/lib/minimap-element.coffee b/lib/minimap-element.coffee index 29bd6819..5b237c1c 100644 --- a/lib/minimap-element.coffee +++ b/lib/minimap-element.coffee @@ -10,23 +10,52 @@ class MinimapElement extends HTMLElement domPollingInterval: 100 domPollingIntervalId: null domPollingPaused: false + displayMinimapOnLeft: false createdCallback: -> @subscriptions = new CompositeDisposable @initializeContent() - attach: -> - @getTextEditorElementRoot().appendChild(this) + @subscriptions.add atom.config.observe 'minimap.displayMinimapOnLeft', (displayMinimapOnLeft) => + swapPosition = @attached and displayMinimapOnLeft isnt @displayMinimapOnLeft + @displayMinimapOnLeft = displayMinimapOnLeft + + @swapMinimapPosition() if swapPosition attachedCallback: -> @domPollingIntervalId = setInterval((=> @pollDOM()), @domPollingInterval) @measureHeightAndWidth() @requestUpdate() + @attached = true detachedCallback: -> + @attached = false attributeChangedCallback: (attrName, oldValue, newValue) -> + attach: -> + return if @attached + @swapMinimapPosition() + + swapMinimapPosition: -> + if @displayMinimapOnLeft + @attachToLeft() + else + @attachToRight() + + attachToLeft: -> + root = @getTextEditorElementRoot() + root.insertBefore(this, root.children[0]) + + attachToRight: -> + @getTextEditorElementRoot().appendChild(this) + + detach: -> + return unless @attached + return unless @parentNode? + + @parentNode.removeChild(this) + getModel: -> @minimap setModel: (@minimap) -> diff --git a/spec/minimap-element-spec.coffee b/spec/minimap-element-spec.coffee index eae93f3a..b3298fc3 100644 --- a/spec/minimap-element-spec.coffee +++ b/spec/minimap-element-spec.coffee @@ -147,3 +147,11 @@ describe 'MinimapElement', -> expect(canvas.offsetWidth).toEqual(minimapElement.offsetWidth) expect(canvas.offsetHeight).toEqual(minimapElement.offsetHeight + minimap.getLineHeight()) + + describe 'when displayMinimapOnLeft setting is true', -> + beforeEach -> + atom.config.set 'minimap.displayMinimapOnLeft', true + + it 'moves the attached to the left', -> + expect(Array::indexOf.call(editorElement.shadowRoot.children, minimapElement)).toEqual(0) + nextAnimationFrame()