diff --git a/src/lines-presenter.coffee b/src/lines-presenter.coffee deleted file mode 100644 index c1e3676ba..000000000 --- a/src/lines-presenter.coffee +++ /dev/null @@ -1,41 +0,0 @@ -module.exports = -class LinesPresenter - startRow: null - endRow: null - lineHeight: null - - constructor: (@presenter) -> - @lines = {} - - getState: -> - visibleLineIds = {} - row = @startRow - while row < @endRow - line = @presenter.model.tokenizedLineForScreenRow(row) - unless line? - throw new Error("No line exists for row #{row}. Last screen row: #{@model.getLastScreenRow()}") - - visibleLineIds[line.id] = true - if @lines.hasOwnProperty(line.id) - lineState = @lines[line.id] - lineState.screenRow = row - lineState.top = (row - @startRow) * @lineHeight - lineState.decorationClasses = @presenter.lineDecorationClassesForRow(row) - else - @lines[line.id] = - screenRow: row - text: line.text - tokens: line.tokens - isOnlyWhitespace: line.isOnlyWhitespace() - endOfLineInvisibles: line.endOfLineInvisibles - indentLevel: line.indentLevel - tabLength: line.tabLength - fold: line.fold - top: (row - @startRow) * @lineHeight - decorationClasses: @presenter.lineDecorationClassesForRow(row) - row++ - - for id, line of @lines - delete @lines[id] unless visibleLineIds.hasOwnProperty(id) - - @lines diff --git a/src/text-editor-presenter.coffee b/src/text-editor-presenter.coffee index c7bf282ed..9d8c22c3c 100644 --- a/src/text-editor-presenter.coffee +++ b/src/text-editor-presenter.coffee @@ -23,7 +23,6 @@ class TextEditorPresenter @gutterWidth ?= 0 @tileOverdrawMargin ?= 0 @tileCount ?= 3 - @linesPresentersByTileIndex = {} @disposables = new CompositeDisposable @emitter = new Emitter @@ -318,19 +317,18 @@ class TextEditorPresenter visibleTiles = {} for index in [startIndex...endIndex] - presenter = @linesPresentersByTileIndex[index] ?= new LinesPresenter(@) - presenter.startRow = Math.floor(index * linesPerTile) - presenter.endRow = Math.ceil(Math.min(@model.getScreenLineCount(), (index + 1) * linesPerTile)) - presenter.lineHeight = @lineHeight + startRow = Math.floor(index * linesPerTile) + endRow = Math.ceil(Math.min(@model.getScreenLineCount(), (index + 1) * linesPerTile)) isNewTile = not @state.content.tiles.hasOwnProperty(index) tile = @state.content.tiles[index] ?= {} tile.top = (index * linesPerTile * @lineHeight) - @scrollTop - tile.lines = presenter.getState() tile.height = linesPerTile * @lineHeight tile.newlyCreated = isNewTile tile.display = "block" + @updateLinesState(tile, startRow, endRow) + visibleTiles[index] = true for index, tile of @state.content.tiles @@ -340,9 +338,40 @@ class TextEditorPresenter tile.display = "none" else delete @state.content.tiles[index] - delete @linesPresentersByTileIndex[index] + updateLinesState: (tileState, startRow, endRow) -> + tileState.lines ?= {} + visibleLineIds = {} + row = startRow + while row < endRow + line = @model.tokenizedLineForScreenRow(row) + unless line? + throw new Error("No line exists for row #{row}. Last screen row: #{@model.getLastScreenRow()}") + + visibleLineIds[line.id] = true + if tileState.lines.hasOwnProperty(line.id) + lineState = tileState.lines[line.id] + lineState.screenRow = row + lineState.top = (row - startRow) * @lineHeight + lineState.decorationClasses = @lineDecorationClassesForRow(row) + else + tileState.lines[line.id] = + screenRow: row + text: line.text + tokens: line.tokens + isOnlyWhitespace: line.isOnlyWhitespace() + endOfLineInvisibles: line.endOfLineInvisibles + indentLevel: line.indentLevel + tabLength: line.tabLength + fold: line.fold + top: (row - startRow) * @lineHeight + decorationClasses: @lineDecorationClassesForRow(row) + row++ + + for id, line of tileState.lines + delete tileState.lines[id] unless visibleLineIds.hasOwnProperty(id) + updateCursorsState: -> @state.content.cursors = {} @updateCursorState(cursor) for cursor in @model.cursors # using property directly to avoid allocation