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 #8558 from atom/ns-simplify-page-up-down
Browse files Browse the repository at this point in the history
Simplify page-up/page-down
  • Loading branch information
Nathan Sobo committed Aug 28, 2015
2 parents f3a90c2 + c7cc404 commit c0b4181
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 17 deletions.
13 changes: 1 addition & 12 deletions spec/text-editor-spec.coffee
Expand Up @@ -4535,26 +4535,21 @@ describe "TextEditor", ->
expect(editor.getScrollBottom()).toBe (9 + editor.getVerticalScrollMargin()) * 10

describe ".pageUp/Down()", ->
it "scrolls one screen height up or down and moves the cursor one page length", ->
it "moves the cursor down one page length", ->
editor.setLineHeightInPixels(10)
editor.setHeight(50)
expect(editor.getScrollHeight()).toBe 130
expect(editor.getCursorBufferPosition().row).toBe 0

editor.pageDown()
expect(editor.getScrollTop()).toBe 50
expect(editor.getCursorBufferPosition().row).toBe 5

editor.pageDown()
expect(editor.getScrollTop()).toBe 80
expect(editor.getCursorBufferPosition().row).toBe 10

editor.pageUp()
expect(editor.getScrollTop()).toBe 30
expect(editor.getCursorBufferPosition().row).toBe 5

editor.pageUp()
expect(editor.getScrollTop()).toBe 0
expect(editor.getCursorBufferPosition().row).toBe 0

describe ".selectPageUp/Down()", ->
Expand All @@ -4565,28 +4560,22 @@ describe "TextEditor", ->
expect(editor.getCursorBufferPosition().row).toBe 0

editor.selectPageDown()
expect(editor.getScrollTop()).toBe 30
expect(editor.getSelectedBufferRanges()).toEqual [[[0, 0], [5, 0]]]

editor.selectPageDown()
expect(editor.getScrollTop()).toBe 80
expect(editor.getSelectedBufferRanges()).toEqual [[[0, 0], [10, 0]]]

editor.selectPageDown()
expect(editor.getScrollTop()).toBe 80
expect(editor.getSelectedBufferRanges()).toEqual [[[0, 0], [12, 2]]]

editor.moveToBottom()
editor.selectPageUp()
expect(editor.getScrollTop()).toBe 50
expect(editor.getSelectedBufferRanges()).toEqual [[[7, 0], [12, 2]]]

editor.selectPageUp()
expect(editor.getScrollTop()).toBe 0
expect(editor.getSelectedBufferRanges()).toEqual [[[2, 0], [12, 2]]]

editor.selectPageUp()
expect(editor.getScrollTop()).toBe 0
expect(editor.getSelectedBufferRanges()).toEqual [[[0, 0], [12, 2]]]

describe '.get/setPlaceholderText()', ->
Expand Down
6 changes: 1 addition & 5 deletions src/text-editor.coffee
Expand Up @@ -2898,14 +2898,10 @@ class TextEditor extends Model
setVerticalScrollbarWidth: (width) -> @displayBuffer.setVerticalScrollbarWidth(width)

pageUp: ->
newScrollTop = @getScrollTop() - @getHeight()
@moveUp(@getRowsPerPage())
@setScrollTop(newScrollTop)

pageDown: ->
newScrollTop = @getScrollTop() + @getHeight()
@moveDown(@getRowsPerPage())
@setScrollTop(newScrollTop)

selectPageUp: ->
@selectUp(@getRowsPerPage())
Expand All @@ -2915,7 +2911,7 @@ class TextEditor extends Model

# Returns the number of rows per page
getRowsPerPage: ->
Math.max(1, Math.ceil(@getHeight() / @getLineHeightInPixels()))
Math.max(1, Math.floor(@getHeight() / @getLineHeightInPixels()))

###
Section: Config
Expand Down

0 comments on commit c0b4181

Please sign in to comment.