From acb01bba379896ba8c7b503701f79c0d8ea253d1 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 31 May 2012 17:48:50 -0600 Subject: [PATCH 1/2] Correctly render lines when destroying a fold forces an autoscroll --- spec/app/editor-spec.coffee | 52 ++++++++++++++++++++++++------------- src/app/editor.coffee | 9 ++++--- 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index 4c6d8e0f3..45db6130b 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -463,24 +463,6 @@ describe "Editor", -> otherEditor.simulateDomAttachment() expect(otherEditor.setMaxLineLength).toHaveBeenCalled() - 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) @@ -515,6 +497,40 @@ describe "Editor", -> expect(editor.visibleLines.find('.line:first').text()).toBe editor.buffer.lineForRow(1) expect(editor.visibleLines.find('.line:last').text()).toBe editor.buffer.lineForRow(10) + describe "when creating and destroying folds that are longer than the visible lines", -> + describe "when the cursor precedes the fold when it is destroyed", -> + it "renders lines and line numbers correctly", -> + fold = editor.createFold(1, 9) + fold.destroy() + + expect(editor.visibleLines.find('.line').length).toBe 8 + expect(editor.visibleLines.find('.line:last').text()).toBe buffer.lineForRow(7) + + expect(editor.gutter.find('.line-number').length).toBe 8 + expect(editor.gutter.find('.line-number:last').text()).toBe '8' + + editor.scrollTop(4 * editor.lineHeight) + + expect(editor.visibleLines.find('.line').length).toBe 10 + expect(editor.visibleLines.find('.line:last').text()).toBe buffer.lineForRow(11) + + describe "when the cursor follows the fold when it is destroyed", -> + it "renders lines and line numbers correctly", -> + fold = editor.createFold(1, 9) + editor.setCursorBufferPosition([10, 0]) + fold.destroy() + + expect(editor.visibleLines.find('.line').length).toBe 8 + expect(editor.visibleLines.find('.line:last').text()).toBe buffer.lineForRow(12) + + expect(editor.gutter.find('.line-number').length).toBe 8 + expect(editor.gutter.find('.line-number:last').text()).toBe '13' + + editor.scrollTop(4 * editor.lineHeight) + + expect(editor.visibleLines.find('.line').length).toBe 10 + expect(editor.visibleLines.find('.line:last').text()).toBe buffer.lineForRow(11) + describe "when scrolling vertically", -> describe "when 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", -> diff --git a/src/app/editor.coffee b/src/app/editor.coffee index b5302e9b4..35defc80f 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -338,8 +338,7 @@ class Editor extends View Math.floor(@scrollTop() / @lineHeight) getLastVisibleScreenRow: -> - maxVisibleScreenRow = Math.ceil((@scrollTop() + @scrollView.height()) / @lineHeight) - 1 - Math.min(maxVisibleScreenRow, @getLastScreenRow()) + Math.ceil((@scrollTop() + @scrollView.height()) / @lineHeight) - 1 highlightSelectedFolds: -> screenLines = @screenLinesForRows(@firstRenderedScreenRow, @lastRenderedScreenRow) @@ -446,8 +445,6 @@ class Editor extends View oldScreenRange = e.oldRange newScreenRange = e.newRange - @compositeCursor.updateBufferPosition() unless e.bufferChanged - if @attached @verticalScrollbarContent.height(@lineHeight * @screenLineCount()) @@ -478,10 +475,14 @@ 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 + @compositeCursor.updateBufferPosition() unless e.bufferChanged + buildLineElements: (startRow, endRow) -> charWidth = @charWidth charHeight = @charHeight From 72b971e01eddcf195ea244e19e648bee0c6fe1b5 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 31 May 2012 17:56:26 -0600 Subject: [PATCH 2/2] Revert "Replace @getLastVisibleScreenRow with @getFirstVisibleScreenRow" This reverts commit 89ac1f50af60850d54e6f322b989e6d49efff40f. --- src/app/editor.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 50976b9a8..35defc80f 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -450,7 +450,7 @@ class Editor extends View return if oldScreenRange.start.row > @lastRenderedScreenRow - maxEndRow = Math.max(@getFirstVisibleScreenRow() + @lineOverdraw, @lastRenderedScreenRow) + maxEndRow = Math.max(@getLastVisibleScreenRow() + @lineOverdraw, @lastRenderedScreenRow) @gutter.renderLineNumbers(@firstRenderedScreenRow, maxEndRow) if e.lineNumbersChanged newScreenRange = newScreenRange.copy()