Subscribe directly to the decoration destroy for removal

This commit is contained in:
Ben Ogle
2014-09-05 16:53:35 -07:00
parent 86e9778adb
commit 47ef54a072
2 changed files with 8 additions and 21 deletions

View File

@@ -53,6 +53,8 @@ class Decoration
@flashQueue = null
@isDestroyed = false
@markerDestroyDisposable = @marker.onDidDestroy => @destroy()
# Essential: An id unique across all {Decoration} objects
getId: -> @id
@@ -114,8 +116,9 @@ class Decoration
# this decoration.
destroy: ->
return if @isDestroyed
@markerDestroyDisposable.dispose()
@markerDestroyDisposable = null
@isDestroyed = true
@displayBuffer.removeDecoration(this)
@emit 'destroyed'
@emitter.emit 'did-destroy'
@emitter.dispose()

View File

@@ -53,7 +53,6 @@ class DisplayBuffer extends Model
@foldsByMarkerId = {}
@decorationsById = {}
@decorationsByMarkerId = {}
@decorationMarkerDestroyedSubscriptions = {}
@updateAllScreenLines()
@createFoldForMarker(marker) for marker in @buffer.findMarkers(@getFoldMarkerAttributes())
@subscribe @tokenizedBuffer.onDidChange @handleTokenizedBufferChange
@@ -136,9 +135,9 @@ class DisplayBuffer extends Model
when 'decoration-removed'
Grim.deprecate("Use DisplayBuffer::onDidRemoveDecoration instead")
when 'decoration-changed'
Grim.deprecate("Use DisplayBuffer::onDidChangeDecoration instead")
Grim.deprecate("Use decoration.getMarker().onDidChange() instead")
when 'decoration-updated'
Grim.deprecate("Use DisplayBuffer::onDidChangeDecoration instead")
Grim.deprecate("Use Decoration::onDidChangeProperties instead")
# else
# Grim.deprecate("DisplayBuffer::on is deprecated. Use event subscription methods instead.")
@@ -835,11 +834,8 @@ class DisplayBuffer extends Model
decorateMarker: (marker, decorationParams) ->
marker = @getMarker(marker.id)
@decorationMarkerDestroyedSubscriptions[marker.id] ?= @subscribe marker.onDidDestroy =>
@removeAllDecorationsForMarker(marker)
decoration = new Decoration(marker, this, decorationParams)
@subscribe decoration.onDidDestroy => @removeDecoration(decoration)
@decorationsByMarkerId[marker.id] ?= []
@decorationsByMarkerId[marker.id].push(decoration)
@decorationsById[decoration.id] = decoration
@@ -857,19 +853,7 @@ class DisplayBuffer extends Model
delete @decorationsById[decoration.id]
@emit 'decoration-removed', decoration
@emitter.emit 'did-remove-decoration', decoration
@removedAllMarkerDecorations(marker) if decorations.length is 0
removeAllDecorationsForMarker: (marker) ->
decorations = @decorationsByMarkerId[marker.id].slice()
for decoration in decorations
@emit 'decoration-removed', decoration
@emitter.emit 'did-remove-decoration', decoration
@removedAllMarkerDecorations(marker)
removedAllMarkerDecorations: (marker) ->
@decorationMarkerDestroyedSubscriptions[marker.id].dispose()
delete @decorationsByMarkerId[marker.id]
delete @decorationMarkerDestroyedSubscriptions[marker.id]
delete @decorationsByMarkerId[marker.id] if decorations.length is 0
# Retrieves a {DisplayBufferMarker} based on its id.
#