Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Don't build soft-wrapped line segments beyond the requested endScreenRow
Browse files Browse the repository at this point in the history
Co-Authored-By: Antonio Scandurra <as-cii@github.com>
  • Loading branch information
Nathan Sobo and Antonio Scandurra committed Jun 5, 2019
1 parent 6e38150 commit 57cd849
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/screen-line-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ class ScreenLineBuilder {
this.bufferRow = this.displayLayer.findBoundaryPrecedingBufferRow(this.bufferRow)
this.screenRow = this.displayLayer.translateBufferPositionWithSpatialIndex(Point(this.bufferRow, 0)).row

let endBufferRow;
([endBufferRow, endScreenRow] = this.displayLayer.findBoundaryFollowingScreenRow(endScreenRow))
const endBufferRow = this.displayLayer.translateScreenPositionWithSpatialIndex(Point(endScreenRow, Infinity)).row

let didSeekDecorationIterator = false
const decorationIterator = this.displayLayer.buffer.languageMode.buildHighlightIterator()
Expand All @@ -55,10 +54,12 @@ class ScreenLineBuilder {
if (nextHunk.newStart.row === this.screenRow) {
if (nextHunk.newEnd.row > nextHunk.newStart.row) {
this.screenRow++
this.bufferColumn = nextHunk.oldEnd.column
hunkIndex++
continue screenRowLoop
} else {
this.bufferRow = nextHunk.oldEnd.row
this.bufferColumn = nextHunk.oldEnd.column
}
}

Expand All @@ -85,6 +86,12 @@ class ScreenLineBuilder {
this.scopeIdsToReopen = decorationIterator.seek(Point(this.bufferRow, this.bufferColumn), endBufferRow)
}

var prevCachedScreenLine = this.displayLayer.cachedScreenLines[this.screenRow - 1]
if (prevCachedScreenLine && prevCachedScreenLine.softWrapIndent >= 0) {
this.inLeadingWhitespace = false
if (prevCachedScreenLine.softWrapIndent > 0) this.emitIndentWhitespace(prevCachedScreenLine.softWrapIndent)
}

// This loop may visit multiple buffer rows if there are folds and
// multiple screen rows if there are soft wraps.
while (this.bufferColumn <= this.bufferLine.length) {
Expand All @@ -93,6 +100,9 @@ class ScreenLineBuilder {
while (nextHunk && nextHunk.oldStart.row === this.bufferRow && nextHunk.oldStart.column === this.bufferColumn) {
if (this.displayLayer.isSoftWrapHunk(nextHunk)) {
this.emitSoftWrap(nextHunk)
if (this.screenRow === endScreenRow) {
break screenRowLoop
}
} else {
this.emitFold(nextHunk, decorationIterator, endBufferRow)
}
Expand Down Expand Up @@ -248,7 +258,7 @@ class ScreenLineBuilder {
this.emitCloseTag(this.getBuiltInScopeId(this.currentBuiltInClassNameFlags))
this.currentBuiltInClassNameFlags = 0
this.closeContainingScopes()
this.emitNewline()
this.emitNewline(nextHunk.newEnd.column)
this.emitIndentWhitespace(nextHunk.newEnd.column)
}

Expand Down Expand Up @@ -280,11 +290,12 @@ class ScreenLineBuilder {
this.bufferColumn = 0
}

emitNewline () {
emitNewline (softWrapIndent = -1) {
const screenLine = {
id: nextScreenLineId++,
lineText: this.currentScreenLineText,
tags: this.currentScreenLineTags
tags: this.currentScreenLineTags,
softWrapIndent
}
this.pushScreenLine(screenLine)
this.displayLayer.cachedScreenLines[this.screenRow] = screenLine
Expand Down

0 comments on commit 57cd849

Please # to comment.