diff --git a/lib/minimap-element.coffee b/lib/minimap-element.coffee index 6b7a58e5..d9addf49 100644 --- a/lib/minimap-element.coffee +++ b/lib/minimap-element.coffee @@ -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) diff --git a/spec/minimap-element-spec.coffee b/spec/minimap-element-spec.coffee index e85357bc..6cde7880 100644 --- a/spec/minimap-element-spec.coffee +++ b/spec/minimap-element-spec.coffee @@ -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