diff --git a/package.json b/package.json index 526857445..4400d8f15 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "service-hub": "^0.7.0", "source-map-support": "^0.3.2", "temp": "0.8.1", - "text-buffer": "9.0.0", + "text-buffer": "9.1.0", "typescript-simple": "1.0.0", "underscore-plus": "^1.6.6", "yargs": "^3.23.0" diff --git a/spec/text-editor-presenter-spec.coffee b/spec/text-editor-presenter-spec.coffee index af0260b95..c770c74c1 100644 --- a/spec/text-editor-presenter-spec.coffee +++ b/spec/text-editor-presenter-spec.coffee @@ -2805,16 +2805,20 @@ describe "TextEditorPresenter", -> editor.setSoftWrapped(true) editor.setDefaultCharWidth(1) editor.setEditorWidthInChars(51) - presenter = buildPresenter(explicitHeight: 25, scrollTop: 30, lineHeight: 10, tileSize: 2) + presenter = buildPresenter(explicitHeight: 25, scrollTop: 30, lineHeight: 10, tileSize: 3) + presenter.setScreenRowsToMeasure([9, 11]) - expect(lineNumberStateForScreenRow(presenter, 1)).toBeUndefined() - expectValues lineNumberStateForScreenRow(presenter, 2), {screenRow: 2, bufferRow: 2, softWrapped: false} + expect(lineNumberStateForScreenRow(presenter, 2)).toBeUndefined() expectValues lineNumberStateForScreenRow(presenter, 3), {screenRow: 3, bufferRow: 3, softWrapped: false} expectValues lineNumberStateForScreenRow(presenter, 4), {screenRow: 4, bufferRow: 3, softWrapped: true} expectValues lineNumberStateForScreenRow(presenter, 5), {screenRow: 5, bufferRow: 4, softWrapped: false} expectValues lineNumberStateForScreenRow(presenter, 6), {screenRow: 6, bufferRow: 7, softWrapped: false} expectValues lineNumberStateForScreenRow(presenter, 7), {screenRow: 7, bufferRow: 8, softWrapped: false} - expect(lineNumberStateForScreenRow(presenter, 8)).toBeUndefined() + expectValues lineNumberStateForScreenRow(presenter, 8), {screenRow: 8, bufferRow: 8, softWrapped: true} + expect(lineNumberStateForScreenRow(presenter, 9)).toBeUndefined() + expect(lineNumberStateForScreenRow(presenter, 10)).toBeUndefined() + expect(lineNumberStateForScreenRow(presenter, 11)).toBeUndefined() + expect(lineNumberStateForScreenRow(presenter, 12)).toBeUndefined() it "updates when the editor's content changes", -> editor.foldBufferRow(4) diff --git a/src/text-editor-component.coffee b/src/text-editor-component.coffee index 8c20055ed..048033a20 100644 --- a/src/text-editor-component.coffee +++ b/src/text-editor-component.coffee @@ -491,7 +491,7 @@ class TextEditorComponent screenPosition = Point.fromObject(screenPosition) screenPosition = @editor.clipScreenPosition(screenPosition) if clip - unless @presenter.isRowVisible(screenPosition.row) + unless @presenter.isRowRendered(screenPosition.row) @presenter.setScreenRowsToMeasure([screenPosition.row]) unless @linesComponent.lineNodeForScreenRow(screenPosition.row)? @@ -503,7 +503,7 @@ class TextEditorComponent screenPositionForPixelPosition: (pixelPosition) -> row = @linesYardstick.measuredRowForPixelPosition(pixelPosition) - if row? and not @presenter.isRowVisible(row) + if row? and not @presenter.isRowRendered(row) @presenter.setScreenRowsToMeasure([row]) @updateSyncPreMeasurement() @@ -513,9 +513,9 @@ class TextEditorComponent pixelRectForScreenRange: (screenRange) -> rowsToMeasure = [] - unless @presenter.isRowVisible(screenRange.start.row) + unless @presenter.isRowRendered(screenRange.start.row) rowsToMeasure.push(screenRange.start.row) - unless @presenter.isRowVisible(screenRange.end.row) + unless @presenter.isRowRendered(screenRange.end.row) rowsToMeasure.push(screenRange.end.row) if rowsToMeasure.length > 0 diff --git a/src/text-editor-presenter.coffee b/src/text-editor-presenter.coffee index 1a7723128..14ed2bdc9 100644 --- a/src/text-editor-presenter.coffee +++ b/src/text-editor-presenter.coffee @@ -601,42 +601,19 @@ class TextEditorPresenter tileState.lineNumbers ?= {} visibleLineNumberIds = {} - startRow = screenRows[screenRows.length - 1] - endRow = Math.min(screenRows[0] + 1, @model.getScreenLineCount()) + for screenRow in screenRows when @isRowRendered(screenRow) + lineId = @linesByScreenRow.get(screenRow).id + {bufferRow, softWrappedAtStart: softWrapped} = @displayLayer.softWrapDescriptorForScreenRow(screenRow) + foldable = not softWrapped and @model.isFoldableAtBufferRow(bufferRow) + decorationClasses = @lineNumberDecorationClassesForRow(screenRow) + blockDecorationsBeforeCurrentScreenRowHeight = @lineTopIndex.pixelPositionAfterBlocksForRow(screenRow) - @lineTopIndex.pixelPositionBeforeBlocksForRow(screenRow) + blockDecorationsHeight = blockDecorationsBeforeCurrentScreenRowHeight + if screenRow % @tileSize isnt 0 + blockDecorationsAfterPreviousScreenRowHeight = @lineTopIndex.pixelPositionBeforeBlocksForRow(screenRow) - @lineHeight - @lineTopIndex.pixelPositionAfterBlocksForRow(screenRow - 1) + blockDecorationsHeight += blockDecorationsAfterPreviousScreenRowHeight - if startRow > 0 - rowBeforeStartRow = startRow - 1 - lastBufferRow = @model.bufferRowForScreenRow(rowBeforeStartRow) - else - lastBufferRow = null - - if endRow > startRow - bufferRows = @model.bufferRowsForScreenRows(startRow, endRow - 1) - previousBufferRow = -1 - foldable = false - for bufferRow, i in bufferRows - # don't compute foldability more than once per buffer row - if previousBufferRow isnt bufferRow - foldable = @model.isFoldableAtBufferRow(bufferRow) - previousBufferRow = bufferRow - - if bufferRow is lastBufferRow - softWrapped = true - else - lastBufferRow = bufferRow - softWrapped = false - - screenRow = startRow + i - lineId = @linesByScreenRow.get(screenRow).id - decorationClasses = @lineNumberDecorationClassesForRow(screenRow) - blockDecorationsBeforeCurrentScreenRowHeight = @lineTopIndex.pixelPositionAfterBlocksForRow(screenRow) - @lineTopIndex.pixelPositionBeforeBlocksForRow(screenRow) - blockDecorationsHeight = blockDecorationsBeforeCurrentScreenRowHeight - if screenRow % @tileSize isnt 0 - blockDecorationsAfterPreviousScreenRowHeight = @lineTopIndex.pixelPositionBeforeBlocksForRow(screenRow) - @lineHeight - @lineTopIndex.pixelPositionAfterBlocksForRow(screenRow - 1) - blockDecorationsHeight += blockDecorationsAfterPreviousScreenRowHeight - - tileState.lineNumbers[lineId] = {screenRow, bufferRow, softWrapped, decorationClasses, foldable, blockDecorationsHeight} - visibleLineNumberIds[lineId] = true + tileState.lineNumbers[lineId] = {screenRow, bufferRow, softWrapped, decorationClasses, foldable, blockDecorationsHeight} + visibleLineNumberIds[lineId] = true for id of tileState.lineNumbers delete tileState.lineNumbers[id] unless visibleLineNumberIds[id] @@ -1548,8 +1525,8 @@ class TextEditorPresenter getVisibleRowRange: -> [@startRow, @endRow] - isRowVisible: (row) -> - @startRow <= row < @endRow + isRowRendered: (row) -> + @getStartTileRow() <= row < @constrainRow(@getEndTileRow() + @tileSize) isOpenTagCode: (tagCode) -> @displayLayer.isOpenTagCode(tagCode)