From 0f4bcac8d4225854c60d15cfdd915cb48f41eae0 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 19 Jan 2015 14:31:12 -0700 Subject: [PATCH] =?UTF-8?q?Add=201=20to=20the=20last=20row=20to=20ensure?= =?UTF-8?q?=20it=E2=80=99s=20visible?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/text-editor-presenter-spec.coffee | 14 +++++++++++--- src/text-editor-presenter.coffee | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/spec/text-editor-presenter-spec.coffee b/spec/text-editor-presenter-spec.coffee index e0c70cae2..697ae21bb 100644 --- a/spec/text-editor-presenter-spec.coffee +++ b/spec/text-editor-presenter-spec.coffee @@ -145,7 +145,7 @@ describe "TextEditorPresenter", -> describe "when ::clientHeight changes", -> it "updates the lines that are visible on screen", -> - presenter = new TextEditorPresenter(model: editor, clientHeight: 25, scrollTop: 25, lineHeight: 10, lineOverdrawMargin: 1) + presenter = new TextEditorPresenter(model: editor, clientHeight: 25, scrollTop: 15, lineHeight: 10, lineOverdrawMargin: 1) line5 = editor.tokenizedLineForScreenRow(5) expect(presenter.state.lines[line5.id]).toBeUndefined() @@ -200,10 +200,11 @@ describe "TextEditorPresenter", -> line3 = editor.tokenizedLineForScreenRow(3) line4 = editor.tokenizedLineForScreenRow(4) line5 = editor.tokenizedLineForScreenRow(5) + line6 = editor.tokenizedLineForScreenRow(6) expect(presenter.state.lines[line1.id]).toBeDefined() expect(presenter.state.lines[line2.id]).toBeDefined() - expect(presenter.state.lines[line3.id]).toBeUndefined() + expect(presenter.state.lines[line3.id]).toBeDefined() expect(presenter.state.lines[line4.id]).toBeUndefined() expect(presenter.state.lines[line5.id]).toBeUndefined() @@ -232,7 +233,14 @@ describe "TextEditorPresenter", -> top: 5 * 4 } - expect(presenter.state.lines[line5.id]).toBeUndefined() + expectValues presenter.state.lines[line5.id], { + screenRow: 5 + text: line5.text + tokens: line5.tokens + top: 5 * 5 + } + + expect(presenter.state.lines[line6.id]).toBeUndefined() describe "when the editor's content changes", -> it "updates the lines state accordingly", -> diff --git a/src/text-editor-presenter.coffee b/src/text-editor-presenter.coffee index 0fde3d9d3..355b8c3cb 100644 --- a/src/text-editor-presenter.coffee +++ b/src/text-editor-presenter.coffee @@ -56,7 +56,7 @@ class TextEditorPresenter Math.max(0, startRow) getEndRow: -> - endRow = @getStartRow() + Math.ceil(@clientHeight / @lineHeight) + @lineOverdrawMargin + endRow = @getStartRow() + Math.ceil(@clientHeight / @lineHeight) + 1 + @lineOverdrawMargin Math.min(@model.getScreenLineCount(), endRow) getScrollWidth: ->