Implement shouldComponentUpdate for SelectionsComponent

This commit is contained in:
Corey Johnson & Nathan Sobo
2014-05-15 11:50:25 -06:00
committed by Nathan Sobo
parent 7dfe829fc8
commit 3f01e2f748
3 changed files with 35 additions and 9 deletions

View File

@@ -22,7 +22,7 @@ LinesComponent = React.createClass
WebkitTransform: "translate3d(#{-scrollLeft}px, #{-scrollTop}px, 0px)"
div {className: 'lines', style},
SelectionsComponent({editor, lineHeight}) if @isMounted
SelectionsComponent({editor, lineHeight}) if @isMounted()
componentWillMount: ->
@measuredLines = new WeakSet

View File

@@ -6,8 +6,8 @@ SelectionComponent = React.createClass
displayName: 'SelectionComponent'
render: ->
{editor, selection, lineHeight} = @props
{start, end} = selection.getScreenRange()
{editor, screenRange, lineHeight} = @props
{start, end} = screenRange
rowCount = end.row - start.row + 1
startPixelPosition = editor.pixelPositionForScreenPosition(start)
endPixelPosition = editor.pixelPositionForScreenPosition(end)

View File

@@ -7,11 +7,37 @@ SelectionsComponent = React.createClass
displayName: 'SelectionsComponent'
render: ->
div className: 'selections', @renderSelections()
renderSelections: ->
{editor, lineHeight} = @props
div className: 'selections',
if @isMounted()
for selection, index in editor.getSelections()
# Rendering artifacts occur on the lines GPU layer if we remove the last selection
if index is 0 or (not selection.isEmpty() and editor.selectionIntersectsVisibleRowRange(selection))
SelectionComponent({key: selection.id, selection, editor, lineHeight})
selectionComponents = []
for selectionId, screenRange of @selectionRanges
selectionComponents.push(SelectionComponent({key: selectionId, screenRange, editor, lineHeight}))
selectionComponents
componentWillMount: ->
@selectionRanges = {}
shouldComponentUpdate: ->
{editor} = @props
oldSelectionRanges = @selectionRanges
newSelectionRanges = {}
@selectionRanges = newSelectionRanges
for selection, index in editor.getSelections()
# Rendering artifacts occur on the lines GPU layer if we remove the last selection
if index is 0 or (not selection.isEmpty() and editor.selectionIntersectsVisibleRowRange(selection))
newSelectionRanges[selection.id] = selection.getScreenRange()
for id, range of newSelectionRanges
if oldSelectionRanges.hasOwnProperty(id)
return true unless range.isEqual(oldSelectionRanges[id])
else
return true
for id of oldSelectionRanges
return true unless newSelectionRanges.hasOwnProperty(id)
false