mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Optimize highlightCursorLine by using cached element references
This commit is contained in:
@@ -50,6 +50,9 @@ class Anchor
|
||||
getScreenPosition: ->
|
||||
@screenPosition
|
||||
|
||||
getScreenRow: ->
|
||||
@screenPosition.row
|
||||
|
||||
setScreenPosition: (position, options={}) ->
|
||||
previousScreenPosition = @screenPosition
|
||||
@screenPosition = Point.fromObject(position)
|
||||
|
||||
@@ -31,6 +31,9 @@ class Cursor
|
||||
getScreenPosition: ->
|
||||
@anchor.getScreenPosition()
|
||||
|
||||
getScreenRow: ->
|
||||
@anchor.getScreenRow()
|
||||
|
||||
setBufferPosition: (bufferPosition, options) ->
|
||||
@goalColumn = null
|
||||
@clearSelection()
|
||||
|
||||
@@ -430,6 +430,9 @@ class EditSession
|
||||
getCursorScreenPosition: ->
|
||||
@getLastCursor().getScreenPosition()
|
||||
|
||||
getCursorScreenRow: ->
|
||||
@getLastCursor().getScreenRow()
|
||||
|
||||
setCursorBufferPosition: (position, options) ->
|
||||
@moveCursors (cursor) -> cursor.setBufferPosition(position, options)
|
||||
|
||||
|
||||
@@ -178,6 +178,7 @@ class Editor extends View
|
||||
moveCursorToEndOfLine: -> @activeEditSession.moveCursorToEndOfLine()
|
||||
setCursorScreenPosition: (position) -> @activeEditSession.setCursorScreenPosition(position)
|
||||
getCursorScreenPosition: -> @activeEditSession.getCursorScreenPosition()
|
||||
getCursorScreenRow: -> @activeEditSession.getCursorScreenRow()
|
||||
setCursorBufferPosition: (position, options) -> @activeEditSession.setCursorBufferPosition(position, options)
|
||||
getCursorBufferPosition: -> @activeEditSession.getCursorBufferPosition()
|
||||
|
||||
@@ -344,7 +345,7 @@ class Editor extends View
|
||||
else
|
||||
@gutter.addClass('drop-shadow')
|
||||
|
||||
@on 'cursor-move', => @highlightCursorLine()
|
||||
@on 'cursor-move', ({bufferChanged}) => @highlightCursorLine()
|
||||
@on 'selection-change', => @highlightCursorLine()
|
||||
|
||||
selectOnMousemoveUntilMouseup: ->
|
||||
@@ -638,6 +639,7 @@ class Editor extends View
|
||||
@setScrollPositionFromActiveEditSession()
|
||||
|
||||
@renderLines()
|
||||
@highlightCursorLine()
|
||||
@activeEditSession.on 'screen-lines-change', (e) => @handleDisplayBufferChange(e)
|
||||
|
||||
getCursorView: (index) ->
|
||||
@@ -817,6 +819,8 @@ class Editor extends View
|
||||
@lastRenderedScreenRow = maxEndRow
|
||||
@updatePaddingOfRenderedLines()
|
||||
|
||||
@highlightCursorLine()
|
||||
|
||||
buildLineElements: (startRow, endRow) ->
|
||||
charWidth = @charWidth
|
||||
charHeight = @charHeight
|
||||
@@ -825,19 +829,15 @@ class Editor extends View
|
||||
cursorScreenRow = @getCursorScreenPosition().row
|
||||
mini = @mini
|
||||
|
||||
buildLineHtml = (line, lineClasses) => @buildLineHtml(line, lineClasses)
|
||||
buildLineHtml = (line) => @buildLineHtml(line)
|
||||
|
||||
$$ ->
|
||||
row = startRow
|
||||
for line in lines
|
||||
if mini or row isnt cursorScreenRow
|
||||
lineClasses = null
|
||||
else
|
||||
lineClasses = ' cursor-line'
|
||||
@raw(buildLineHtml(line, lineClasses))
|
||||
@raw(buildLineHtml(line))
|
||||
row++
|
||||
|
||||
buildLineHtml: (screenLine, lineClasses) ->
|
||||
buildLineHtml: (screenLine) ->
|
||||
scopeStack = []
|
||||
line = []
|
||||
|
||||
@@ -869,8 +869,6 @@ class Editor extends View
|
||||
else
|
||||
lineAttributes = { class: 'line' }
|
||||
|
||||
lineAttributes.class += lineClasses if lineClasses
|
||||
|
||||
attributePairs = []
|
||||
attributePairs.push "#{attributeName}=\"#{value}\"" for attributeName, value of lineAttributes
|
||||
line.push("<pre #{attributePairs.join(' ')}>")
|
||||
@@ -965,9 +963,9 @@ class Editor extends View
|
||||
|
||||
highlightCursorLine: ->
|
||||
return if @mini
|
||||
|
||||
@cursorScreenRow = @getCursorScreenPosition().row
|
||||
screenRow = @cursorScreenRow - @firstRenderedScreenRow
|
||||
@find('pre.line.cursor-line').removeClass('cursor-line')
|
||||
@highlightedLine?.removeClass('cursor-line')
|
||||
if @getSelection().isSingleScreenLine()
|
||||
@find("pre.line:eq(#{screenRow})").addClass('cursor-line')
|
||||
@highlightedLine = @lineElementForScreenRow(@getCursorScreenRow())
|
||||
@highlightedLine.addClass('cursor-line')
|
||||
else
|
||||
@highlightedLine = null
|
||||
|
||||
Reference in New Issue
Block a user