From 419d7b1dec0f7f5359c2fe377bf1ffb0079fe667 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Mon, 4 Jun 2012 17:45:05 -0700 Subject: [PATCH] Use renderTo and renderFrom (instead of firstVisible/lastVisible) to adjust visible lines. Fix specs that had wrong assumptions, --- spec/app/editor-spec.coffee | 39 ++++++++++++++++++++++++------------- src/app/editor.coffee | 10 +++++----- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index aa2a32c36..d6ae76fdb 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -537,28 +537,28 @@ describe "Editor", -> expect(editor.visibleLines.find('.line').length).toBe 8 editor.scrollTop(editor.lineHeight * 1.5) - expect(editor.visibleLines.find('.line').length).toBe 8 + expect(editor.visibleLines.find('.line').length).toBe 9 expect(editor.visibleLines.find('.line:first').text()).toBe buffer.lineForRow(0) - expect(editor.visibleLines.find('.line:last').text()).toBe buffer.lineForRow(7) + expect(editor.visibleLines.find('.line:last').text()).toBe buffer.lineForRow(8) - editor.scrollTop(editor.lineHeight * 3.5) # first visible row will be 3, last will be 8 + editor.scrollTop(editor.lineHeight * 3.5) expect(editor.visibleLines.find('.line').length).toBe 10 expect(editor.visibleLines.find('.line:first').text()).toBe buffer.lineForRow(1) expect(editor.visibleLines.find('.line:last').html()).toBe ' ' # line 10 is blank expect(editor.gutter.find('.line-number:first').text()).toBe '2' expect(editor.gutter.find('.line-number:last').text()).toBe '11' + editor.scrollTop(editor.lineHeight * 5.5) + expect(editor.visibleLines.find('.line').length).toBe 10 + expect(editor.visibleLines.find('.line:first').text()).toBe buffer.lineForRow(3) + expect(editor.visibleLines.find('.line:last').text()).toBe buffer.lineForRow(12) + expect(editor.gutter.find('.line-number:first').text()).toBe '4' + expect(editor.gutter.find('.line-number:last').text()).toBe '13' + # here we don't scroll far enough to trigger additional rendering - editor.scrollTop(editor.lineHeight * 5.5) # first visible row will be 5, last will be 10 + editor.scrollTop(editor.lineHeight * 7.5) expect(editor.visibleLines.find('.line').length).toBe 10 - expect(editor.visibleLines.find('.line:first').text()).toBe buffer.lineForRow(1) - expect(editor.visibleLines.find('.line:last').html()).toBe ' ' # line 10 is blank - expect(editor.gutter.find('.line-number:first').text()).toBe '2' - expect(editor.gutter.find('.line-number:last').text()).toBe '11' - - editor.scrollTop(editor.lineHeight * 7.5) # first visible row is 7, last will be 12 - expect(editor.visibleLines.find('.line').length).toBe 8 - expect(editor.visibleLines.find('.line:first').text()).toBe buffer.lineForRow(5) + expect(editor.visibleLines.find('.line:first').text()).toBe buffer.lineForRow(3) expect(editor.visibleLines.find('.line:last').text()).toBe buffer.lineForRow(12) editor.scrollTop(editor.lineHeight * 3.5) # first visible row will be 3, last will be 8 @@ -690,6 +690,17 @@ describe "Editor", -> expect(editor.visibleLines.find(".line:first").text()).toBe buffer.lineForRow(0) expect(editor.visibleLines.find(".line:last").text()).toBe buffer.lineForRow(6) + describe "when folding leaves less then a screen worth of text (regression)", -> + it "renders lines properly", -> + editor.lineOverdraw = 1 + editor.clearVisibleLines() + editor.attachToDom(heightInLines: 5) + editor.renderer.toggleFoldAtBufferRow(4) + editor.renderer.toggleFoldAtBufferRow(0) + + expect(editor.visibleLines.find('.line').length).toBe 1 + expect(editor.visibleLines.find('.line').text()).toBe buffer.lineForRow(0) + describe "gutter rendering", -> beforeEach -> editor.attachToDom(heightInLines: 5.5) @@ -701,9 +712,9 @@ describe "Editor", -> # here we don't scroll far enough to trigger additional rendering editor.scrollTop(editor.lineHeight * 1.5) - expect(editor.visibleLines.find('.line').length).toBe 8 + expect(editor.visibleLines.find('.line').length).toBe 9 expect(editor.gutter.find('.line-number:first').text()).toBe "1" - expect(editor.gutter.find('.line-number:last').text()).toBe "8" + expect(editor.gutter.find('.line-number:last').text()).toBe "9" editor.scrollTop(editor.lineHeight * 3.5) expect(editor.visibleLines.find('.line').length).toBe 10 diff --git a/src/app/editor.coffee b/src/app/editor.coffee index a66764d1e..a9b00bcb0 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -233,7 +233,7 @@ class Editor extends View afterAttach: (onDom) -> return if @attached or not onDom @attached = true - @clearLines() + @clearVisibleLines() @subscribeToFontSize() @calculateDimensions() @setMaxLineLength() if @softWrap @@ -291,10 +291,10 @@ class Editor extends View @scrollTop() + @scrollView.height() renderVisibleLines: -> - @clearLines() + @clearVisibleLines() @updateVisibleLines() - clearLines: -> + clearVisibleLines: -> @lineCache = [] @visibleLines.find('.line').remove() @@ -307,7 +307,7 @@ class Editor extends View renderFrom = Math.max(0, firstVisibleScreenRow - @lineOverdraw) renderTo = Math.min(@getLastScreenRow(), lastVisibleScreenRow + @lineOverdraw) - if firstVisibleScreenRow < @firstRenderedScreenRow + if renderFrom < @firstRenderedScreenRow @removeLineElements(Math.max(@firstRenderedScreenRow, renderTo + 1), @lastRenderedScreenRow) @lastRenderedScreenRow = renderTo newLines = @buildLineElements(renderFrom, Math.min(@firstRenderedScreenRow - 1, renderTo)) @@ -315,7 +315,7 @@ class Editor extends View @firstRenderedScreenRow = renderFrom renderedLines = true - if lastVisibleScreenRow > @lastRenderedScreenRow + if renderTo > @lastRenderedScreenRow if 0 <= @firstRenderedScreenRow < renderFrom @removeLineElements(@firstRenderedScreenRow, Math.min(@lastRenderedScreenRow, renderFrom - 1)) @firstRenderedScreenRow = renderFrom