1 helpers = require './spec-helper'
3 describe "Scrolling", ->
4 [editor, editorElement, vimState] = []
7 vimMode = atom.packages.loadPackage('vim-mode')
8 vimMode.activateResources()
10 helpers.getEditorElement (element) ->
11 editorElement = element
12 editor = editorElement.getModel()
13 vimState = editorElement.vimState
14 vimState.activateCommandMode()
15 vimState.resetCommandMode()
17 keydown = (key, options={}) ->
18 options.element ?= editorElement
19 helpers.keydown(key, options)
21 describe "scrolling keybindings", ->
23 editor.setText("1\n2\n3\n4\n5\n6\n7\n8\n9\n10")
24 spyOn(editor, 'getFirstVisibleScreenRow').andReturn(2)
25 spyOn(editor, 'getLastVisibleScreenRow').andReturn(8)
26 spyOn(editor, 'scrollToScreenPosition')
28 describe "the ctrl-e keybinding", ->
30 spyOn(editor, 'getCursorScreenPosition').andReturn({row: 4, column: 0})
31 spyOn(editor, 'setCursorScreenPosition')
33 it "moves the screen down by one and keeps cursor onscreen", ->
34 keydown('e', ctrl: true)
35 expect(editor.scrollToScreenPosition).toHaveBeenCalledWith([7, 0])
36 expect(editor.setCursorScreenPosition).toHaveBeenCalledWith([6, 0])
38 describe "the ctrl-y keybinding", ->
40 spyOn(editor, 'getCursorScreenPosition').andReturn({row: 6, column: 0})
41 spyOn(editor, 'setCursorScreenPosition')
43 it "moves the screen up by one and keeps the cursor onscreen", ->
44 keydown('y', ctrl: true)
45 expect(editor.scrollToScreenPosition).toHaveBeenCalledWith([3, 0])
46 expect(editor.setCursorScreenPosition).toHaveBeenCalledWith([4, 0])
48 describe "scroll cursor keybindings", ->
55 spyOn(editor, 'moveToFirstCharacterOfLine')
56 spyOn(editor, 'getLineHeightInPixels').andReturn(20)
57 spyOn(editor, 'setScrollTop')
58 spyOn(editor, 'getHeight').andReturn(200)
59 spyOn(editor, 'getFirstVisibleScreenRow').andReturn(90)
60 spyOn(editor, 'getLastVisibleScreenRow').andReturn(110)
62 describe "the z<CR> keybinding", ->
63 keydownCodeForEnter = '\r'
66 spyOn(editor, 'pixelPositionForScreenPosition').andReturn({top: 1000, left: 0})
68 it "moves the screen to position cursor at the top of the window and moves cursor to first non-blank in the line", ->
70 keydown(keydownCodeForEnter)
71 expect(editor.setScrollTop).toHaveBeenCalledWith(960)
72 expect(editor.moveToFirstCharacterOfLine).toHaveBeenCalled()
74 describe "the zt keybinding", ->
76 spyOn(editor, 'pixelPositionForScreenPosition').andReturn({top: 1000, left: 0})
78 it "moves the screen to position cursor at the top of the window and leave cursor in the same column", ->
81 expect(editor.setScrollTop).toHaveBeenCalledWith(960)
82 expect(editor.moveToFirstCharacterOfLine).not.toHaveBeenCalled()
84 describe "the z. keybinding", ->
86 spyOn(editor, 'pixelPositionForScreenPosition').andReturn({top: 1000, left: 0})
88 it "moves the screen to position cursor at the center of the window and moves cursor to first non-blank in the line", ->
91 expect(editor.setScrollTop).toHaveBeenCalledWith(900)
92 expect(editor.moveToFirstCharacterOfLine).toHaveBeenCalled()
94 describe "the zz keybinding", ->
96 spyOn(editor, 'pixelPositionForScreenPosition').andReturn({top: 1000, left: 0})
98 it "moves the screen to position cursor at the center of the window and leave cursor in the same column", ->
101 expect(editor.setScrollTop).toHaveBeenCalledWith(900)
102 expect(editor.moveToFirstCharacterOfLine).not.toHaveBeenCalled()
104 describe "the z- keybinding", ->
106 spyOn(editor, 'pixelPositionForScreenPosition').andReturn({top: 1000, left: 0})
108 it "moves the screen to position cursor at the bottom of the window and moves cursor to first non-blank in the line", ->
111 expect(editor.setScrollTop).toHaveBeenCalledWith(860)
112 expect(editor.moveToFirstCharacterOfLine).toHaveBeenCalled()
114 describe "the zb keybinding", ->
116 spyOn(editor, 'pixelPositionForScreenPosition').andReturn({top: 1000, left: 0})
118 it "moves the screen to position cursor at the bottom of the window and leave cursor in the same column", ->
121 expect(editor.setScrollTop).toHaveBeenCalledWith(860)
122 expect(editor.moveToFirstCharacterOfLine).not.toHaveBeenCalled()