diff --git a/lib/minimap.coffee b/lib/minimap.coffee index 5bf4a530..23eb3148 100644 --- a/lib/minimap.coffee +++ b/lib/minimap.coffee @@ -70,6 +70,7 @@ class Minimap # Destroys the model. destroy: -> @subscriptions.dispose() + @removeAllDecorations() @textEditor = null @emitter.emit 'did-destroy' @destroyed = true diff --git a/lib/mixins/decoration-management.coffee b/lib/mixins/decoration-management.coffee index c2ad40eb..a6dae9ff 100644 --- a/lib/mixins/decoration-management.coffee +++ b/lib/mixins/decoration-management.coffee @@ -105,6 +105,7 @@ class DecorationManagement extends Mixin # # Returns a `Decoration` object. decorateMarker: (marker, decorationParams) -> + return if @destroyed return unless marker? marker = @getMarker(marker.id) return unless marker? @@ -226,6 +227,21 @@ class DecorationManagement extends Mixin delete @decorationMarkerChangedSubscriptions[marker.id] delete @decorationMarkerDestroyedSubscriptions[marker.id] + removeAllDecorations: -> + sub.dispose() for id,sub of @decorationMarkerChangedSubscriptions + sub.dispose() for id,sub of @decorationMarkerDestroyedSubscriptions + sub.dispose() for id,sub of @decorationUpdatedSubscriptions + sub.dispose() for id,sub of @decorationDestroyedSubscriptions + decoration.destroy() for id,decoration of @decorationsById + + @decorationsById = {} + @decorationsByMarkerId = {} + @decorationMarkerChangedSubscriptions = {} + @decorationMarkerDestroyedSubscriptions = {} + @decorationUpdatedSubscriptions = {} + @decorationDestroyedSubscriptions = {} + + # Internal: Receive the update event of a decoration and trigger # a `minimap:decoration-updated` event. # diff --git a/spec/minimap-spec.coffee b/spec/minimap-spec.coffee index 3adfb230..6dba5b19 100644 --- a/spec/minimap-spec.coffee +++ b/spec/minimap-spec.coffee @@ -257,3 +257,17 @@ describe 'Minimap', -> it 'creates a change corresponding to the marker range', -> expect(changeSpy.calls[1].args[0].start).toEqual(0) expect(changeSpy.calls[1].args[0].end).toEqual(0) + + describe 'destroying the minimap', -> + beforeEach -> + minimap.destroy() + + it 'removes all the previously added decorations', -> + expect(minimap.decorationsById).toEqual({}) + expect(minimap.decorationsByMarkerId).toEqual({}) + + it 'prevents the creation of new decorations', -> + marker = editor.markBufferRange [[0,6], [0,11]] + decoration = minimap.decorateMarker marker, type: 'highlight', class: 'dummy' + + expect(decoration).toBeUndefined()