     describe "when a selected fold is scrolled into view (and the fold line was not previously rendered)", ->
       it "renders the fold's line element with the 'selected' class", ->
         setEditorHeightInLines(editor, 5)
+        editor.renderVisibleLines() # re-render lines so certain lines are not rendered
 
         editor.createFold(2, 4)
         editor.setSelectionBufferRange([[1, 0], [5, 0]])


        it "scrolls the buffer with the specified scroll margin when cursor approaches the end of the screen", ->
          setEditorHeightInLines(editor, 10)
          editor.renderVisibleLines() # Ensures the editor only has 10 lines visible

          _.times 6, -> editor.moveCursorDown()
          window.advanceClock()
          expect(editor.scrollTop()).toBe(0)

          editor.moveCursorDown()
          advanceClock()
          editor.verticalScrollbar.trigger 'scroll'

          expect(editor.scrollTop()).toBe(editor.lineHeight)
          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 '&nbsp;' # line 10 is blank, but a nbsp holds its height

          editor.moveCursorDown()
          window.advanceClock()

          expect(editor.scrollTop()).toBe(editor.lineHeight * 2)
          expect(editor.visibleLines.find('.line').length).toBe 10
          expect(editor.visibleLines.find('.line:first').text()).toBe buffer.lineForRow(2)
          expect(editor.visibleLines.find('.line:last').text()).toBe buffer.lineForRow(11)

          _.times 3, -> editor.moveCursorUp()
          window.advanceClock()

          editor.moveCursorUp()
          window.advanceClock()
          editor.verticalScrollbar.trigger 'scroll'

          expect(editor.scrollTop()).toBe(editor.lineHeight)

          editor.moveCursorUp()
          window.advanceClock()
          editor.verticalScrollbar.trigger 'scroll'

          expect(editor.scrollTop()).toBe(0)

        it "reduces scroll margins when there isn't enough height to maintain them and scroll smoothly", ->
          setEditorHeightInLines(editor, 5)

          _.times 3, ->
            editor.moveCursorDown()
            window.advanceClock()
            editor.verticalScrollbar.trigger 'scroll'

          expect(editor.scrollTop()).toBe(editor.lineHeight)

          editor.moveCursorUp()
          window.advanceClock()
          editor.verticalScrollbar.trigger 'scroll'
          expect(editor.scrollView.scrollTop()).toBe(0)

      describe "horizontal scrolling", ->

_ = require 'underscore'
fs = require 'fs'

describe "Editor", ->
  [rootView, buffer, editor, cachedLineHeight] = []

  getLineHeight = ->
