mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Directly subscribe to the decorations in EditorComponent
This commit is contained in:
@@ -1134,7 +1134,7 @@ describe "EditorComponent", ->
|
||||
it "renders the decoration's new params", ->
|
||||
expect(componentNode.querySelector('.test-highlight')).toBeTruthy()
|
||||
|
||||
decoration.update(type: 'highlight', class: 'new-test-highlight')
|
||||
decoration.setProperties(type: 'highlight', class: 'new-test-highlight')
|
||||
nextAnimationFrame()
|
||||
|
||||
expect(componentNode.querySelector('.test-highlight')).toBeFalsy()
|
||||
|
||||
@@ -53,7 +53,6 @@ class DisplayBuffer extends Model
|
||||
@foldsByMarkerId = {}
|
||||
@decorationsById = {}
|
||||
@decorationsByMarkerId = {}
|
||||
@decorationMarkerChangedSubscriptions = {}
|
||||
@decorationMarkerDestroyedSubscriptions = {}
|
||||
@updateAllScreenLines()
|
||||
@createFoldForMarker(marker) for marker in @buffer.findMarkers(@getFoldMarkerAttributes())
|
||||
@@ -112,6 +111,10 @@ class DisplayBuffer extends Model
|
||||
onDidChangeCharacterWidths: (callback) ->
|
||||
@emitter.on 'did-change-character-widths', callback
|
||||
|
||||
observeDecorations: (callback) ->
|
||||
callback(decoration) for decoration in @getDecorations()
|
||||
@onDidAddDecoration(callback)
|
||||
|
||||
onDidAddDecoration: (callback) ->
|
||||
@emitter.on 'did-add-decoration', callback
|
||||
|
||||
@@ -820,6 +823,12 @@ class DisplayBuffer extends Model
|
||||
decorationForId: (id) ->
|
||||
@decorationsById[id]
|
||||
|
||||
getDecorations: ->
|
||||
allDecorations = []
|
||||
for markerId, decorations of @decorationsByMarkerId
|
||||
allDecorations = allDecorations.concat(decorations) if decorations?
|
||||
allDecorations
|
||||
|
||||
decorationsForScreenRowRange: (startScreenRow, endScreenRow) ->
|
||||
decorationsByMarkerId = {}
|
||||
for marker in @findMarkers(intersectsScreenRowRange: [startScreenRow, endScreenRow])
|
||||
@@ -833,16 +842,6 @@ class DisplayBuffer extends Model
|
||||
@decorationMarkerDestroyedSubscriptions[marker.id] ?= @subscribe marker.onDidDestroy =>
|
||||
@removeAllDecorationsForMarker(marker)
|
||||
|
||||
@decorationMarkerChangedSubscriptions[marker.id] ?= @subscribe marker.onDidChange (event) =>
|
||||
decorations = @decorationsByMarkerId[marker.id]
|
||||
|
||||
# Why check existence? Markers may get destroyed or decorations removed
|
||||
# in the change handler. Bookmarks does this.
|
||||
if decorations?
|
||||
for decoration in decorations
|
||||
@emit 'decoration-changed', decoration
|
||||
@emitter.emit 'did-change-decoration', decoration
|
||||
|
||||
decoration = new Decoration(marker, this, decorationParams)
|
||||
@decorationsByMarkerId[marker.id] ?= []
|
||||
@decorationsByMarkerId[marker.id].push(decoration)
|
||||
@@ -871,18 +870,10 @@ class DisplayBuffer extends Model
|
||||
@removedAllMarkerDecorations(marker)
|
||||
|
||||
removedAllMarkerDecorations: (marker) ->
|
||||
@decorationMarkerChangedSubscriptions[marker.id].dispose()
|
||||
@decorationMarkerDestroyedSubscriptions[marker.id].dispose()
|
||||
|
||||
delete @decorationsByMarkerId[marker.id]
|
||||
delete @decorationMarkerChangedSubscriptions[marker.id]
|
||||
delete @decorationMarkerDestroyedSubscriptions[marker.id]
|
||||
|
||||
# Called by the decoration
|
||||
decorationChanged: (decoration) ->
|
||||
@emit 'decoration-changed', decoration
|
||||
@emitter.emit 'did-change-decoration', decoration
|
||||
|
||||
# Retrieves a {DisplayBufferMarker} based on its id.
|
||||
#
|
||||
# id - A {Number} representing a marker id
|
||||
|
||||
@@ -347,9 +347,8 @@ EditorComponent = React.createClass
|
||||
@subscribe editor, 'screen-lines-changed', @onScreenLinesChanged
|
||||
@subscribe editor.onDidAddCursor(@onCursorAdded)
|
||||
@subscribe editor.onDidAddSelection(@onSelectionAdded)
|
||||
@subscribe editor.onDidAddDecoration @onDecorationChanged
|
||||
@subscribe editor.onDidRemoveDecoration @onDecorationChanged
|
||||
@subscribe editor.onDidChangeDecoration @onDecorationChanged
|
||||
@subscribe editor.observeDecorations(@onDecorationAdded)
|
||||
@subscribe editor.onDidRemoveDecoration(@onDecorationRemoved)
|
||||
@subscribe editor.onDidChangeCharacterWidths @onCharacterWidthsChanged
|
||||
@subscribe editor.$scrollTop.changes, @onScrollTopChanged
|
||||
@subscribe editor.$scrollLeft.changes, @requestUpdate
|
||||
@@ -758,9 +757,17 @@ EditorComponent = React.createClass
|
||||
@cursorMoved = true
|
||||
@requestUpdate()
|
||||
|
||||
onDecorationAdded: (decoration) ->
|
||||
@subscribe decoration.onDidChangeProperties(@onDecorationChanged)
|
||||
@subscribe decoration.getMarker().onDidChange(@onDecorationChanged)
|
||||
@requestUpdate()
|
||||
|
||||
onDecorationChanged: ->
|
||||
@requestUpdate()
|
||||
|
||||
onDecorationRemoved: ->
|
||||
@requestUpdate()
|
||||
|
||||
onCharacterWidthsChanged: (@scopedCharacterWidthsChangeCount) ->
|
||||
@requestUpdate()
|
||||
|
||||
|
||||
@@ -325,6 +325,9 @@ class Editor extends Model
|
||||
onDidRemoveSelection: (callback) ->
|
||||
@emitter.on 'did-remove-selection', callback
|
||||
|
||||
observeDecorations: (callback) ->
|
||||
@displayBuffer.observeDecorations(callback)
|
||||
|
||||
onDidAddDecoration: (callback) ->
|
||||
@displayBuffer.onDidAddDecoration(callback)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user