Use a boolean in each line state object

This commit is contained in:
Antonio Scandurra
2015-11-30 14:44:58 +01:00
parent 539a5b0ae7
commit 8a54a2c15b
2 changed files with 46 additions and 45 deletions

View File

@@ -1270,8 +1270,8 @@ describe "TextEditorPresenter", ->
expect(lineStateForScreenRow(presenter, 0).endOfLineInvisibles).toEqual [atom.config.get('editor.invisibles.eol')]
expect(lineStateForScreenRow(presenter, 1).endOfLineInvisibles).toEqual [atom.config.get('editor.invisibles.cr'), atom.config.get('editor.invisibles.eol')]
describe ".blockDecorations", ->
it "adds block decorations to the relevant line state objects, both initially and when decorations change", ->
describe ".hasBlockDecorations", ->
it "is true when block decorations are present before a line, both initially and when decorations change", ->
blockDecoration1 = editor.addBlockDecorationForScreenRow(0)
presenter = buildPresenter()
blockDecoration2 = editor.addBlockDecorationForScreenRow(3)
@@ -1279,19 +1279,19 @@ describe "TextEditorPresenter", ->
waitsForStateToUpdate presenter
runs ->
expect(lineStateForScreenRow(presenter, 0).blockDecorations).toEqual [blockDecoration1]
expect(lineStateForScreenRow(presenter, 1).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 2).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 3).blockDecorations).toEqual [blockDecoration2]
expect(lineStateForScreenRow(presenter, 4).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 5).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 6).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 7).blockDecorations).toEqual [blockDecoration3]
expect(lineStateForScreenRow(presenter, 8).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 9).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 10).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 11).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 12).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 0).hasBlockDecorations).toBe(true)
expect(lineStateForScreenRow(presenter, 1).hasBlockDecorations).toBe(false)
expect(lineStateForScreenRow(presenter, 2).hasBlockDecorations).toBe(false)
expect(lineStateForScreenRow(presenter, 3).hasBlockDecorations).toBe(true)
expect(lineStateForScreenRow(presenter, 4).hasBlockDecorations).toBe(false)
expect(lineStateForScreenRow(presenter, 5).hasBlockDecorations).toBe(false)
expect(lineStateForScreenRow(presenter, 6).hasBlockDecorations).toBe(false)
expect(lineStateForScreenRow(presenter, 7).hasBlockDecorations).toBe(true)
expect(lineStateForScreenRow(presenter, 8).hasBlockDecorations).toBe(false)
expect(lineStateForScreenRow(presenter, 9).hasBlockDecorations).toBe(false)
expect(lineStateForScreenRow(presenter, 10).hasBlockDecorations).toBe(false)
expect(lineStateForScreenRow(presenter, 11).hasBlockDecorations).toBe(false)
expect(lineStateForScreenRow(presenter, 12).hasBlockDecorations).toBe(false)
waitsForStateToUpdate presenter, ->
blockDecoration1.getMarker().setHeadBufferPosition([1, 0])
@@ -1299,38 +1299,38 @@ describe "TextEditorPresenter", ->
blockDecoration3.getMarker().setHeadBufferPosition([9, 0])
runs ->
expect(lineStateForScreenRow(presenter, 0).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 1).blockDecorations).toEqual [blockDecoration1]
expect(lineStateForScreenRow(presenter, 2).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 3).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 4).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 5).blockDecorations).toEqual [blockDecoration2]
expect(lineStateForScreenRow(presenter, 6).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 7).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 8).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 9).blockDecorations).toEqual [blockDecoration3]
expect(lineStateForScreenRow(presenter, 10).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 11).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 12).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 0).hasBlockDecorations).toBe(false)
expect(lineStateForScreenRow(presenter, 1).hasBlockDecorations).toBe(true)
expect(lineStateForScreenRow(presenter, 2).hasBlockDecorations).toBe(false)
expect(lineStateForScreenRow(presenter, 3).hasBlockDecorations).toBe(false)
expect(lineStateForScreenRow(presenter, 4).hasBlockDecorations).toBe(false)
expect(lineStateForScreenRow(presenter, 5).hasBlockDecorations).toBe(true)
expect(lineStateForScreenRow(presenter, 6).hasBlockDecorations).toBe(false)
expect(lineStateForScreenRow(presenter, 7).hasBlockDecorations).toBe(false)
expect(lineStateForScreenRow(presenter, 8).hasBlockDecorations).toBe(false)
expect(lineStateForScreenRow(presenter, 9).hasBlockDecorations).toBe(true)
expect(lineStateForScreenRow(presenter, 10).hasBlockDecorations).toBe(false)
expect(lineStateForScreenRow(presenter, 11).hasBlockDecorations).toBe(false)
expect(lineStateForScreenRow(presenter, 12).hasBlockDecorations).toBe(false)
waitsForStateToUpdate presenter, ->
blockDecoration1.destroy()
blockDecoration3.destroy()
runs ->
expect(lineStateForScreenRow(presenter, 0).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 1).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 2).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 3).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 4).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 5).blockDecorations).toEqual [blockDecoration2]
expect(lineStateForScreenRow(presenter, 6).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 7).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 8).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 9).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 10).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 11).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 12).blockDecorations).toEqual []
expect(lineStateForScreenRow(presenter, 0).hasBlockDecorations).toBe(false)
expect(lineStateForScreenRow(presenter, 1).hasBlockDecorations).toBe(false)
expect(lineStateForScreenRow(presenter, 2).hasBlockDecorations).toBe(false)
expect(lineStateForScreenRow(presenter, 3).hasBlockDecorations).toBe(false)
expect(lineStateForScreenRow(presenter, 4).hasBlockDecorations).toBe(false)
expect(lineStateForScreenRow(presenter, 5).hasBlockDecorations).toBe(true)
expect(lineStateForScreenRow(presenter, 6).hasBlockDecorations).toBe(false)
expect(lineStateForScreenRow(presenter, 7).hasBlockDecorations).toBe(false)
expect(lineStateForScreenRow(presenter, 8).hasBlockDecorations).toBe(false)
expect(lineStateForScreenRow(presenter, 9).hasBlockDecorations).toBe(false)
expect(lineStateForScreenRow(presenter, 10).hasBlockDecorations).toBe(false)
expect(lineStateForScreenRow(presenter, 11).hasBlockDecorations).toBe(false)
expect(lineStateForScreenRow(presenter, 12).hasBlockDecorations).toBe(false)
describe ".decorationClasses", ->
it "adds decoration classes to the relevant line state objects, both initially and when decorations change", ->
@@ -2563,8 +2563,8 @@ describe "TextEditorPresenter", ->
expectValues lineNumberStateForScreenRow(presenter, 6), {screenRow: 6, bufferRow: 5, softWrapped: false}
expectValues lineNumberStateForScreenRow(presenter, 7), {screenRow: 7, bufferRow: 6, softWrapped: false}
describe ".blockDecorations", ->
it "adds block decorations' height to the relevant line number state objects, both initially and when decorations change", ->
describe ".blockDecorationsHeight", ->
it "adds the sum of all block decorations' heights to the relevant line number state objects, both initially and when decorations change", ->
blockDecoration1 = editor.addBlockDecorationForScreenRow(0)
presenter = buildPresenter()
blockDecoration2 = editor.addBlockDecorationForScreenRow(3)

View File

@@ -485,11 +485,12 @@ class TextEditorPresenter
throw new Error("No line exists for row #{screenRow}. Last screen row: #{@model.getLastScreenRow()}")
visibleLineIds[line.id] = true
blockDecorations = this.blockDecorationsPresenter.getDecorationsByScreenRow(screenRow)
if tileState.lines.hasOwnProperty(line.id)
lineState = tileState.lines[line.id]
lineState.screenRow = screenRow
lineState.decorationClasses = @lineDecorationClassesForRow(screenRow)
lineState.blockDecorations = Array.from(this.blockDecorationsPresenter.getDecorationsByScreenRow(screenRow))
lineState.hasBlockDecorations = blockDecorations.size isnt 0
else
tileState.lines[line.id] =
screenRow: screenRow
@@ -506,7 +507,7 @@ class TextEditorPresenter
tabLength: line.tabLength
fold: line.fold
decorationClasses: @lineDecorationClassesForRow(screenRow)
blockDecorations: Array.from(this.blockDecorationsPresenter.getDecorationsByScreenRow(screenRow))
hasBlockDecorations: blockDecorations.size isnt 0
for id, line of tileState.lines
delete tileState.lines[id] unless visibleLineIds.hasOwnProperty(id)