From cd7787028680c67b1b7a030d63d4bcf97c4b0ca2 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 3 Feb 2015 13:30:42 -0700 Subject: [PATCH] In presenter, handle the first line being soft-wrapped Signed-off-by: Max Brunsfeld --- spec/text-editor-presenter-spec.coffee | 9 +++++++++ src/text-editor-presenter.coffee | 23 +++++++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/spec/text-editor-presenter-spec.coffee b/spec/text-editor-presenter-spec.coffee index 08eb84b52..6e8aa547b 100644 --- a/spec/text-editor-presenter-spec.coffee +++ b/spec/text-editor-presenter-spec.coffee @@ -1522,6 +1522,15 @@ describe "TextEditorPresenter", -> expect(lineNumberStateForScreenRow(presenter, 7)).toBeDefined() expect(lineNumberStateForScreenRow(presenter, 8)).toBeUndefined() + it "correctly handles the first screen line being soft-wrapped", -> + editor.setSoftWrapped(true) + editor.setEditorWidthInChars(30) + presenter = new TextEditorPresenter(model: editor, height: 25, scrollTop: 50, lineHeight: 10, lineOverdrawMargin: 0) + + expectValues lineNumberStateForScreenRow(presenter, 5), {screenRow: 5, bufferRow: 3, softWrapped: true} + expectValues lineNumberStateForScreenRow(presenter, 6), {screenRow: 6, bufferRow: 3, softWrapped: true} + expectValues lineNumberStateForScreenRow(presenter, 7), {screenRow: 7, bufferRow: 4, softWrapped: false} + describe ".decorationClasses", -> it "adds decoration classes to the relevant line number state objects, both initially and when decorations change", -> marker1 = editor.markBufferRange([[4, 0], [6, 2]], invalidate: 'touch') diff --git a/src/text-editor-presenter.coffee b/src/text-editor-presenter.coffee index 6655280c2..4b0aefa1a 100644 --- a/src/text-editor-presenter.coffee +++ b/src/text-editor-presenter.coffee @@ -237,22 +237,29 @@ class TextEditorPresenter updateLineNumbersState: -> startRow = @computeStartRow() endRow = @computeEndRow() - lastBufferRow = null - wrapCount = 0 visibleLineNumberIds = {} + if startRow > 0 + rowBeforeStartRow = startRow - 1 + lastBufferRow = @model.bufferRowForScreenRow(rowBeforeStartRow) + wrapCount = rowBeforeStartRow - @model.screenRowForBufferRow(lastBufferRow) + else + lastBufferRow = null + wrapCount = 0 + for bufferRow, i in @model.bufferRowsForScreenRows(startRow, endRow - 1) - screenRow = startRow + i - top = screenRow * @lineHeight if bufferRow is lastBufferRow wrapCount++ - softWrapped = true id = bufferRow + '-' + wrapCount + softWrapped = true else - wrapCount = 0 - softWrapped = false - lastBufferRow = bufferRow id = bufferRow + wrapCount = 0 + lastBufferRow = bufferRow + softWrapped = false + + screenRow = startRow + i + top = screenRow * @lineHeight decorationClasses = @lineNumberDecorationClassesForRow(screenRow) foldable = @model.isFoldableAtScreenRow(screenRow)