]>
Commit | Line | Data |
---|---|---|
1 | helpers = require './spec-helper' | |
2 | ||
3 | describe "Scrolling", -> | |
4 | [editor, editorElement, vimState] = [] | |
5 | ||
6 | beforeEach -> | |
7 | vimMode = atom.packages.loadPackage('vim-mode') | |
8 | vimMode.activateResources() | |
9 | ||
10 | helpers.getEditorElement (element) -> | |
11 | editorElement = element | |
12 | editor = editorElement.getModel() | |
13 | vimState = editorElement.vimState | |
14 | vimState.activateNormalMode() | |
15 | vimState.resetNormalMode() | |
16 | ||
17 | keydown = (key, options={}) -> | |
18 | options.element ?= editorElement | |
19 | helpers.keydown(key, options) | |
20 | ||
21 | describe "scrolling keybindings", -> | |
22 | beforeEach -> | |
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') | |
27 | ||
28 | describe "the ctrl-e keybinding", -> | |
29 | beforeEach -> | |
30 | spyOn(editor, 'getCursorScreenPosition').andReturn({row: 4, column: 0}) | |
31 | spyOn(editor, 'setCursorScreenPosition') | |
32 | ||
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]) | |
37 | ||
38 | describe "the ctrl-y keybinding", -> | |
39 | beforeEach -> | |
40 | spyOn(editor, 'getCursorScreenPosition').andReturn({row: 6, column: 0}) | |
41 | spyOn(editor, 'setCursorScreenPosition') | |
42 | ||
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]) | |
47 | ||
48 | describe "scroll cursor keybindings", -> | |
49 | beforeEach -> | |
50 | text = "" | |
51 | for i in [1..200] | |
52 | text += "#{i}\n" | |
53 | editor.setText(text) | |
54 | ||
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) | |
61 | ||
62 | describe "the z<CR> keybinding", -> | |
63 | keydownCodeForEnter = '\r' | |
64 | ||
65 | beforeEach -> | |
66 | spyOn(editor, 'pixelPositionForScreenPosition').andReturn({top: 1000, left: 0}) | |
67 | ||
68 | it "moves the screen to position cursor at the top of the window and moves cursor to first non-blank in the line", -> | |
69 | keydown('z') | |
70 | keydown(keydownCodeForEnter) | |
71 | expect(editor.setScrollTop).toHaveBeenCalledWith(960) | |
72 | expect(editor.moveToFirstCharacterOfLine).toHaveBeenCalled() | |
73 | ||
74 | describe "the zt keybinding", -> | |
75 | beforeEach -> | |
76 | spyOn(editor, 'pixelPositionForScreenPosition').andReturn({top: 1000, left: 0}) | |
77 | ||
78 | it "moves the screen to position cursor at the top of the window and leave cursor in the same column", -> | |
79 | keydown('z') | |
80 | keydown('t') | |
81 | expect(editor.setScrollTop).toHaveBeenCalledWith(960) | |
82 | expect(editor.moveToFirstCharacterOfLine).not.toHaveBeenCalled() | |
83 | ||
84 | describe "the z. keybinding", -> | |
85 | beforeEach -> | |
86 | spyOn(editor, 'pixelPositionForScreenPosition').andReturn({top: 1000, left: 0}) | |
87 | ||
88 | it "moves the screen to position cursor at the center of the window and moves cursor to first non-blank in the line", -> | |
89 | keydown('z') | |
90 | keydown('.') | |
91 | expect(editor.setScrollTop).toHaveBeenCalledWith(900) | |
92 | expect(editor.moveToFirstCharacterOfLine).toHaveBeenCalled() | |
93 | ||
94 | describe "the zz keybinding", -> | |
95 | beforeEach -> | |
96 | spyOn(editor, 'pixelPositionForScreenPosition').andReturn({top: 1000, left: 0}) | |
97 | ||
98 | it "moves the screen to position cursor at the center of the window and leave cursor in the same column", -> | |
99 | keydown('z') | |
100 | keydown('z') | |
101 | expect(editor.setScrollTop).toHaveBeenCalledWith(900) | |
102 | expect(editor.moveToFirstCharacterOfLine).not.toHaveBeenCalled() | |
103 | ||
104 | describe "the z- keybinding", -> | |
105 | beforeEach -> | |
106 | spyOn(editor, 'pixelPositionForScreenPosition').andReturn({top: 1000, left: 0}) | |
107 | ||
108 | it "moves the screen to position cursor at the bottom of the window and moves cursor to first non-blank in the line", -> | |
109 | keydown('z') | |
110 | keydown('-') | |
111 | expect(editor.setScrollTop).toHaveBeenCalledWith(860) | |
112 | expect(editor.moveToFirstCharacterOfLine).toHaveBeenCalled() | |
113 | ||
114 | describe "the zb keybinding", -> | |
115 | beforeEach -> | |
116 | spyOn(editor, 'pixelPositionForScreenPosition').andReturn({top: 1000, left: 0}) | |
117 | ||
118 | it "moves the screen to position cursor at the bottom of the window and leave cursor in the same column", -> | |
119 | keydown('z') | |
120 | keydown('b') | |
121 | expect(editor.setScrollTop).toHaveBeenCalledWith(860) | |
122 | expect(editor.moveToFirstCharacterOfLine).not.toHaveBeenCalled() | |
123 | ||
124 | describe "horizontal scroll cursor keybindings", -> | |
125 | beforeEach -> | |
126 | editor.setWidth(600) | |
127 | editor.setLineHeightInPixels(10) | |
128 | editor.setDefaultCharWidth(10) | |
129 | text = "" | |
130 | for i in [100..199] | |
131 | text += "#{i} " | |
132 | editor.setText(text) | |
133 | editor.setCursorBufferPosition([0, 0]) | |
134 | ||
135 | describe "the zs keybinding", -> | |
136 | zsPos = (pos) -> | |
137 | editor.setCursorBufferPosition([0, pos]) | |
138 | keydown('z') | |
139 | keydown('s') | |
140 | editor.getScrollLeft() | |
141 | ||
142 | startPosition = NaN | |
143 | ||
144 | beforeEach -> | |
145 | startPosition = editor.getScrollLeft() | |
146 | ||
147 | it "does nothing near the start of the line", -> | |
148 | pos1 = zsPos(1) | |
149 | expect(pos1).toEqual(startPosition) | |
150 | ||
151 | it "moves the cursor the nearest it can to the left edge of the editor", -> | |
152 | pos10 = zsPos(10) | |
153 | expect(pos10).toBeGreaterThan(startPosition) | |
154 | ||
155 | pos11 = zsPos(11) | |
156 | expect(pos11 - pos10).toEqual(10) | |
157 | ||
158 | it "does nothing near the end of the line", -> | |
159 | posEnd = zsPos(399) | |
160 | expect(editor.getCursorBufferPosition()).toEqual [0, 399] | |
161 | ||
162 | pos390 = zsPos(390) | |
163 | expect(pos390).toEqual(posEnd) | |
164 | expect(editor.getCursorBufferPosition()).toEqual [0, 390] | |
165 | ||
166 | pos340 = zsPos(340) | |
167 | expect(pos340).toBeLessThan(posEnd) | |
168 | pos342 = zsPos(342) | |
169 | expect(pos342 - pos340).toEqual(20) | |
170 | ||
171 | it "does nothing if all lines are short", -> | |
172 | editor.setText('short') | |
173 | startPosition = editor.getScrollLeft() | |
174 | pos1 = zsPos(1) | |
175 | expect(pos1).toEqual(startPosition) | |
176 | expect(editor.getCursorBufferPosition()).toEqual [0, 1] | |
177 | pos10 = zsPos(10) | |
178 | expect(pos10).toEqual(startPosition) | |
179 | expect(editor.getCursorBufferPosition()).toEqual [0, 4] | |
180 | ||
181 | ||
182 | describe "the ze keybinding", -> | |
183 | zePos = (pos) -> | |
184 | editor.setCursorBufferPosition([0, pos]) | |
185 | keydown('z') | |
186 | keydown('e') | |
187 | editor.getScrollLeft() | |
188 | ||
189 | startPosition = NaN | |
190 | ||
191 | beforeEach -> | |
192 | startPosition = editor.getScrollLeft() | |
193 | ||
194 | it "does nothing near the start of the line", -> | |
195 | pos1 = zePos(1) | |
196 | expect(pos1).toEqual(startPosition) | |
197 | ||
198 | pos40 = zePos(40) | |
199 | expect(pos40).toEqual(startPosition) | |
200 | ||
201 | it "moves the cursor the nearest it can to the right edge of the editor", -> | |
202 | pos110 = zePos(110) | |
203 | expect(pos110).toBeGreaterThan(startPosition) | |
204 | ||
205 | pos109 = zePos(109) | |
206 | expect(pos110 - pos109).toEqual(10) | |
207 | ||
208 | it "does nothing when very near the end of the line", -> | |
209 | posEnd = zePos(399) | |
210 | expect(editor.getCursorBufferPosition()).toEqual [0, 399] | |
211 | ||
212 | pos397 = zePos(397) | |
213 | expect(pos397).toEqual(posEnd) | |
214 | expect(editor.getCursorBufferPosition()).toEqual [0, 397] | |
215 | ||
216 | pos380 = zePos(380) | |
217 | expect(pos380).toBeLessThan(posEnd) | |
218 | ||
219 | pos382 = zePos(382) | |
220 | expect(pos382 - pos380).toEqual(20) | |
221 | ||
222 | it "does nothing if all lines are short", -> | |
223 | editor.setText('short') | |
224 | startPosition = editor.getScrollLeft() | |
225 | pos1 = zePos(1) | |
226 | expect(pos1).toEqual(startPosition) | |
227 | expect(editor.getCursorBufferPosition()).toEqual [0, 1] | |
228 | pos10 = zePos(10) | |
229 | expect(pos10).toEqual(startPosition) | |
230 | expect(editor.getCursorBufferPosition()).toEqual [0, 4] |