Skip to content

Commit

Permalink
🐛 Fix error raised on destruction due to remaining decorations
Browse files Browse the repository at this point in the history
Fixes #273
  • Loading branch information
abe33 committed Feb 16, 2015
1 parent a0aabd5 commit 23f1349
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/minimap.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class Minimap
# Destroys the model.
destroy: ->
@subscriptions.dispose()
@removeAllDecorations()
@textEditor = null
@emitter.emit 'did-destroy'
@destroyed = true
Expand Down
16 changes: 16 additions & 0 deletions lib/mixins/decoration-management.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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.
#
Expand Down
14 changes: 14 additions & 0 deletions spec/minimap-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 23f1349

Please sign in to comment.