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

Commit

Permalink
Merge pull request #312 from atom/ns-as/faster-long-lines
Browse files Browse the repository at this point in the history
Don't build soft-wrapped line segments until they become visible on screen
  • Loading branch information
Nathan Sobo authored Jun 6, 2019
2 parents 6e38150 + f845011 commit 83cba39
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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
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 83cba39

Please # to comment.