From 2c3bec7468629e05cdbe8f3c03e1f3f64321fa2b Mon Sep 17 00:00:00 2001 From: Lee Dohm Date: Wed, 24 Sep 2014 07:14:42 -0700 Subject: [PATCH 1/2] Add ability to scroll past the end of the file Fixes #3592 --- src/display-buffer.coffee | 9 +++++++-- src/text-editor-view.coffee | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/display-buffer.coffee b/src/display-buffer.coffee index 4a686c88b..60430692b 100644 --- a/src/display-buffer.coffee +++ b/src/display-buffer.coffee @@ -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 diff --git a/src/text-editor-view.coffee b/src/text-editor-view.coffee index b613cbc95..2e6663fcf 100644 --- a/src/text-editor-view.coffee +++ b/src/text-editor-view.coffee @@ -60,6 +60,7 @@ class TextEditorView extends View space: '\u00b7' tab: '\u00bb' cr: '\u00a4' + scrollPastEnd: false @content: (params) -> attributes = params.attributes ? {} From 00baedbdf94687bb0c741c20c8806947c87039ee Mon Sep 17 00:00:00 2001 From: Lee Dohm Date: Thu, 25 Sep 2014 23:03:25 -0700 Subject: [PATCH 2/2] Add specs for editor.scrollPastEnd behavior --- spec/display-buffer-spec.coffee | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/spec/display-buffer-spec.coffee b/spec/display-buffer-spec.coffee index 9890504d3..b5583c0ad 100644 --- a/spec/display-buffer-spec.coffee +++ b/spec/display-buffer-spec.coffee @@ -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