Renders decoration changes.

This commit is contained in:
Ben Ogle
2014-06-03 18:44:35 -07:00
parent 77d269c6d9
commit 142eedd705
4 changed files with 23 additions and 6 deletions

View File

@@ -3207,7 +3207,7 @@ describe "Editor", ->
expect(editor.getScrollTop()).toBe 0
fdescribe "decorations", ->
it "can add decorations", ->
it "can add and remove decorations", ->
decoration = {type: 'gutter-class', class: 'one'}
editor.addDecorationForBufferRow(2, decoration)
editor.addDecorationForBufferRow(2, decoration)
@@ -3215,3 +3215,7 @@ describe "Editor", ->
decorations = editor.decorationsForBufferRow(2)
expect(decorations).toHaveLength 1
expect(decorations).toContain decoration
editor.removeDecorationForBufferRow(2, decoration)
decorations = editor.decorationsForBufferRow(2)
expect(decorations).toHaveLength 0

View File

@@ -727,18 +727,20 @@ class DisplayBuffer extends Model
for current in @decorations[bufferRow]
return if _.isEqual(current, decoration)
@decorations[bufferRow].push(decoration)
@emit 'decoration-changed', {bufferRow, add: decoration}
@emit 'decoration-changed', {bufferRow, decoration, action: 'add'}
removeDecorationForBufferRow: (bufferRow, decoration) ->
return unless @decorations[bufferRow]
removed = @findDecorationsForBufferRow(bufferRow, decoration)
@decorations[bufferRow] = _.without(@decorations, removed)
@emit 'decoration-changed', {bufferRow, remove: removed}
@decorations[bufferRow] = _.without(@decorations[bufferRow], removed...)
for decoration in removed
@emit 'decoration-changed', {bufferRow, decoration, action: 'remove'}
findDecorationsForBufferRow: (bufferRow, options) ->
return unless @decorations[bufferRow]
(dec for dec in @decorations[bufferRow] when _.isEqual(options, _.pick(decoration, _.keys(options))))
(dec for dec in @decorations[bufferRow] when _.isEqual(options, _.pick(dec, _.keys(options))))
addGutterClassForMarker: (bufferRow) ->
removeGutterClassForMarker: (bufferRow) ->

View File

@@ -214,6 +214,7 @@ class Editor extends Model
@subscribe @displayBuffer, 'grammar-changed', => @handleGrammarChange()
@subscribe @displayBuffer, 'tokenized', => @handleTokenization()
@subscribe @displayBuffer, 'soft-wrap-changed', (args...) => @emit 'soft-wrap-changed', args...
@subscribe @displayBuffer, "decoration-changed", (e) => @emit 'decoration-changed', e
getViewClass: ->
if atom.config.get('core.useReactEditor')

View File

@@ -24,6 +24,7 @@ GutterComponent = React.createClass
@lineNumberNodesById = {}
@lineNumberIdsByScreenRow = {}
@screenRowsByLineNumberId = {}
@decoratorUpdates = {}
componentDidMount: ->
@appendDummyLineNumber()
@@ -141,6 +142,7 @@ GutterComponent = React.createClass
classes = "line-number"
classes += ' foldable' if not softWrapped and @props.editor.isFoldableAtBufferRow(bufferRow)
classes += ' folded' if @props.editor.isFoldedAtBufferRow(bufferRow)
"<div class=\"#{classes}\" style=\"#{style}\" data-buffer-row=\"#{bufferRow}\" data-screen-row=\"#{screenRow}\">#{innerHTML}</div>"
buildLineNumberInnerHTML: (bufferRow, softWrapped, maxLineNumberDigits) ->
@@ -159,6 +161,11 @@ GutterComponent = React.createClass
@toggleClass node, 'foldable', not softWrapped and @props.editor.isFoldableAtBufferRow(bufferRow)
@toggleClass node, 'folded', @props.editor.isFoldedAtBufferRow(bufferRow)
if @decoratorUpdates[bufferRow]?
for change in @decoratorUpdates[bufferRow]
node.classList[change.action](change.decoration.class)
delete @decoratorUpdates[bufferRow]
unless @screenRowsByLineNumberId[lineNumberId] is screenRow
{lineHeightInPixels} = @props
node.style.top = screenRow * lineHeightInPixels + 'px'
@@ -176,4 +183,7 @@ GutterComponent = React.createClass
if condition then node.classList.add(klass) else node.classList.remove(klass)
onDecorationChanged: (change) ->
@forceUpdate()
if change.decoration.type == 'gutter-class'
@decoratorUpdates[change.bufferRow] ?= []
@decoratorUpdates[change.bufferRow].push change
@forceUpdate()