Merge pull request #12325 from atom/ns-fix-decorated-layer-destruction

Fix decorated layer destruction
This commit is contained in:
Max Brunsfeld 2016-08-04 14:02:40 -07:00 committed by GitHub
commit a79ffa308a
4 changed files with 13 additions and 6 deletions

View File

@ -58,7 +58,7 @@
"sinon": "1.17.4",
"source-map-support": "^0.3.2",
"temp": "0.8.1",
"text-buffer": "9.2.4",
"text-buffer": "9.2.6",
"typescript-simple": "1.0.0",
"underscore-plus": "^1.6.6",
"winreg": "^1.2.1",

View File

@ -5901,6 +5901,13 @@ describe "TextEditor", ->
rangeIsReversed: false
}
it "does not throw errors after the marker's containing layer is destroyed", ->
layer = editor.addMarkerLayer()
marker = layer.markBufferRange([[2, 4], [6, 8]])
decoration = editor.decorateMarker(marker, type: 'highlight', class: 'foo')
layer.destroy()
editor.decorationsStateForScreenRowRange(0, 5)
describe "::decorateMarkerLayer", ->
it "based on the markers in the layer, includes multiple decoration objects with the same properties and different ranges in the object returned from ::decorationsStateForScreenRowRange", ->
layer1 = editor.getBuffer().addMarkerLayer()

View File

@ -144,7 +144,7 @@ class DecorationManager extends Model
else
delete @overlayDecorationsById[decoration.id]
didDestroyDecoration: (decoration) ->
didDestroyMarkerDecoration: (decoration) ->
{marker} = decoration
return unless decorations = @decorationsByMarkerId[marker.id]
index = decorations.indexOf(decoration)

View File

@ -69,16 +69,16 @@ class Decoration
@destroyed = false
@markerDestroyDisposable = @marker.onDidDestroy => @destroy()
# Essential: Destroy this marker.
# Essential: Destroy this marker decoration.
#
# If you own the marker, you should use {DisplayMarker::destroy} which will destroy
# this decoration.
# You can also destroy the marker if you own it, which will destroy this
# decoration.
destroy: ->
return if @destroyed
@markerDestroyDisposable.dispose()
@markerDestroyDisposable = null
@destroyed = true
@decorationManager.didDestroyDecoration(this)
@decorationManager.didDestroyMarkerDecoration(this)
@emitter.emit 'did-destroy'
@emitter.dispose()