Keep a minimum of 3 lines on screen when scrolling past end

This commit is contained in:
Nathan Sobo 2015-02-10 14:38:20 -07:00
parent 3e9b48ef71
commit f5294454e6
2 changed files with 9 additions and 13 deletions

View File

@ -263,7 +263,7 @@ describe "TextEditorPresenter", ->
expect(presenter.state.verticalScrollbar.scrollHeight).toBe presenter.computeContentHeight()
expectStateUpdate presenter, -> atom.config.set("editor.scrollPastEnd", true)
expect(presenter.state.verticalScrollbar.scrollHeight).toBe presenter.computeContentHeight() + presenter.computeClientHeight()
expect(presenter.state.verticalScrollbar.scrollHeight).toBe presenter.computeContentHeight() + presenter.computeClientHeight() - (presenter.lineHeight * 3)
expectStateUpdate presenter, -> atom.config.set("editor.scrollPastEnd", false)
expect(presenter.state.verticalScrollbar.scrollHeight).toBe presenter.computeContentHeight()
@ -306,7 +306,7 @@ describe "TextEditorPresenter", ->
atom.config.set("editor.scrollPastEnd", true)
expectStateUpdate presenter, -> presenter.setScrollTop(300)
expect(presenter.state.verticalScrollbar.scrollTop).toBe presenter.computeContentHeight()
expect(presenter.state.verticalScrollbar.scrollTop).toBe presenter.computeContentHeight() - (presenter.lineHeight * 3)
expectStateUpdate presenter, -> atom.config.set("editor.scrollPastEnd", false)
expect(presenter.state.verticalScrollbar.scrollTop).toBe presenter.computeContentHeight() - presenter.computeClientHeight()
@ -355,7 +355,7 @@ describe "TextEditorPresenter", ->
expect(presenter.state.content.scrollHeight).toBe presenter.computeContentHeight()
expectStateUpdate presenter, -> atom.config.set("editor.scrollPastEnd", true)
expect(presenter.state.content.scrollHeight).toBe presenter.computeContentHeight() + presenter.computeClientHeight()
expect(presenter.state.content.scrollHeight).toBe presenter.computeContentHeight() + presenter.computeClientHeight() - (presenter.lineHeight * 3)
expectStateUpdate presenter, -> atom.config.set("editor.scrollPastEnd", false)
expect(presenter.state.content.scrollHeight).toBe presenter.computeContentHeight()
@ -453,7 +453,7 @@ describe "TextEditorPresenter", ->
atom.config.set("editor.scrollPastEnd", true)
expectStateUpdate presenter, -> presenter.setScrollTop(300)
expect(presenter.state.content.scrollTop).toBe presenter.computeContentHeight()
expect(presenter.state.content.scrollTop).toBe presenter.computeContentHeight() - (presenter.lineHeight * 3)
expectStateUpdate presenter, -> atom.config.set("editor.scrollPastEnd", false)
expect(presenter.state.content.scrollTop).toBe presenter.computeContentHeight() - presenter.computeClientHeight()
@ -1524,7 +1524,7 @@ describe "TextEditorPresenter", ->
expect(presenter.state.gutter.scrollHeight).toBe presenter.computeContentHeight()
expectStateUpdate presenter, -> atom.config.set("editor.scrollPastEnd", true)
expect(presenter.state.gutter.scrollHeight).toBe presenter.computeContentHeight() + presenter.computeClientHeight()
expect(presenter.state.gutter.scrollHeight).toBe presenter.computeContentHeight() + presenter.computeClientHeight() - (presenter.lineHeight * 3)
expectStateUpdate presenter, -> atom.config.set("editor.scrollPastEnd", false)
expect(presenter.state.gutter.scrollHeight).toBe presenter.computeContentHeight()
@ -1567,7 +1567,7 @@ describe "TextEditorPresenter", ->
atom.config.set("editor.scrollPastEnd", true)
expectStateUpdate presenter, -> presenter.setScrollTop(300)
expect(presenter.state.gutter.scrollTop).toBe presenter.computeContentHeight()
expect(presenter.state.gutter.scrollTop).toBe presenter.computeContentHeight() - (presenter.lineHeight * 3)
expectStateUpdate presenter, -> atom.config.set("editor.scrollPastEnd", false)
expect(presenter.state.gutter.scrollTop).toBe presenter.computeContentHeight() - presenter.computeClientHeight()
@ -1735,12 +1735,6 @@ describe "TextEditorPresenter", ->
expectValues lineNumberStateForScreenRow(presenter, 6), {screenRow: 6, bufferRow: 3, softWrapped: true}
expectValues lineNumberStateForScreenRow(presenter, 7), {screenRow: 7, bufferRow: 4, softWrapped: false}
it "renders no line numbers if scrolled past the end", ->
atom.config.set('editor.scrollPastEnd', true)
presenter = buildPresenter(explicitHeight: 50, lineHeight: 10, lineOverdrawMargin: 0)
presenter.setScrollTop(300)
expect(presenter.state.gutter.lineNumbers).toEqual {}
describe ".decorationClasses", ->
it "adds decoration classes to the relevant line number state objects, both initially and when decorations change", ->
marker1 = editor.markBufferRange([[4, 0], [6, 2]], invalidate: 'touch')

View File

@ -348,7 +348,9 @@ class TextEditorPresenter
computeScrollHeight: ->
contentHeight = @computeContentHeight()
contentHeight += @computeClientHeight() if atom.config.get('editor.scrollPastEnd')
if atom.config.get('editor.scrollPastEnd')
extraScrollHeight = @computeClientHeight() - (@lineHeight * 3)
contentHeight += extraScrollHeight if extraScrollHeight > 0
Math.max(contentHeight, @computeHeight())
computeContentWidth: ->