Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3619 from lee-dohm/scroll-past-end
Browse files Browse the repository at this point in the history
Add ability to scroll past the end of the file
  • Loading branch information
benogle committed Sep 26, 2014
2 parents 3601d11 + 00baedb commit 1f2fc4b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
27 changes: 27 additions & 0 deletions spec/display-buffer-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions src/display-buffer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/text-editor-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class TextEditorView extends View
space: '\u00b7'
tab: '\u00bb'
cr: '\u00a4'
scrollPastEnd: false

@content: (params) ->
attributes = params.attributes ? {}
Expand Down

0 comments on commit 1f2fc4b

Please sign in to comment.