In presenter, handle the first line being soft-wrapped

Signed-off-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
This commit is contained in:
Nathan Sobo 2015-02-03 13:30:42 -07:00
parent 75652e36d9
commit cd77870286
2 changed files with 24 additions and 8 deletions

View File

@ -1522,6 +1522,15 @@ describe "TextEditorPresenter", ->
expect(lineNumberStateForScreenRow(presenter, 7)).toBeDefined()
expect(lineNumberStateForScreenRow(presenter, 8)).toBeUndefined()
it "correctly handles the first screen line being soft-wrapped", ->
editor.setSoftWrapped(true)
editor.setEditorWidthInChars(30)
presenter = new TextEditorPresenter(model: editor, height: 25, scrollTop: 50, lineHeight: 10, lineOverdrawMargin: 0)
expectValues lineNumberStateForScreenRow(presenter, 5), {screenRow: 5, bufferRow: 3, softWrapped: true}
expectValues lineNumberStateForScreenRow(presenter, 6), {screenRow: 6, bufferRow: 3, softWrapped: true}
expectValues lineNumberStateForScreenRow(presenter, 7), {screenRow: 7, bufferRow: 4, softWrapped: false}
describe ".decorationClasses", ->
it "adds decoration classes to the relevant line number state objects, both initially and when decorations change", ->
marker1 = editor.markBufferRange([[4, 0], [6, 2]], invalidate: 'touch')

View File

@ -237,22 +237,29 @@ class TextEditorPresenter
updateLineNumbersState: ->
startRow = @computeStartRow()
endRow = @computeEndRow()
lastBufferRow = null
wrapCount = 0
visibleLineNumberIds = {}
if startRow > 0
rowBeforeStartRow = startRow - 1
lastBufferRow = @model.bufferRowForScreenRow(rowBeforeStartRow)
wrapCount = rowBeforeStartRow - @model.screenRowForBufferRow(lastBufferRow)
else
lastBufferRow = null
wrapCount = 0
for bufferRow, i in @model.bufferRowsForScreenRows(startRow, endRow - 1)
screenRow = startRow + i
top = screenRow * @lineHeight
if bufferRow is lastBufferRow
wrapCount++
softWrapped = true
id = bufferRow + '-' + wrapCount
softWrapped = true
else
wrapCount = 0
softWrapped = false
lastBufferRow = bufferRow
id = bufferRow
wrapCount = 0
lastBufferRow = bufferRow
softWrapped = false
screenRow = startRow + i
top = screenRow * @lineHeight
decorationClasses = @lineNumberDecorationClassesForRow(screenRow)
foldable = @model.isFoldableAtScreenRow(screenRow)