Skip to content

Commit

Permalink
Implement proper quick settings view life cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
abe33 committed Dec 18, 2014
1 parent 4f32ca7 commit 9af0bd1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
24 changes: 15 additions & 9 deletions lib/minimap-element.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,21 @@ class MinimapElement extends HTMLElement
@openQuickSettings.classList.add 'open-minimap-quick-settings'
@controls.appendChild(@openQuickSettings)
@openQuickSettings.addEventListener 'click', (e) =>
MinimapQuickSettingsView ?= require './minimap-quick-settings-view'

@quickSettingsView = new MinimapQuickSettingsView(this)
@quickSettingsView.attach()
{top, left} = @getBoundingClientRect()
@quickSettingsView.css({
top: top + 'px'
left: (left - @quickSettingsView.width()) + 'px'
})
if @quickSettingsView?
@quickSettingsView.destroy()
@quickSettingsSubscription.dispose()
else
MinimapQuickSettingsView ?= require './minimap-quick-settings-view'
@quickSettingsView = new MinimapQuickSettingsView(this)
@quickSettingsSubscription = @quickSettingsView.onDidDestroy =>
@quickSettingsView = null

@quickSettingsView.attach()
{top, left} = @getBoundingClientRect()
@quickSettingsView.css({
top: top + 'px'
left: (left - @quickSettingsView.width()) + 'px'
})

disposeOpenQuickSettings: ->
@controls.removeChild(@openQuickSettings)
Expand Down
29 changes: 28 additions & 1 deletion spec/minimap-element-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -461,13 +461,40 @@ describe 'MinimapElement', ->
it 'opens the quick settings view', ->
expect(quickSettingsView).toExist()

it 'position the quick settings view next to the minimap', ->
it 'positions the quick settings view next to the minimap', ->
minimapBounds = minimapElement.getBoundingClientRect()
settingsBounds = quickSettingsView.getBoundingClientRect()

expect(realOffsetTop(quickSettingsView)).toBeCloseTo(minimapBounds.top, 0)
expect(realOffsetLeft(quickSettingsView)).toBeCloseTo(minimapBounds.left - settingsBounds.width, 0)

describe 'when the quick settings view is open', ->
beforeEach ->
workspaceElement = atom.views.getView(atom.workspace)
jasmineContent.appendChild(workspaceElement)

openQuickSettings = minimapElement.shadowRoot.querySelector('.open-minimap-quick-settings')
click(openQuickSettings)

quickSettingsView = workspaceElement.querySelector('.minimap-quick-settings')

describe 'clicking on the open settings button again', ->
beforeEach ->
click(openQuickSettings)

it 'closes the quick settings view', ->
expect(workspaceElement.querySelector('.minimap-quick-settings')).not.toExist()

it 'removes the view from the element', ->
expect(minimapElement.quickSettingsView).toBeNull()

describe 'when an external event destroys the view', ->
beforeEach ->
minimapElement.quickSettingsView.destroy()

it 'removes the view reference from the element', ->
expect(minimapElement.quickSettingsView).toBeNull()

describe 'then disabling it', ->
beforeEach ->
atom.config.set 'minimap.displayPluginsControls', false
Expand Down

0 comments on commit 9af0bd1

Please sign in to comment.