Skip to content

Commit

Permalink
Implement minimap on left config support in minimap element
Browse files Browse the repository at this point in the history
  • Loading branch information
abe33 committed Dec 15, 2014
1 parent c7ab242 commit 15a586a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
33 changes: 31 additions & 2 deletions lib/minimap-element.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down
8 changes: 8 additions & 0 deletions spec/minimap-element-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 15a586a

Please sign in to comment.