From 3ab354d426959626e83e0b288f93248ada96daaa Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 12 Feb 2013 16:54:14 -0700 Subject: [PATCH] Recycle existing lines when calculating pixel positions --- src/app/editor.coffee | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/app/editor.coffee b/src/app/editor.coffee index a5ce20265..c4fd2a835 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -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