diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index e63c4ecb8..e378453ef 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -1311,6 +1311,38 @@ describe "Editor", -> expect(editor.renderedLines.find(".line:first").text()).toBe buffer.lineForRow(0) expect(editor.renderedLines.find(".line:last").text()).toBe buffer.lineForRow(6) + describe "when the last line is removed when the editor is scrolled to the bottom", -> + it "reduces the editor's scrollTop (due to the reduced total scroll height) and renders the correct screen lines", -> + editor.setCursorScreenPosition([Infinity, Infinity]) + editor.insertText('\n\n\n') + editor.scrollToBottom() + + expect(buffer.getLineCount()).toBe 16 + + initialScrollTop = editor.scrollTop() + expect(editor.firstRenderedScreenRow).toBe 9 + expect(editor.lastRenderedScreenRow).toBe 15 + + editor.backspace() + + expect(editor.scrollTop()).toBeLessThan initialScrollTop + expect(editor.firstRenderedScreenRow).toBe 9 + expect(editor.lastRenderedScreenRow).toBe 14 + + expect(editor.find('.line').length).toBe 6 + + editor.backspace() + expect(editor.firstRenderedScreenRow).toBe 9 + expect(editor.lastRenderedScreenRow).toBe 13 + + expect(editor.find('.line').length).toBe 5 + + editor.backspace() + expect(editor.firstRenderedScreenRow).toBe 6 + expect(editor.lastRenderedScreenRow).toBe 12 + + expect(editor.find('.line').length).toBe 7 + it "decreases the width of the rendered screen lines if the max line length changes", -> widthBefore = editor.renderedLines.width() buffer.delete([[6, 0], [6, Infinity]]) diff --git a/src/app/editor.coffee b/src/app/editor.coffee index c4d23dcf0..ac7e94ba2 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -658,6 +658,11 @@ class Editor extends View adjustWidthOfRenderedLines: -> @renderedLines.width(@charWidth * @maxScreenLineLength()) + handleScrollHeightChange: -> + scrollHeight = @lineHeight * @screenLineCount() + @verticalScrollbarContent.height(scrollHeight) + @scrollBottom(scrollHeight) if @scrollBottom() > scrollHeight + renderLines: -> @clearRenderedLines() @updateRenderedLines() @@ -717,7 +722,7 @@ class Editor extends View newScreenRange = e.newRange if @attached - @verticalScrollbarContent.height(@lineHeight * @screenLineCount()) + @handleScrollHeightChange() unless newScreenRange.coversSameRows(oldScreenRange) @adjustWidthOfRenderedLines() return if oldScreenRange.start.row > @lastRenderedScreenRow