From c901417a195c836db0259156ee02a3a4a0e8a85c Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 31 May 2012 12:06:00 -0600 Subject: [PATCH] When lines are added, remove any that get pushed down to exceed the max allowed row This fixes issues where unfolding or pasting caused rendering artifacts below the last visible row. --- spec/app/editor-spec.coffee | 22 ++++++++++++++++++++-- src/app/editor.coffee | 5 ++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index a4295f2af..cd9dbacd5 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -470,6 +470,24 @@ describe "Editor", -> expect(editor.gutter.find('.line-number:last').text()).toBe '13' expect(editor.gutter.find('.line-number').length).toBe 13 + describe "when lines are folded, then the editor becomes shorter before the lines are unfolded", -> + it "renders the lines and line numbers correctly after unfolding", -> + fold = editor.createFold(1, 9) + setEditorHeightInLines(editor, 4.5) + + fold.destroy() + + expect(editor.visibleLines.find('.line').length).toBe 7 + expect(editor.visibleLines.find('.line:last').text()).toBe buffer.lineForRow(6) + + expect(editor.gutter.find('.line-number').length).toBe 7 + expect(editor.gutter.find('.line-number:last').text()).toBe '7' + + editor.scrollTop(3 * editor.lineHeight) + + expect(editor.visibleLines.find('.line').length).toBe 9 + expect(editor.visibleLines.find('.line:last').text()).toBe buffer.lineForRow(9) + describe "when some lines at the end of the buffer are not visible on screen", -> beforeEach -> editor.attachToDom(heightInLines: 5.5) @@ -602,9 +620,9 @@ describe "Editor", -> expect(editor.visibleLines.find(".line:last").text()).toBe buffer.lineForRow(12) buffer.change([[2,0], [7,0]], "2\n3\n4\n5\n6\n7\n8\n9\n") - expect(editor.visibleLines.find(".line").length).toBe 10 + expect(editor.visibleLines.find(".line").length).toBe 9 expect(editor.visibleLines.find(".line:first").text()).toBe buffer.lineForRow(6) - expect(editor.visibleLines.find(".line:last").text()).toBe buffer.lineForRow(15) + expect(editor.visibleLines.find(".line:last").text()).toBe buffer.lineForRow(14) describe "when the change straddles the last rendered row", -> it "doesn't render rows that were not previously rendered", -> diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 9235c406a..1d16a46fe 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -452,7 +452,7 @@ class Editor extends View firstVisibleScreenRow = @getFirstVisibleScreenRow() lastVisibleScreenRow = @getLastVisibleScreenRow() - maxEndRow = Math.max(lastVisibleScreenRow, @lastRenderedScreenRow) + maxEndRow = Math.max(lastVisibleScreenRow + @lineOverdraw, @lastRenderedScreenRow) @gutter.renderLineNumbers(@firstRenderedScreenRow, maxEndRow) if e.lineNumbersChanged @verticalScrollbarContent.height(@lineHeight * @screenLineCount()) @@ -480,6 +480,9 @@ class Editor extends View rowDelta = newScreenRange.end.row - oldScreenRange.end.row @lastRenderedScreenRow += rowDelta @updateVisibleLines() if rowDelta < 0 + if @lastRenderedScreenRow > maxEndRow + @removeLineElements(maxEndRow + 1, @lastRenderedScreenRow) + @lastRenderedScreenRow = maxEndRow buildLineElements: (startRow, endRow) -> charWidth = @charWidth