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

Add ability to scroll past the end of the file #3619

Merged
merged 2 commits into from
Sep 26, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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