mirror of
https://github.com/atom/atom.git
synced 2026-01-25 14:59:03 -05:00
Add .decorationClasses to line state on initial render
This commit is contained in:
@@ -183,7 +183,7 @@ describe "TextEditorPresenter", ->
|
||||
expect(presenter.state.content.lines[editor.tokenizedLineForScreenRow(0).id]).toBeDefined()
|
||||
expect(presenter.state.content.lines[editor.tokenizedLineForScreenRow(12).id]).toBeDefined()
|
||||
|
||||
it "includes the endOfLineInvisibles in the line state", ->
|
||||
it "includes the .endOfLineInvisibles in the line state if the editor.showInvisibles config option is true", ->
|
||||
editor.setText("hello\nworld\r\n")
|
||||
presenter = new TextEditorPresenter(model: editor, clientHeight: 25, clientWidth: 50, scrollTop: 0, baseCharacterWidth: 10, lineHeight: 10, lineOverdrawMargin: 0)
|
||||
expect(presenter.state.content.lines[editor.tokenizedLineForScreenRow(0).id].endOfLineInvisibles).toBeNull()
|
||||
@@ -194,6 +194,18 @@ describe "TextEditorPresenter", ->
|
||||
expect(presenter.state.content.lines[editor.tokenizedLineForScreenRow(0).id].endOfLineInvisibles).toEqual [atom.config.get('editor.invisibles.eol')]
|
||||
expect(presenter.state.content.lines[editor.tokenizedLineForScreenRow(1).id].endOfLineInvisibles).toEqual [atom.config.get('editor.invisibles.cr'), atom.config.get('editor.invisibles.eol')]
|
||||
|
||||
it "includes .decorationClasses in the line state", ->
|
||||
editor.decorateMarker(editor.markBufferRange([[4, 0], [6, 0]]), type: 'line', class: 'a')
|
||||
editor.decorateMarker(editor.markBufferRange([[5, 0], [5, 0]]), type: 'line', class: 'b')
|
||||
|
||||
presenter = new TextEditorPresenter(model: editor, clientHeight: 130, clientWidth: 50, scrollTop: 0, baseCharacterWidth: 10, lineHeight: 10, lineOverdrawMargin: 0)
|
||||
|
||||
expect(presenter.state.content.lines[editor.tokenizedLineForScreenRow(3).id].decorationClasses).toBeNull()
|
||||
expect(presenter.state.content.lines[editor.tokenizedLineForScreenRow(4).id].decorationClasses).toEqual ['a']
|
||||
expect(presenter.state.content.lines[editor.tokenizedLineForScreenRow(5).id].decorationClasses).toEqual ['a', 'b']
|
||||
expect(presenter.state.content.lines[editor.tokenizedLineForScreenRow(6).id].decorationClasses).toEqual ['a']
|
||||
expect(presenter.state.content.lines[editor.tokenizedLineForScreenRow(7).id].decorationClasses).toBeNull()
|
||||
|
||||
describe "when ::scrollTop changes", ->
|
||||
it "updates the lines that are visible on screen", ->
|
||||
presenter = new TextEditorPresenter(model: editor, clientHeight: 25, scrollTop: 0, lineHeight: 10, lineOverdrawMargin: 1)
|
||||
|
||||
@@ -66,6 +66,12 @@ class TextEditorPresenter
|
||||
lineState.top = row * @getLineHeight()
|
||||
|
||||
buildLineState: (row, line) ->
|
||||
decorationClasses = null
|
||||
for markerId, decorations of @model.decorationsForScreenRowRange(row, row) when @model.getMarker(markerId).isValid()
|
||||
for decoration in decorations when decoration.isType('line')
|
||||
decorationClasses ?= []
|
||||
decorationClasses.push(decoration.getProperties().class)
|
||||
|
||||
@state.content.lines[line.id] =
|
||||
screenRow: row
|
||||
text: line.text
|
||||
@@ -75,6 +81,7 @@ class TextEditorPresenter
|
||||
tabLength: line.tabLength
|
||||
fold: line.fold
|
||||
top: row * @getLineHeight()
|
||||
decorationClasses: decorationClasses
|
||||
|
||||
getStartRow: ->
|
||||
startRow = Math.floor(@getScrollTop() / @getLineHeight()) - @lineOverdrawMargin
|
||||
|
||||
Reference in New Issue
Block a user