Throw exceptions when decorating destroyed marker layers

This commit is contained in:
Nathan Sobo 2017-02-14 09:44:02 -07:00
parent 8dafc1ce1b
commit 4abcace5c3
2 changed files with 9 additions and 1 deletions

View File

@ -1,7 +1,7 @@
DecorationManager = require '../src/decoration-manager'
describe "DecorationManager", ->
[decorationManager, buffer, defaultMarkerLayer] = []
[decorationManager, buffer, defaultMarkerLayer, displayLayer] = []
beforeEach ->
buffer = atom.project.bufferForPathSync('sample.js')
@ -45,6 +45,13 @@ describe "DecorationManager", ->
).toThrow("Cannot decorate a destroyed marker")
expect(decorationManager.getOverlayDecorations()).toEqual []
it "does not allow destroyed marker layers to be decorated", ->
layer = displayLayer.addMarkerLayer()
layer.destroy()
expect(->
decorationManager.decorateMarkerLayer(layer, {type: 'highlight'})
).toThrow("Cannot decorate a destroyed marker layer")
describe "when a decoration is updated via Decoration::update()", ->
it "emits an 'updated' event containing the new and old params", ->
decoration.onDidChangeProperties updatedSpy = jasmine.createSpy()

View File

@ -117,6 +117,7 @@ class DecorationManager extends Model
decoration
decorateMarkerLayer: (markerLayer, decorationParams) ->
throw new Error("Cannot decorate a destroyed marker layer") if markerLayer.isDestroyed()
decoration = new LayerDecoration(markerLayer, this, decorationParams)
@layerDecorationsByMarkerLayerId[markerLayer.id] ?= []
@layerDecorationsByMarkerLayerId[markerLayer.id].push(decoration)