Move selection background region calculation into React component

This commit is contained in:
Nathan Sobo
2014-05-13 10:59:38 -06:00
parent 0162247bd7
commit 9b02055db9
3 changed files with 13 additions and 18 deletions

View File

@@ -40,7 +40,7 @@ EditorScrollViewComponent = React.createClass
selectionChanged
}
div className: 'underlayer',
SelectionBackgroundsComponent({editor, scrollTop, scrollLeft})
SelectionBackgroundsComponent({editor, lineHeight, scrollTop})
componentDidMount: ->
@getDOMNode().addEventListener 'overflowchanged', @onOverflowChanged

View File

@@ -6,13 +6,19 @@ SelectionBackgroundsComponent = React.createClass
displayName: 'SelectionBackgroundsComponent'
render: ->
{editor, scrollTop} = @props
{editor, lineHeight, scrollTop} = @props
div className: 'selections',
if @isMounted()
for selection in editor.getSelections()
if backgroundRect = selection.getBackgroundRect()
{top, left, right, height} = backgroundRect
WebkitTransform = "translate3d(0px, #{top - scrollTop}px, 0px)"
div className: 'selection', key: selection.id,
div className: 'region', style: {left, right, height, WebkitTransform}
{start, end} = selection.getScreenRange()
continue if start.row is end.row
height = (end.row - start.row) * lineHeight
top = (start.row * lineHeight) - scrollTop
left = 0
right = 0
WebkitTransform = "translate3d(0px, #{top}px, 0px)"
div className: 'selection', key: selection.id,
div className: 'region', style: {left, right, height, WebkitTransform}

View File

@@ -591,17 +591,6 @@ class Selection extends Model
compare: (otherSelection) ->
@getBufferRange().compare(otherSelection.getBufferRange())
getBackgroundRect: ->
{start, end} = @getScreenRange()
return if start.row is end.row
lineHeight = @editor.getLineHeight()
height = (end.row - start.row) * lineHeight
top = start.row * lineHeight
left = 0
right = 0
{top, left, right, height}
screenRangeChanged: ->
screenRange = @getScreenRange()
@emit 'screen-range-changed', screenRange