diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index 169aff40f..1345275d4 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -466,7 +466,6 @@ fdescribe "Editor", -> describe "when the editor is attached and some lines at the end of the buffer are not visible on screen", -> beforeEach -> editor.attachToDom(heightInLines: 5.5) - console.log "--------------------" it "only renders the visible lines plus the overdrawn lines, setting the padding-bottom of the lines element to account for the missing lines", -> expect(editor.visibleLines.find('.line').length).toBe 8 @@ -552,11 +551,9 @@ fdescribe "Editor", -> expect(editor.visibleLines.find('.line:eq(7)').text()).toBe editor.buffer.lineForRow(7) it "renders correctly when scrolling after text is removed from buffer", -> - console.log "lastRenderedScreenRow before delete", editor.lastRenderedScreenRow editor.buffer.delete([[0,0],[1,0]]) expect(editor.visibleLines.find('.line:eq(0)').text()).toBe editor.buffer.lineForRow(0) expect(editor.visibleLines.find('.line:eq(5)').text()).toBe editor.buffer.lineForRow(5) - console.log "lastRenderedScreenRow after delete", editor.lastRenderedScreenRow editor.scrollTop(3 * editor.lineHeight) expect(editor.visibleLines.find('.line:first').text()).toBe editor.buffer.lineForRow(1) @@ -569,36 +566,35 @@ fdescribe "Editor", -> describe "when the change the precedes the first rendered row", -> it "inserts and removes rendered lines to account for upstream change", -> - console.log "-------------------" editor.scrollToBottom() + expect(editor.visibleLines.find(".line").length).toBe 7 expect(editor.visibleLines.find(".line:first").text()).toBe buffer.lineForRow(6) expect(editor.visibleLines.find(".line:last").text()).toBe buffer.lineForRow(12) buffer.change([[1,0], [3,0]], "1\n2\n3\n") - expect(editor.visibleLines.find(".line").length).toBe 7 - expect(editor.visibleLines.find(".line:first").text()).toBe buffer.lineForRow(7) + expect(editor.visibleLines.find(".line").length).toBe 8 + expect(editor.visibleLines.find(".line:first").text()).toBe buffer.lineForRow(6) expect(editor.visibleLines.find(".line:last").text()).toBe buffer.lineForRow(13) - editor.visibleLines.find('.line').each -> console.log $(this).text() - - describe "when the change straddles the first rendered row", -> it "doesn't render rows that were not previously rendered", -> - editor.scrollBottom(editor.scrollView.prop('scrollHeight')) - expect(editor.visibleLines.find(".line:first").text()).toBe buffer.lineForRow(8) + editor.scrollToBottom() + + expect(editor.visibleLines.find(".line").length).toBe 7 + expect(editor.visibleLines.find(".line:first").text()).toBe buffer.lineForRow(6) 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 5 - expect(editor.visibleLines.find(".line:first").text()).toBe buffer.lineForRow(8) - expect(editor.visibleLines.find(".line:last").text()).toBe buffer.lineForRow(12) + expect(editor.visibleLines.find(".line").length).toBe 10 + expect(editor.visibleLines.find(".line:first").text()).toBe buffer.lineForRow(6) + expect(editor.visibleLines.find(".line:last").text()).toBe buffer.lineForRow(15) - describe "when the change the straddles the last rendered row", -> + describe "when the change straddles the last rendered row", -> it "doesn't render rows that were not previously rendered", -> buffer.change([[2,0], [7,0]], "2\n3\n4\n5\n6\n7\n8\n") - expect(editor.visibleLines.find(".line").length).toBe 5 + expect(editor.visibleLines.find(".line").length).toBe 7 expect(editor.visibleLines.find(".line:first").text()).toBe buffer.lineForRow(0) - expect(editor.visibleLines.find(".line:last").text()).toBe buffer.lineForRow(4) + expect(editor.visibleLines.find(".line:last").text()).toBe buffer.lineForRow(6) describe "when the change the follows the last rendered row", -> it "does not change the rendered lines", -> @@ -609,45 +605,46 @@ fdescribe "Editor", -> describe "when lines are removed", -> beforeEach -> - editor.attachToDom() - setEditorHeightInLines(editor, 5) + editor.attachToDom(heightInLines: 5) spyOn(editor, "scrollTo") describe "when the change the precedes the first rendered row", -> it "removes rendered lines to account for upstream change", -> - editor.scrollBottom(editor.scrollView.prop('scrollHeight')) - expect(editor.visibleLines.find(".line:first").text()).toBe buffer.lineForRow(8) + editor.scrollToBottom() + expect(editor.visibleLines.find(".line").length).toBe 7 + expect(editor.visibleLines.find(".line:first").text()).toBe buffer.lineForRow(6) expect(editor.visibleLines.find(".line:last").text()).toBe buffer.lineForRow(12) buffer.change([[1,0], [2,0]], "") - expect(editor.visibleLines.find(".line").length).toBe 4 - expect(editor.visibleLines.find(".line:first").text()).toBe buffer.lineForRow(8) + expect(editor.visibleLines.find(".line").length).toBe 6 + expect(editor.visibleLines.find(".line:first").text()).toBe buffer.lineForRow(6) expect(editor.visibleLines.find(".line:last").text()).toBe buffer.lineForRow(11) describe "when the change straddles the first rendered row", -> it "renders the correct rows", -> - editor.scrollBottom(editor.scrollView.prop('scrollHeight')) - expect(editor.visibleLines.find(".line:first").text()).toBe buffer.lineForRow(8) + editor.scrollToBottom() + expect(editor.visibleLines.find(".line").length).toBe 7 + expect(editor.visibleLines.find(".line:first").text()).toBe buffer.lineForRow(6) expect(editor.visibleLines.find(".line:last").text()).toBe buffer.lineForRow(12) buffer.change([[7,0], [11,0]], "1\n2\n") - expect(editor.visibleLines.find(".line").length).toBe 3 - expect(editor.visibleLines.find(".line:first").text()).toBe buffer.lineForRow(8) + expect(editor.visibleLines.find(".line").length).toBe 5 + expect(editor.visibleLines.find(".line:first").text()).toBe buffer.lineForRow(6) expect(editor.visibleLines.find(".line:last").text()).toBe buffer.lineForRow(10) - describe "when the change the straddles the last rendered row", -> + describe "when the change straddles the last rendered row", -> it "renders the correct rows", -> buffer.change([[2,0], [7,0]], "") - expect(editor.visibleLines.find(".line").length).toBe 5 + expect(editor.visibleLines.find(".line").length).toBe 7 expect(editor.visibleLines.find(".line:first").text()).toBe buffer.lineForRow(0) - expect(editor.visibleLines.find(".line:last").text()).toBe buffer.lineForRow(4) + expect(editor.visibleLines.find(".line:last").text()).toBe buffer.lineForRow(6) describe "when the change the follows the last rendered row", -> it "does not change the rendered lines", -> - buffer.change([[12,0], [12,0]], "") - expect(editor.visibleLines.find(".line").length).toBe 5 + buffer.change([[10,0], [12,0]], "") + expect(editor.visibleLines.find(".line").length).toBe 7 expect(editor.visibleLines.find(".line:first").text()).toBe buffer.lineForRow(0) - expect(editor.visibleLines.find(".line:last").text()).toBe buffer.lineForRow(4) + expect(editor.visibleLines.find(".line:last").text()).toBe buffer.lineForRow(6) describe "gutter rendering", -> beforeEach -> diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 8c3162316..6682373ff 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -308,7 +308,9 @@ class Editor extends View renderFrom = Math.max(0, firstVisibleScreenRow - @lineOverdraw) renderTo = Math.min(@getLastScreenRow(), lastVisibleScreenRow + @lineOverdraw) - console.log "Rendering lines %d-%d", renderFrom, renderTo + + console.log "Lines we have: %d-%d", @firstRenderedScreenRow, @lastRenderedScreenRow + console.log "Lines we want: %d-%d", renderFrom, renderTo if firstVisibleScreenRow < @firstRenderedScreenRow @removeLineElements(Math.max(@firstRenderedScreenRow, renderTo + 1), @lastRenderedScreenRow) @@ -319,7 +321,8 @@ class Editor extends View adjustPadding = true if lastVisibleScreenRow > @lastRenderedScreenRow - @removeLineElements(@firstRenderedScreenRow, Math.min(@lastRenderedScreenRow, renderFrom - 1)) if @firstRenderedScreenRow >= 0 + if 0 <= @firstRenderedScreenRow < renderFrom + @removeLineElements(@firstRenderedScreenRow, Math.min(@lastRenderedScreenRow, renderFrom - 1)) @firstRenderedScreenRow = renderFrom startRowOfNewLines = Math.max(@lastRenderedScreenRow + 1, renderFrom) newLines = @buildLineElements(startRowOfNewLines, renderTo) @@ -336,46 +339,6 @@ class Editor extends View @visibleLines.css('padding-bottom', paddingBottom) @gutter.lineNumbers.css('padding-bottom', paddingBottom) - # if firstVisibleScreenRow < @firstRenderedScreenRow - # newLinesEndRow = Math.min(@firstRenderedScreenRow - 1, lastVisibleScreenRow) - # lineElements = @buildLineElements(renderFrom, newLinesEndRow) - # console.log "inserting", renderFrom, "to", newLinesEndRow - # @insertLineElements(renderFrom, lineElements) - # @firstRenderedScreenRow = renderFrom - # adjustPaddingTop = true - - # if renderTo < @lastRenderedScreenRow - # console.log "removing", renderTo + 1, "to", @lastRenderedScreenRow - # @removeLineElements(renderTo + 1, @lastRenderedScreenRow) - # adjustPaddingBottom = true - - # @lastRenderedScreenRow = renderTo - - # if lastVisibleScreenRow > @lastRenderedScreenRow - # newLinesStartRow = Math.max(@lastRenderedScreenRow + 1, renderFrom) - # lineElements = @buildLineElements(newLinesStartRow, renderTo) - # console.log "inserting", newLinesStartRow, "to", renderTo - # @insertLineElements(newLinesStartRow, lineElements) - # @lastRenderedScreenRow = renderTo - # adjustPaddingBottom = true - - # if 0 <= @firstRenderedScreenRow < renderFrom - # console.log "removing", @firstRenderedScreenRow, "to", renderFrom - 1 - # @removeLineElements(@firstRenderedScreenRow, renderFrom - 1) - # adjustPaddingTop = true - - # @firstRenderedScreenRow = renderFrom - - # if adjustPaddingTop - # paddingTop = @firstRenderedScreenRow * @lineHeight - # @visibleLines.css('padding-top', paddingTop) - # @gutter.lineNumbers.css('padding-top', paddingTop) - - # if adjustPaddingBottom - # paddingBottom = (@getLastScreenRow() - @lastRenderedScreenRow) * @lineHeight - # @visibleLines.css('padding-bottom', paddingBottom) - # @gutter.lineNumbers.css('padding-bottom', paddingBottom) - getFirstVisibleScreenRow: -> Math.floor(@scrollTop() / @lineHeight) @@ -488,6 +451,8 @@ class Editor extends View oldScreenRange = e.oldRange newScreenRange = e.newRange + @renderer.logLines() + @compositeCursor.updateBufferPosition() unless e.bufferChanged if @attached @@ -510,13 +475,14 @@ class Editor extends View oldScreenRange.end.row += delta newScreenRange.start.row = Math.max(newScreenRange.start.row, @firstRenderedScreenRow) + newScreenRange.end.row = Math.min(newScreenRange.end.row, @lastRenderedScreenRow) oldScreenRange.start.row = Math.max(oldScreenRange.start.row, @firstRenderedScreenRow) + oldScreenRange.end.row = Math.min(oldScreenRange.end.row, @lastRenderedScreenRow) lineElements = @buildLineElements(newScreenRange.start.row, newScreenRange.end.row) @replaceLineElements(oldScreenRange.start.row, oldScreenRange.end.row, lineElements) rowDelta = newScreenRange.end.row - oldScreenRange.end.row - @lastRenderedScreenRow += rowDelta @updateVisibleLines() if rowDelta < 0 @@ -548,7 +514,6 @@ 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) ->