🐎 Mark soft-wrapped lines in TokenizedLine

This commit is contained in:
Antonio Scandurra
2015-10-01 11:15:55 +02:00
parent 243dea1a1c
commit 116f92d816
3 changed files with 19 additions and 11 deletions

View File

@@ -143,6 +143,16 @@ describe "DisplayBuffer", ->
expect(displayBuffer.tokenizedLineForScreenRow(3).tokens[1].isHardTab).toBeTruthy()
describe "when a line is wrapped", ->
it "marks it as soft-wrapped", ->
displayBuffer.setEditorWidthInChars(7)
expect(displayBuffer.tokenizedLineForScreenRow(0).softWrapped).toBeFalsy()
expect(displayBuffer.tokenizedLineForScreenRow(1).softWrapped).toBeTruthy()
expect(displayBuffer.tokenizedLineForScreenRow(2).softWrapped).toBeTruthy()
expect(displayBuffer.tokenizedLineForScreenRow(3).softWrapped).toBeTruthy()
expect(displayBuffer.tokenizedLineForScreenRow(4).softWrapped).toBeTruthy()
expect(displayBuffer.tokenizedLineForScreenRow(5).softWrapped).toBeFalsy()
it "breaks soft-wrap indentation into a token for each indentation level to support indent guides", ->
tokenizedLine = displayBuffer.tokenizedLineForScreenRow(4)

View File

@@ -641,27 +641,22 @@ class TextEditorPresenter
isVisible = isVisible and @showLineNumbers
isVisible
isSoftWrappedRow: (bufferRow, screenRow) ->
return false if screenRow is 0
@model.bufferRowForScreenRow(screenRow - 1) is bufferRow
updateLineNumbersState: (tileState, screenRows) ->
tileState.lineNumbers ?= {}
visibleLineNumberIds = {}
for screenRow in screenRows
line = @model.tokenizedLineForScreenRow(screenRow)
bufferRow = @model.bufferRowForScreenRow(screenRow)
softWrapped = @isSoftWrappedRow(bufferRow, screenRow)
softWrapped = line.softWrapped
decorationClasses = @lineNumberDecorationClassesForRow(screenRow)
foldable = @model.isFoldableAtScreenRow(screenRow)
id = @model.tokenizedLineForScreenRow(screenRow).id
tileState.lineNumbers[id] = {screenRow, bufferRow, softWrapped, decorationClasses, foldable}
visibleLineNumberIds[id] = true
tileState.lineNumbers[line.id] = {screenRow, bufferRow, softWrapped, decorationClasses, foldable}
visibleLineNumberIds[line.id] = true
for id of tileState.lineNumbers
delete tileState.lineNumbers[id] unless visibleLineNumberIds[id]
for lineId of tileState.lineNumbers
delete tileState.lineNumbers[lineId] unless visibleLineNumberIds[lineId]
return

View File

@@ -34,6 +34,7 @@ class TokenizedLine
lineIsWhitespaceOnly: false
firstNonWhitespaceIndex: 0
foldable: false
softWrapped: false
constructor: (properties) ->
@id = idCounter++
@@ -420,6 +421,7 @@ class TokenizedLine
leftFragment.tabLength = @tabLength
leftFragment.firstNonWhitespaceIndex = Math.min(column, @firstNonWhitespaceIndex)
leftFragment.firstTrailingWhitespaceIndex = Math.min(column, @firstTrailingWhitespaceIndex)
leftFragment.softWrapped = @softWrapped
rightFragment = new TokenizedLine
rightFragment.tokenIterator = @tokenIterator
@@ -437,6 +439,7 @@ class TokenizedLine
rightFragment.endOfLineInvisibles = @endOfLineInvisibles
rightFragment.firstNonWhitespaceIndex = Math.max(softWrapIndent, @firstNonWhitespaceIndex - column + softWrapIndent)
rightFragment.firstTrailingWhitespaceIndex = Math.max(softWrapIndent, @firstTrailingWhitespaceIndex - column + softWrapIndent)
rightFragment.softWrapped = true
[leftFragment, rightFragment]