Recycle existing lines when calculating pixel positions

This commit is contained in:
Nathan Sobo
2013-02-12 16:54:14 -07:00
parent 65bf13e211
commit 3ab354d426

View File

@@ -1101,6 +1101,9 @@ class Editor extends View
@pendingChanges.push(change)
@requestDisplayUpdate()
buildLineElementForScreenRow: (screenRow) ->
@buildLineElementsForScreenRows(screenRow, screenRow)[0]
buildLineElementsForScreenRows: (startRow, endRow) ->
div = document.createElement('div')
div.innerHTML = @buildLinesHtml(@activeEditSession.linesForScreenRows(startRow, endRow))
@@ -1192,11 +1195,16 @@ class Editor extends View
pixelPositionForScreenPosition: (position) ->
return { top: 0, left: 0 } unless @isOnDom()
{row, column} = Point.fromObject(position)
[lineElement] = @buildLineElementsForScreenRows(row, row)
@renderedLines.append(lineElement)
actualRow = Math.floor(row)
lineElement = existingLineElement = @lineElementForScreenRow(actualRow)[0]
unless existingLineElement
lineElement = @buildLineElementForScreenRow(actualRow)
@renderedLines.append(lineElement)
left = @positionLeftForLineAndColumn(lineElement, column)
@renderedLines[0].removeChild(lineElement)
{ top: row * @lineHeight, left: left }
unless existingLineElement
@renderedLines[0].removeChild(lineElement)
{ top: row * @lineHeight, left }
positionLeftForLineAndColumn: (lineElement, column) ->
return 0 if column is 0