Update TextEditorPresenter when the editor’s content changes

This commit is contained in:
Nathan Sobo
2015-01-19 11:57:16 -07:00
parent 5a2bbc945b
commit a1c2e1bb66
2 changed files with 37 additions and 0 deletions

View File

@@ -197,3 +197,30 @@ describe "TextEditorPresenter", ->
}
expect(presenter.state.lines[line5.id]).toBeUndefined()
describe "when the editor's content changes", ->
it "updates the lines state accordingly", ->
presenter = new TextEditorPresenter(model: editor, clientHeight: 25, scrollTop: 10, lineHeight: 10, lineOverdrawMargin: 0)
buffer.insert([2, 0], "hello\nworld\n")
line1 = editor.tokenizedLineForScreenRow(1)
expectValues presenter.state.lines[line1.id], {
screenRow: 1
tokens: line1.tokens
top: 10 * 1
}
line2 = editor.tokenizedLineForScreenRow(2)
expectValues presenter.state.lines[line2.id], {
screenRow: 2
tokens: line2.tokens
top: 10 * 2
}
line3 = editor.tokenizedLineForScreenRow(3)
expectValues presenter.state.lines[line3.id], {
screenRow: 3
tokens: line3.tokens
top: 10 * 3
}

View File

@@ -1,9 +1,19 @@
{CompositeDisposable} = require 'event-kit'
module.exports =
class TextEditorPresenter
constructor: ({@model, @clientHeight, @scrollTop, @lineHeight, @lineOverdrawMargin}) ->
@disposables = new CompositeDisposable
@state = {}
@subscribeToModel()
@buildLinesState()
destroy: ->
@disposables.dispose()
subscribeToModel: ->
@disposables.add @model.onDidChange(@updateLinesState.bind(this))
buildLinesState: ->
@state.lines = {}
@updateLinesState()