mirror of
https://github.com/atom/atom.git
synced 2026-01-24 22:38:20 -05:00
🐎 Mark soft-wrapped lines in TokenizedLine
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user