mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Add support for Page Up and Page Down keys
This commit is contained in:
@@ -1654,3 +1654,41 @@ describe "Editor", ->
|
||||
editor.edit(project.buildEditSessionForPath())
|
||||
paths = editor.getOpenBufferPaths().map (path) -> project.relativize(path)
|
||||
expect(paths).toEqual = ['sample.js', 'sample.txt', 'two-hundred.txt']
|
||||
|
||||
describe "paging up and down", ->
|
||||
beforeEach ->
|
||||
editor.attachToDom()
|
||||
|
||||
it "moves to the last line when page down is repeated from the first line", ->
|
||||
rows = editor.getLineCount() - 1
|
||||
expect(rows).toBeGreaterThan(0)
|
||||
row = editor.getCursor(0).getScreenPosition().row
|
||||
expect(row).toBe(0)
|
||||
while row < rows
|
||||
editor.pageDown()
|
||||
newRow = editor.getCursor(0).getScreenPosition().row
|
||||
expect(newRow).toBeGreaterThan(row)
|
||||
if (newRow <= row)
|
||||
break
|
||||
row = newRow
|
||||
expect(row).toBe(rows)
|
||||
|
||||
it "moves to the first line when page up is repeated from the last line", ->
|
||||
editor.moveCursorToBottom()
|
||||
row = editor.getCursor().getScreenPosition().row
|
||||
expect(row).toBeGreaterThan(0)
|
||||
while row > 0
|
||||
editor.pageUp()
|
||||
newRow = editor.getCursor().getScreenPosition().row
|
||||
expect(newRow).toBeLessThan(row)
|
||||
if (newRow >= row)
|
||||
break
|
||||
row = newRow
|
||||
expect(row).toBe(0)
|
||||
|
||||
it "resets to original position when down is followed by up", ->
|
||||
expect(editor.getCursor().getScreenPosition().row).toBe(0)
|
||||
editor.pageDown()
|
||||
expect(editor.getCursor().getScreenPosition().row).toBeGreaterThan(0)
|
||||
editor.pageUp()
|
||||
expect(editor.getCursor().getScreenPosition().row).toBe(0)
|
||||
|
||||
@@ -54,16 +54,16 @@ class Cursor
|
||||
refreshScreenPosition: ->
|
||||
@anchor.refreshScreenPosition()
|
||||
|
||||
moveUp: ->
|
||||
moveUp: (rowCount = 1) ->
|
||||
{ row, column } = @getScreenPosition()
|
||||
column = @goalColumn if @goalColumn?
|
||||
@setScreenPosition({row: row - 1, column: column})
|
||||
@setScreenPosition({row: row - rowCount, column: column})
|
||||
@goalColumn = column
|
||||
|
||||
moveDown: ->
|
||||
moveDown: (rowCount = 1) ->
|
||||
{ row, column } = @getScreenPosition()
|
||||
column = @goalColumn if @goalColumn?
|
||||
@setScreenPosition({row: row + 1, column: column})
|
||||
@setScreenPosition({row: row + rowCount, column: column})
|
||||
@goalColumn = column
|
||||
|
||||
moveLeft: ->
|
||||
|
||||
@@ -427,11 +427,11 @@ class EditSession
|
||||
getTextInBufferRange: (range) ->
|
||||
@buffer.getTextInRange(range)
|
||||
|
||||
moveCursorUp: ->
|
||||
@moveCursors (cursor) -> cursor.moveUp()
|
||||
moveCursorUp: (lineCount) ->
|
||||
@moveCursors (cursor) -> cursor.moveUp(lineCount)
|
||||
|
||||
moveCursorDown: ->
|
||||
@moveCursors (cursor) -> cursor.moveDown()
|
||||
moveCursorDown: (lineCount) ->
|
||||
@moveCursors (cursor) -> cursor.moveDown(lineCount)
|
||||
|
||||
moveCursorLeft: ->
|
||||
@moveCursors (cursor) -> cursor.moveLeft()
|
||||
|
||||
@@ -131,6 +131,8 @@ class Editor extends View
|
||||
'select-to-end-of-word': @selectToEndOfWord
|
||||
'select-to-beginning-of-word': @selectToBeginningOfWord
|
||||
'select-all': @selectAll
|
||||
'page-down': @pageDown
|
||||
'page-up': @pageUp
|
||||
|
||||
if not @mini
|
||||
_.extend editorBindings,
|
||||
@@ -246,6 +248,20 @@ class Editor extends View
|
||||
bufferRowsForScreenRows: (startRow, endRow) -> @activeEditSession.bufferRowsForScreenRows(startRow, endRow)
|
||||
stateForScreenRow: (row) -> @activeEditSession.stateForScreenRow(row)
|
||||
|
||||
pageDown: ->
|
||||
[top, rows] = @getPageSize()
|
||||
@activeEditSession.moveCursorDown(rows)
|
||||
@scrollTop(top, 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]
|
||||
|
||||
setText: (text) -> @getBuffer().setText(text)
|
||||
getText: -> @getBuffer().getText()
|
||||
getPath: -> @getBuffer().getPath()
|
||||
|
||||
@@ -5,3 +5,5 @@ window.keymap.bindKeys '*'
|
||||
left: 'move-left'
|
||||
down: 'move-down'
|
||||
up: 'move-up'
|
||||
pagedown: 'page-down'
|
||||
pageup: 'page-up'
|
||||
|
||||
Reference in New Issue
Block a user