1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
helpers = require './spec-helper'
describe "Scrolling", ->
[editor, editorElement, vimState] = []
beforeEach ->
vimMode = atom.packages.loadPackage('vim-mode')
vimMode.activateResources()
helpers.getEditorElement (element) ->
editorElement = element
editor = editorElement.getModel()
vimState = editorElement.vimState
vimState.activateCommandMode()
vimState.resetCommandMode()
keydown = (key, options={}) ->
options.element ?= editorElement
helpers.keydown(key, options)
describe "scrolling keybindings", ->
beforeEach ->
editor.setText("1\n2\n3\n4\n5\n6\n7\n8\n9\n10")
spyOn(editor, 'getFirstVisibleScreenRow').andReturn(2)
spyOn(editor, 'getLastVisibleScreenRow').andReturn(8)
spyOn(editor, 'scrollToScreenPosition')
describe "the ctrl-e keybinding", ->
beforeEach ->
spyOn(editor, 'getCursorScreenPosition').andReturn({row: 4, column: 0})
spyOn(editor, 'setCursorScreenPosition')
it "moves the screen down by one and keeps cursor onscreen", ->
keydown('e', ctrl: true)
expect(editor.scrollToScreenPosition).toHaveBeenCalledWith([7, 0])
expect(editor.setCursorScreenPosition).toHaveBeenCalledWith([6, 0])
describe "the ctrl-y keybinding", ->
beforeEach ->
spyOn(editor, 'getCursorScreenPosition').andReturn({row: 6, column: 0})
spyOn(editor, 'setCursorScreenPosition')
it "moves the screen up by one and keeps the cursor onscreen", ->
keydown('y', ctrl: true)
expect(editor.scrollToScreenPosition).toHaveBeenCalledWith([3, 0])
expect(editor.setCursorScreenPosition).toHaveBeenCalledWith([4, 0])
describe "scroll cursor keybindings", ->
beforeEach ->
text = ""
for i in [1..200]
text += "#{i}\n"
editor.setText(text)
spyOn(editor, 'moveToFirstCharacterOfLine')
spyOn(editor, 'getLineHeightInPixels').andReturn(20)
spyOn(editor, 'setScrollTop')
spyOn(editor, 'getHeight').andReturn(200)
spyOn(editor, 'getFirstVisibleScreenRow').andReturn(90)
spyOn(editor, 'getLastVisibleScreenRow').andReturn(110)
describe "the z<CR> keybinding", ->
keydownCodeForEnter = '\r'
beforeEach ->
spyOn(editor, 'pixelPositionForScreenPosition').andReturn({top: 1000, left: 0})
it "moves the screen to position cursor at the top of the window and moves cursor to first non-blank in the line", ->
keydown('z')
keydown(keydownCodeForEnter)
expect(editor.setScrollTop).toHaveBeenCalledWith(960)
expect(editor.moveToFirstCharacterOfLine).toHaveBeenCalled()
describe "the zt keybinding", ->
beforeEach ->
spyOn(editor, 'pixelPositionForScreenPosition').andReturn({top: 1000, left: 0})
it "moves the screen to position cursor at the top of the window and leave cursor in the same column", ->
keydown('z')
keydown('t')
expect(editor.setScrollTop).toHaveBeenCalledWith(960)
expect(editor.moveToFirstCharacterOfLine).not.toHaveBeenCalled()
describe "the z. keybinding", ->
beforeEach ->
spyOn(editor, 'pixelPositionForScreenPosition').andReturn({top: 1000, left: 0})
it "moves the screen to position cursor at the center of the window and moves cursor to first non-blank in the line", ->
keydown('z')
keydown('.')
expect(editor.setScrollTop).toHaveBeenCalledWith(900)
expect(editor.moveToFirstCharacterOfLine).toHaveBeenCalled()
describe "the zz keybinding", ->
beforeEach ->
spyOn(editor, 'pixelPositionForScreenPosition').andReturn({top: 1000, left: 0})
it "moves the screen to position cursor at the center of the window and leave cursor in the same column", ->
keydown('z')
keydown('z')
expect(editor.setScrollTop).toHaveBeenCalledWith(900)
expect(editor.moveToFirstCharacterOfLine).not.toHaveBeenCalled()
describe "the z- keybinding", ->
beforeEach ->
spyOn(editor, 'pixelPositionForScreenPosition').andReturn({top: 1000, left: 0})
it "moves the screen to position cursor at the bottom of the window and moves cursor to first non-blank in the line", ->
keydown('z')
keydown('-')
expect(editor.setScrollTop).toHaveBeenCalledWith(860)
expect(editor.moveToFirstCharacterOfLine).toHaveBeenCalled()
describe "the zb keybinding", ->
beforeEach ->
spyOn(editor, 'pixelPositionForScreenPosition').andReturn({top: 1000, left: 0})
it "moves the screen to position cursor at the bottom of the window and leave cursor in the same column", ->
keydown('z')
keydown('b')
expect(editor.setScrollTop).toHaveBeenCalledWith(860)
expect(editor.moveToFirstCharacterOfLine).not.toHaveBeenCalled()
|