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

Don't build soft-wrapped line segments until they become visible on screen #312

Merged
merged 2 commits into from Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "text-buffer",
"version": "13.16.0",
"version": "13.16.1-0",
"description": "A container for large mutable strings with annotated regions",
"main": "./lib/text-buffer",
"scripts": {
Expand Down
21 changes: 16 additions & 5 deletions src/screen-line-builder.js
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