Substract scroll top when paging up

This commit is contained in:
Kevin Sawicki 2012-09-19 08:52:05 -07:00
parent 9ba3b74a9d
commit 47ed19f851
2 changed files with 11 additions and 11 deletions

View File

@ -1672,6 +1672,7 @@ describe "Editor", ->
break
row = newRow
expect(row).toBe(rows)
expect(editor.getLastVisibleScreenRow()).toBe(rows)
it "moves to the first line when page up is repeated from the last line", ->
editor.moveCursorToBottom()
@ -1685,6 +1686,7 @@ describe "Editor", ->
break
row = newRow
expect(row).toBe(0)
expect(editor.getFirstVisibleScreenRow()).toBe(0)
it "resets to original position when down is followed by up", ->
expect(editor.getCursor().getScreenPosition().row).toBe(0)
@ -1692,3 +1694,4 @@ describe "Editor", ->
expect(editor.getCursor().getScreenPosition().row).toBeGreaterThan(0)
editor.pageUp()
expect(editor.getCursor().getScreenPosition().row).toBe(0)
expect(editor.getFirstVisibleScreenRow()).toBe(0)

View File

@ -249,18 +249,15 @@ class Editor extends View
stateForScreenRow: (row) -> @activeEditSession.stateForScreenRow(row)
pageDown: ->
[top, rows] = @getPageSize()
@activeEditSession.moveCursorDown(rows)
@scrollTop(top, adjustVerticalScrollbar: true)
newScrollTop = @scrollTop() + @scrollView[0].clientHeight
@activeEditSession.moveCursorDown(@getPageRows())
@scrollTop(newScrollTop, adjustVerticalScrollbar: true)
pageUp: ->
[top, rows] = @getPageSize()
@activeEditSession.moveCursorUp(rows)
@scrollTop(top, adjustVerticalScrollbar: true)
getPageSize: ->
scrollViewHeight = @scrollView[0].clientHeight
newScrollTop = @scrollTop() + scrollViewHeight
rows = Math.max(1, Math.ceil(scrollViewHeight / @lineHeight))
[newScrollTop, rows]
newScrollTop = @scrollTop() - @scrollView[0].clientHeight
@activeEditSession.moveCursorUp(@getPageRows())
@scrollTop(newScrollTop, adjustVerticalScrollbar: true)
getPageRows: ->
Math.max(1, Math.ceil(@scrollView[0].clientHeight / @lineHeight))
setText: (text) -> @getBuffer().setText(text)
getText: -> @getBuffer().getText()