mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Move selection background region calculation into React component
This commit is contained in:
@@ -40,7 +40,7 @@ EditorScrollViewComponent = React.createClass
|
||||
selectionChanged
|
||||
}
|
||||
div className: 'underlayer',
|
||||
SelectionBackgroundsComponent({editor, scrollTop, scrollLeft})
|
||||
SelectionBackgroundsComponent({editor, lineHeight, scrollTop})
|
||||
|
||||
componentDidMount: ->
|
||||
@getDOMNode().addEventListener 'overflowchanged', @onOverflowChanged
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user