4 constructor: (@editorElement) ->
5 @scrolloff = 2 # atom default
6 @editor = @editorElement.getModel()
8 first: @editorElement.getFirstVisibleScreenRow()
9 last: @editorElement.getLastVisibleScreenRow()
10 final: @editor.getLastScreenRow()
12 class ScrollDown extends Scroll
14 @keepCursorOnScreen(count)
17 keepCursorOnScreen: (count) ->
18 {row, column} = @editor.getCursorScreenPosition()
19 firstScreenRow = @rows.first + @scrolloff + 1
20 if row - count <= firstScreenRow
21 @editor.setCursorScreenPosition([firstScreenRow + count, column])
24 lastScreenRow = @rows.last - @scrolloff
25 @editor.scrollToScreenPosition([lastScreenRow + count, 0])
27 class ScrollUp extends Scroll
29 @keepCursorOnScreen(count)
32 keepCursorOnScreen: (count) ->
33 {row, column} = @editor.getCursorScreenPosition()
34 lastScreenRow = @rows.last - @scrolloff - 1
35 if row + count >= lastScreenRow
36 @editor.setCursorScreenPosition([lastScreenRow - count, column])
38 scrollDown: (count) ->
39 firstScreenRow = @rows.first + @scrolloff
40 @editor.scrollToScreenPosition([firstScreenRow - count, 0])
42 class ScrollCursor extends Scroll
43 constructor: (@editorElement, @opts={}) ->
45 cursor = @editor.getCursorScreenPosition()
46 @pixel = @editorElement.pixelPositionForScreenPosition(cursor).top
48 class ScrollCursorToTop extends ScrollCursor
50 @moveToFirstNonBlank() unless @opts.leaveCursor
54 return if @rows.last is @rows.final
55 @pixel -= (@editor.getLineHeightInPixels() * @scrolloff)
56 @editor.setScrollTop(@pixel)
58 moveToFirstNonBlank: ->
59 @editor.moveToFirstCharacterOfLine()
61 class ScrollCursorToMiddle extends ScrollCursor
63 @moveToFirstNonBlank() unless @opts.leaveCursor
67 @pixel -= (@editor.getHeight() / 2)
68 @editor.setScrollTop(@pixel)
70 moveToFirstNonBlank: ->
71 @editor.moveToFirstCharacterOfLine()
73 class ScrollCursorToBottom extends ScrollCursor
75 @moveToFirstNonBlank() unless @opts.leaveCursor
79 return if @rows.first is 0
80 offset = (@editor.getLineHeightInPixels() * (@scrolloff + 1))
81 @pixel -= (@editor.getHeight() - offset)
82 @editor.setScrollTop(@pixel)
84 moveToFirstNonBlank: ->
85 @editor.moveToFirstCharacterOfLine()
87 module.exports = {ScrollDown, ScrollUp, ScrollCursorToTop, ScrollCursorToMiddle,