Merge pull request #3619 from lee-dohm/scroll-past-end

Add ability to scroll past the end of the file
This commit is contained in:
Ben Ogle 2014-09-26 11:47:58 -07:00
commit 1f2fc4bf00
3 changed files with 35 additions and 2 deletions

View File

@ -1100,6 +1100,33 @@ describe "DisplayBuffer", ->
expect(displayBuffer.setScrollTop(maxScrollTop + 50)).toBe maxScrollTop
expect(displayBuffer.getScrollTop()).toBe maxScrollTop
describe "editor.scrollPastEnd", ->
describe "when editor.scrollPastEnd is false", ->
beforeEach ->
atom.config.set("editor.scrollPastEnd", false)
displayBuffer.manageScrollPosition = true
displayBuffer.setLineHeightInPixels(10)
it "does not add the height of the view to the scroll height", ->
lineHeight = displayBuffer.getLineHeightInPixels()
originalScrollHeight = displayBuffer.getScrollHeight()
displayBuffer.setHeight(50)
expect(displayBuffer.getScrollHeight()).toBe originalScrollHeight
describe "when editor.scrollPastEnd is true", ->
beforeEach ->
atom.config.set("editor.scrollPastEnd", true)
displayBuffer.manageScrollPosition = true
displayBuffer.setLineHeightInPixels(10)
it "adds the height of the view to the scroll height", ->
lineHeight = displayBuffer.getLineHeightInPixels()
originalScrollHeight = displayBuffer.getScrollHeight()
displayBuffer.setHeight(50)
expect(displayBuffer.getScrollHeight()).toEqual(originalScrollHeight + displayBuffer.height - (lineHeight * 3))
describe "::setScrollLeft", ->
beforeEach ->
displayBuffer.manageScrollPosition = true

View File

@ -315,9 +315,14 @@ class DisplayBuffer extends Model
@charWidthsByScope = {}
getScrollHeight: ->
return 0 unless @getLineHeightInPixels() > 0
lineHeight = @getLineHeightInPixels()
return 0 unless lineHeight > 0
@getLineCount() * @getLineHeightInPixels()
scrollHeight = @getLineCount() * lineHeight
if @height? and atom.config.get('editor.scrollPastEnd')
scrollHeight = scrollHeight + @height - (lineHeight * 3)
scrollHeight
getScrollWidth: ->
@scrollWidth

View File

@ -60,6 +60,7 @@ class TextEditorView extends View
space: '\u00b7'
tab: '\u00bb'
cr: '\u00a4'
scrollPastEnd: false
@content: (params) ->
attributes = params.attributes ? {}