Skip to content

Commit

Permalink
🐛 Add guard against duplicated minimap
Browse files Browse the repository at this point in the history
Fixes #504
  • Loading branch information
abe33 committed Jul 5, 2016
1 parent 7d1fdbd commit d782ed6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/minimap-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,13 @@ export default class MinimapElement {
*/
attach (parent) {
if (this.attached) { return }
(parent || this.getTextEditorElementRoot()).appendChild(this)

const container = parent || this.getTextEditorElementRoot()
let minimaps = container.querySelectorAll('atom-text-editor-minimap')
if (minimaps.length) {
Array.prototype.forEach.call(minimaps, (el) => { el.destroy() })
}
container.appendChild(this)
}

/**
Expand Down
13 changes: 13 additions & 0 deletions spec/minimap-main-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ describe('Minimap package', () => {
it('removes the minimap from their editor parent', () => {
expect(editorElement.shadowRoot.querySelector('atom-text-editor-minimap')).not.toExist()
})

fdescribe('and reactivated with a remaining minimap in the DOM', () => {
beforeEach(() => {
const m = new Minimap({textEditor: editor})
const v = atom.views.getView(m)
editorElement.shadowRoot.appendChild(v)
waitsForPromise(() => atom.packages.activatePackage('minimap'))
})

it('removes the remaining minimap', () => {
expect(editorElement.shadowRoot.querySelectorAll('atom-text-editor-minimap').length).toEqual(1)
})
})
})
})

Expand Down

0 comments on commit d782ed6

Please sign in to comment.