mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Use cached text nodes instead of NodeIterator
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
LinesYardstick = require "../src/lines-yardstick"
|
||||
{toArray} = require 'underscore-plus'
|
||||
|
||||
describe "LinesYardstick", ->
|
||||
[editor, mockPresenter, mockLineNodesProvider, createdLineNodes, linesYardstick] = []
|
||||
@@ -46,6 +47,13 @@ describe "LinesYardstick", ->
|
||||
return if availableScreenRows[lineId] isnt screenRow
|
||||
|
||||
buildLineNode(screenRow)
|
||||
textNodesForLineIdAndScreenRow: (lineId, screenRow) ->
|
||||
lineNode = @lineNodeForLineIdAndScreenRow(lineId, screenRow)
|
||||
textNodes = []
|
||||
for span in lineNode.children
|
||||
for textNode in span.childNodes
|
||||
textNodes.push(textNode)
|
||||
textNodes
|
||||
|
||||
editor.setLineHeightInPixels(14)
|
||||
linesYardstick = new LinesYardstick(editor, mockPresenter, mockLineNodesProvider)
|
||||
|
||||
@@ -86,3 +86,7 @@ class LinesComponent extends TiledComponent
|
||||
lineNodeForLineIdAndScreenRow: (lineId, screenRow) ->
|
||||
tile = @presenter.tileForRow(screenRow)
|
||||
@getComponentForTile(tile)?.lineNodeForLineId(lineId)
|
||||
|
||||
textNodesForLineIdAndScreenRow: (lineId, screenRow) ->
|
||||
tile = @presenter.tileForRow(screenRow)
|
||||
@getComponentForTile(tile)?.textNodesForLineId(lineId)
|
||||
|
||||
@@ -35,7 +35,7 @@ class LinesYardstick
|
||||
|
||||
return new Point(row, 0) unless lineNode? and line?
|
||||
|
||||
iterator = document.createNodeIterator(lineNode, NodeFilter.SHOW_TEXT)
|
||||
textNodes = @lineNodesProvider.textNodesForLineIdAndScreenRow(line.id, row)
|
||||
column = 0
|
||||
previousColumn = 0
|
||||
previousLeft = 0
|
||||
@@ -55,13 +55,13 @@ class LinesYardstick
|
||||
textIndex++
|
||||
|
||||
unless textNode?
|
||||
textNode = iterator.nextNode()
|
||||
textNode = textNodes.shift()
|
||||
textNodeLength = textNode.textContent.length
|
||||
textNodeIndex = 0
|
||||
nextTextNodeIndex = textNodeLength
|
||||
|
||||
while nextTextNodeIndex <= column
|
||||
textNode = iterator.nextNode()
|
||||
textNode = textNodes.shift()
|
||||
textNodeLength = textNode.textContent.length
|
||||
textNodeIndex = nextTextNodeIndex
|
||||
nextTextNodeIndex = textNodeIndex + textNodeLength
|
||||
@@ -108,8 +108,8 @@ class LinesYardstick
|
||||
if cachedPosition = @pixelPositionsByLineIdAndColumn[line.id]?[column]
|
||||
return cachedPosition
|
||||
|
||||
textNodes = @lineNodesProvider.textNodesForLineIdAndScreenRow(line.id, row)
|
||||
indexWithinTextNode = null
|
||||
iterator = document.createNodeIterator(lineNode, NodeFilter.SHOW_TEXT)
|
||||
charIndex = 0
|
||||
|
||||
@tokenIterator.reset(line)
|
||||
@@ -130,13 +130,13 @@ class LinesYardstick
|
||||
textIndex++
|
||||
|
||||
unless textNode?
|
||||
textNode = iterator.nextNode()
|
||||
textNode = textNodes.shift()
|
||||
textNodeLength = textNode.textContent.length
|
||||
textNodeIndex = 0
|
||||
nextTextNodeIndex = textNodeLength
|
||||
|
||||
while nextTextNodeIndex <= charIndex
|
||||
textNode = iterator.nextNode()
|
||||
textNode = textNodes.shift()
|
||||
textNodeLength = textNode.textContent.length
|
||||
textNodeIndex = nextTextNodeIndex
|
||||
nextTextNodeIndex = textNodeIndex + textNodeLength
|
||||
|
||||
Reference in New Issue
Block a user