Start on TextEditorPresenter with lines state

This commit is contained in:
Nathan Sobo
2015-01-19 10:48:44 -07:00
parent 37a85bcdd0
commit f0920bf63b
2 changed files with 100 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
module.exports =
class TextEditorPresenter
constructor: ({@model, @clientHeight, @scrollTop, @lineHeight, @lineOverdrawMargin}) ->
@state = {}
@buildLinesState()
buildLinesState: ->
@state.lines = {}
startRow = Math.floor(@scrollTop / @lineHeight) - @lineOverdrawMargin
startRow = Math.max(0, startRow)
endRow = startRow + Math.ceil(@clientHeight / @lineHeight) + @lineOverdrawMargin
endRow = Math.min(@model.getScreenLineCount(), endRow)
for line, i in @model.tokenizedLinesForScreenRows(startRow, endRow)
row = startRow + i
@state.lines[line.id] = {
screenRow: row
tokens: line.tokens
top: row * @lineHeight
}