diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index 47c028c78..9c512f3f7 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -478,6 +478,8 @@ fdescribe "Editor", -> describe "when scrolling vertically", -> describe "whes scrolling less than the editor's height", -> it "draws new lines and removes old lines when the last visible line will exceed the last rendered line", -> + 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:first').text()).toBe buffer.lineForRow(0) @@ -566,7 +568,7 @@ fdescribe "Editor", -> spyOn(editor, "scrollTo") describe "when the change the precedes the first rendered row", -> - fffit "inserts and removes rendered lines to account for upstream change", -> + it "inserts and removes rendered lines to account for upstream change", -> console.log "-------------------" editor.scrollToBottom() expect(editor.visibleLines.find(".line:first").text()).toBe buffer.lineForRow(6) diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 4b3ea5846..8c3162316 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -311,20 +311,20 @@ class Editor extends View console.log "Rendering lines %d-%d", renderFrom, renderTo if firstVisibleScreenRow < @firstRenderedScreenRow - @removeLineElements(Math.max(@firstRenderedScreenRow, renderTo), @lastRenderedScreenRow) + @removeLineElements(Math.max(@firstRenderedScreenRow, renderTo + 1), @lastRenderedScreenRow) @lastRenderedScreenRow = renderTo - @firstRenderedScreenRow = renderFrom - newLines = @buildLineElements(renderFrom, Math.min(@firstRenderedScreenRow, renderTo)) + newLines = @buildLineElements(renderFrom, Math.min(@firstRenderedScreenRow - 1, renderTo)) @insertLineElements(renderFrom, newLines) + @firstRenderedScreenRow = renderFrom adjustPadding = true if lastVisibleScreenRow > @lastRenderedScreenRow - @removeLineElements(@firstRenderedScreenRow, Math.min(@lastRenderedScreenRow, renderFrom)) + @removeLineElements(@firstRenderedScreenRow, Math.min(@lastRenderedScreenRow, renderFrom - 1)) if @firstRenderedScreenRow >= 0 @firstRenderedScreenRow = renderFrom - @lastRenderedScreenRow = renderTo - startRowOfNewLines = Math.max(@lastRenderedScreenRow, renderFrom) + startRowOfNewLines = Math.max(@lastRenderedScreenRow + 1, renderFrom) newLines = @buildLineElements(startRowOfNewLines, renderTo) @insertLineElements(startRowOfNewLines, newLines) + @lastRenderedScreenRow = renderTo adjustPadding = true if adjustPadding @@ -548,9 +548,12 @@ class Editor extends View @spliceLineElements(startRow, endRow - startRow + 1, lineElements) removeLineElements: (startRow, endRow) -> + console.log "removeLineElements", startRow, endRow @spliceLineElements(startRow, endRow - startRow + 1) spliceLineElements: (startScreenRow, rowCount, lineElements) -> + throw new Error("Splicing at a negative start row: #{startScreenRow}") if startScreenRow < 0 + if startScreenRow < @firstRenderedScreenRow startRow = 0 else