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 class ScrollHorizontal
89 isRecordable: -> false
90 constructor: (@editorElement) ->
91 @editor = @editorElement.getModel()
92 cursorPos = @editor.getCursorScreenPosition()
93 @pixel = @editorElement.pixelPositionForScreenPosition(cursorPos).left
94 @cursor = @editor.getLastCursor()
97 @editor.scrollToCursorPosition({center: false})
99 class ScrollCursorToLeft extends ScrollHorizontal
101 @editor.setScrollLeft(@pixel)
104 class ScrollCursorToRight extends ScrollHorizontal
106 @editor.setScrollRight(@pixel)
109 module.exports = {ScrollDown, ScrollUp, ScrollCursorToTop, ScrollCursorToMiddle,
110 ScrollCursorToBottom, ScrollCursorToLeft, ScrollCursorToRight}