]>
Commit | Line | Data |
---|---|---|
24c7594d BB |
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.activateCommandMode() | |
15 | vimState.resetCommandMode() | |
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() |