Add updateDecorationForMarker()

This commit is contained in:
Ben Ogle
2014-07-01 17:33:51 -07:00
parent 15da69287e
commit 7b19152a58
2 changed files with 20 additions and 0 deletions

View File

@@ -795,6 +795,21 @@ class DisplayBuffer extends Model
@decorationsByMarkerId[marker.id].push(decoration)
@emit 'decoration-added', marker, decoration
updateDecorationForMarker: (marker, decorationPattern, newDecoration) ->
unless marker?
console.warn 'A null marker cannot be decorated'
return
marker = @getMarker(marker.id)
return unless decorations = @decorationsByMarkerId[marker.id]
for decoration, i in decorations
if @decorationMatchesPattern(decoration, decorationPattern) and not _.isEqual(decoration, newDecoration)
decorations[i] = newDecoration
@emit 'decoration-updated', marker, decoration, newDecoration
return
removeDecorationForMarker: (marker, decorationPattern) ->
unless marker?
console.warn 'A decoration cannot be removed from a null marker'

View File

@@ -218,6 +218,7 @@ class Editor extends Model
@subscribe @displayBuffer, "decoration-added", (args...) => @emit 'decoration-added', args...
@subscribe @displayBuffer, "decoration-removed", (args...) => @emit 'decoration-removed', args...
@subscribe @displayBuffer, "decoration-changed", (args...) => @emit 'decoration-changed', args...
@subscribe @displayBuffer, "decoration-updated", (args...) => @emit 'decoration-updated', args...
@subscribe @displayBuffer, "character-widths-changed", (changeCount) => @emit 'character-widths-changed', changeCount
getViewClass: ->
@@ -1111,6 +1112,10 @@ class Editor extends Model
addDecorationForMarker: (marker, decoration) ->
@displayBuffer.addDecorationForMarker(marker, decoration)
#
updateDecorationForMarker: (marker, decorationPattern, newDecoration) ->
@displayBuffer.updateDecorationForMarker(marker, decorationPattern, newDecoration)
# Public: Removes all decorations associated with a {Marker} that match a
# `decorationPattern` and stop tracking the {Marker}.
#