diff --git a/spec/display-buffer-spec.coffee b/spec/display-buffer-spec.coffee index 7ed97f0d0..c0c7b608a 100644 --- a/spec/display-buffer-spec.coffee +++ b/spec/display-buffer-spec.coffee @@ -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) diff --git a/src/text-editor-presenter.coffee b/src/text-editor-presenter.coffee index 6d3cee2f1..64e73b770 100644 --- a/src/text-editor-presenter.coffee +++ b/src/text-editor-presenter.coffee @@ -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 diff --git a/src/tokenized-line.coffee b/src/tokenized-line.coffee index bf234b6d3..320703a9b 100644 --- a/src/tokenized-line.coffee +++ b/src/tokenized-line.coffee @@ -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]