blob: 3975a1fe99e34b03d70b1bef47d5ac3f2dd9b129 [file] [log] [blame]
Bram Moolenaarf6196f42022-10-02 21:29:55 +01001" Test for reset 'scroll' and 'smoothscroll'
2
3source check.vim
4source screendump.vim
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01005
6func Test_reset_scroll()
7 let scr = &l:scroll
8
9 setlocal scroll=1
10 setlocal scroll&
11 call assert_equal(scr, &l:scroll)
12
13 setlocal scroll=1
14 setlocal scroll=0
15 call assert_equal(scr, &l:scroll)
16
17 try
18 execute 'setlocal scroll=' . (winheight(0) + 1)
19 " not reached
20 call assert_false(1)
21 catch
22 call assert_exception('E49:')
23 endtry
24
25 split
26
27 let scr = &l:scroll
28
29 setlocal scroll=1
30 setlocal scroll&
31 call assert_equal(scr, &l:scroll)
32
33 setlocal scroll=1
34 setlocal scroll=0
35 call assert_equal(scr, &l:scroll)
36
37 quit!
38endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020039
Bram Moolenaar8df97482022-10-03 12:11:13 +010040func Test_CtrlE_CtrlY_stop_at_end()
41 enew
42 call setline(1, ['one', 'two'])
43 set number
44 exe "normal \<C-Y>"
45 call assert_equal([" 1 one "], ScreenLines(1, 10))
46 exe "normal \<C-E>\<C-E>\<C-E>"
47 call assert_equal([" 2 two "], ScreenLines(1, 10))
48
49 bwipe!
50 set nonumber
51endfunc
52
Bram Moolenaarf6196f42022-10-02 21:29:55 +010053func Test_smoothscroll_CtrlE_CtrlY()
54 CheckScreendump
55
56 let lines =<< trim END
57 vim9script
58 setline(1, [
59 'line one',
60 'word '->repeat(20),
61 'line three',
62 'long word '->repeat(7),
63 'line',
64 'line',
65 'line',
66 ])
67 set smoothscroll
68 :5
69 END
70 call writefile(lines, 'XSmoothScroll', 'D')
71 let buf = RunVimInTerminal('-S XSmoothScroll', #{rows: 12, cols: 40})
72
73 call term_sendkeys(buf, "\<C-E>")
74 call VerifyScreenDump(buf, 'Test_smoothscroll_1', {})
75 call term_sendkeys(buf, "\<C-E>")
76 call VerifyScreenDump(buf, 'Test_smoothscroll_2', {})
77 call term_sendkeys(buf, "\<C-E>")
78 call VerifyScreenDump(buf, 'Test_smoothscroll_3', {})
79 call term_sendkeys(buf, "\<C-E>")
80 call VerifyScreenDump(buf, 'Test_smoothscroll_4', {})
81
82 call term_sendkeys(buf, "\<C-Y>")
83 call VerifyScreenDump(buf, 'Test_smoothscroll_5', {})
84 call term_sendkeys(buf, "\<C-Y>")
85 call VerifyScreenDump(buf, 'Test_smoothscroll_6', {})
86 call term_sendkeys(buf, "\<C-Y>")
87 call VerifyScreenDump(buf, 'Test_smoothscroll_7', {})
88 call term_sendkeys(buf, "\<C-Y>")
89 call VerifyScreenDump(buf, 'Test_smoothscroll_8', {})
90
Bram Moolenaar6b2d4ff2022-10-03 14:06:02 +010091 if has('folding')
92 call term_sendkeys(buf, ":set foldmethod=indent\<CR>")
93 " move the cursor so we can reuse the same dumps
94 call term_sendkeys(buf, "5G")
95 call term_sendkeys(buf, "\<C-E>")
96 call VerifyScreenDump(buf, 'Test_smoothscroll_1', {})
97 call term_sendkeys(buf, "\<C-E>")
98 call VerifyScreenDump(buf, 'Test_smoothscroll_2', {})
99 call term_sendkeys(buf, "7G")
100 call term_sendkeys(buf, "\<C-Y>")
101 call VerifyScreenDump(buf, 'Test_smoothscroll_7', {})
102 call term_sendkeys(buf, "\<C-Y>")
103 call VerifyScreenDump(buf, 'Test_smoothscroll_8', {})
104 endif
105
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100106 call StopVimInTerminal(buf)
107endfunc
108
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +0100109func Test_smoothscroll_number()
110 CheckScreendump
111
112 let lines =<< trim END
113 vim9script
114 setline(1, [
115 'one ' .. 'word '->repeat(20),
116 'two ' .. 'long word '->repeat(7),
117 'line',
118 'line',
119 'line',
120 ])
121 set smoothscroll
122 set number cpo+=n
123 :3
Bram Moolenaareb4de622022-10-15 13:42:17 +0100124
125 def g:DoRel()
126 set number relativenumber scrolloff=0
127 :%del
128 setline(1, [
129 'one',
130 'very long text '->repeat(12),
131 'three',
132 ])
133 exe "normal 2Gzt\<C-E>"
134 enddef
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +0100135 END
136 call writefile(lines, 'XSmoothNumber', 'D')
137 let buf = RunVimInTerminal('-S XSmoothNumber', #{rows: 12, cols: 40})
138
139 call VerifyScreenDump(buf, 'Test_smooth_number_1', {})
140 call term_sendkeys(buf, "\<C-E>")
141 call VerifyScreenDump(buf, 'Test_smooth_number_2', {})
142 call term_sendkeys(buf, "\<C-E>")
143 call VerifyScreenDump(buf, 'Test_smooth_number_3', {})
144
145 call term_sendkeys(buf, ":set cpo-=n\<CR>")
146 call VerifyScreenDump(buf, 'Test_smooth_number_4', {})
147 call term_sendkeys(buf, "\<C-Y>")
148 call VerifyScreenDump(buf, 'Test_smooth_number_5', {})
149 call term_sendkeys(buf, "\<C-Y>")
150 call VerifyScreenDump(buf, 'Test_smooth_number_6', {})
151
Bram Moolenaareb4de622022-10-15 13:42:17 +0100152 call term_sendkeys(buf, ":call DoRel()\<CR>")
153 call VerifyScreenDump(buf, 'Test_smooth_number_7', {})
154
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +0100155 call StopVimInTerminal(buf)
156endfunc
157
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100158func Test_smoothscroll_list()
159 CheckScreendump
160
161 let lines =<< trim END
162 vim9script
163 set smoothscroll scrolloff=0
164 set list
165 setline(1, [
166 'one',
167 'very long text '->repeat(12),
168 'three',
169 ])
170 exe "normal 2Gzt\<C-E>"
171 END
172 call writefile(lines, 'XSmoothList', 'D')
173 let buf = RunVimInTerminal('-S XSmoothList', #{rows: 8, cols: 40})
174
175 call VerifyScreenDump(buf, 'Test_smooth_list_1', {})
176
177 call term_sendkeys(buf, ":set listchars+=precedes:#\<CR>")
178 call VerifyScreenDump(buf, 'Test_smooth_list_2', {})
179
180 call StopVimInTerminal(buf)
181endfunc
182
Bram Moolenaar1a58e1d2022-10-06 13:09:17 +0100183func Test_smoothscroll_diff_mode()
184 CheckScreendump
185
186 let lines =<< trim END
187 vim9script
188 var text = 'just some text here'
189 setline(1, text)
190 set smoothscroll
191 diffthis
192 new
193 setline(1, text)
194 set smoothscroll
195 diffthis
196 END
197 call writefile(lines, 'XSmoothDiff', 'D')
198 let buf = RunVimInTerminal('-S XSmoothDiff', #{rows: 8})
199
200 call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
201 call term_sendkeys(buf, "\<C-Y>")
202 call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
203 call term_sendkeys(buf, "\<C-E>")
204 call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
205
206 call StopVimInTerminal(buf)
207endfunc
208
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100209func Test_smoothscroll_wrap_scrolloff_zero()
210 CheckScreendump
211
212 let lines =<< trim END
213 vim9script
214 setline(1, ['Line' .. (' with some text'->repeat(7))]->repeat(7))
215 set smoothscroll scrolloff=0
216 :3
217 END
218 call writefile(lines, 'XSmoothWrap', 'D')
219 let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 8, cols: 40})
220
221 call VerifyScreenDump(buf, 'Test_smooth_wrap_1', {})
222
Bram Moolenaar46b54742022-10-06 15:46:49 +0100223 " moving cursor down - whole bottom line shows
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100224 call term_sendkeys(buf, "j")
225 call VerifyScreenDump(buf, 'Test_smooth_wrap_2', {})
226
227 call term_sendkeys(buf, "\<C-E>j")
228 call VerifyScreenDump(buf, 'Test_smooth_wrap_3', {})
229
230 call term_sendkeys(buf, "G")
231 call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {})
232
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000233 " moving cursor up right after the >>> marker - no need to show whole line
234 call term_sendkeys(buf, "2gj3l2k")
Bram Moolenaar46b54742022-10-06 15:46:49 +0100235 call VerifyScreenDump(buf, 'Test_smooth_wrap_5', {})
236
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000237 " moving cursor up where the >>> marker is - whole top line shows
238 call term_sendkeys(buf, "2j02k")
239 call VerifyScreenDump(buf, 'Test_smooth_wrap_6', {})
240
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100241 call StopVimInTerminal(buf)
242endfunc
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100243
Bram Moolenaar8cf34592022-10-08 21:13:40 +0100244func Test_smoothscroll_wrap_long_line()
245 CheckScreendump
246
247 let lines =<< trim END
248 vim9script
249 setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(30))])
250 set smoothscroll scrolloff=0
251 normal 3G10|zt
252 END
253 call writefile(lines, 'XSmoothWrap', 'D')
254 let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 6, cols: 40})
255 call VerifyScreenDump(buf, 'Test_smooth_long_1', {})
256
257 " scrolling up, cursor moves screen line down
258 call term_sendkeys(buf, "\<C-E>")
259 call VerifyScreenDump(buf, 'Test_smooth_long_2', {})
260 call term_sendkeys(buf, "5\<C-E>")
261 call VerifyScreenDump(buf, 'Test_smooth_long_3', {})
262
263 " scrolling down, cursor moves screen line up
264 call term_sendkeys(buf, "5\<C-Y>")
265 call VerifyScreenDump(buf, 'Test_smooth_long_4', {})
266 call term_sendkeys(buf, "\<C-Y>")
267 call VerifyScreenDump(buf, 'Test_smooth_long_5', {})
268
Bram Moolenaar118c2352022-10-09 17:19:27 +0100269 " 'scrolloff' set to 1, scrolling up, cursor moves screen line down
270 call term_sendkeys(buf, ":set scrolloff=1\<CR>")
271 call term_sendkeys(buf, "10|\<C-E>")
272 call VerifyScreenDump(buf, 'Test_smooth_long_6', {})
273
274 " 'scrolloff' set to 1, scrolling down, cursor moves screen line up
275 call term_sendkeys(buf, "\<C-E>")
276 call term_sendkeys(buf, "gjgj")
277 call term_sendkeys(buf, "\<C-Y>")
278 call VerifyScreenDump(buf, 'Test_smooth_long_7', {})
279
280 " 'scrolloff' set to 2, scrolling up, cursor moves screen line down
281 call term_sendkeys(buf, ":set scrolloff=2\<CR>")
282 call term_sendkeys(buf, "10|\<C-E>")
283 call VerifyScreenDump(buf, 'Test_smooth_long_8', {})
284
285 " 'scrolloff' set to 2, scrolling down, cursor moves screen line up
286 call term_sendkeys(buf, "\<C-E>")
287 call term_sendkeys(buf, "gj")
288 call term_sendkeys(buf, "\<C-Y>")
289 call VerifyScreenDump(buf, 'Test_smooth_long_9', {})
290
Bram Moolenaar8cf34592022-10-08 21:13:40 +0100291 call StopVimInTerminal(buf)
292endfunc
293
Bram Moolenaar2fbabd22022-10-12 19:53:38 +0100294func Test_smoothscroll_one_long_line()
295 CheckScreendump
296
297 let lines =<< trim END
298 vim9script
299 setline(1, 'with lots of text '->repeat(7))
300 set smoothscroll scrolloff=0
301 END
302 call writefile(lines, 'XSmoothOneLong', 'D')
303 let buf = RunVimInTerminal('-S XSmoothOneLong', #{rows: 6, cols: 40})
304 call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {})
305
306 call term_sendkeys(buf, "\<C-E>")
307 call VerifyScreenDump(buf, 'Test_smooth_one_long_2', {})
308
309 call term_sendkeys(buf, "0")
310 call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {})
311
312 call StopVimInTerminal(buf)
313endfunc
314
Bram Moolenaar75ac25b2022-11-17 19:00:14 +0000315func Test_smoothscroll_long_line_showbreak()
316 CheckScreendump
317
318 let lines =<< trim END
319 vim9script
320 # a line that spans four screen lines
321 setline(1, 'with lots of text in one line '->repeat(6))
322 set smoothscroll scrolloff=0 showbreak=+++\
323 END
324 call writefile(lines, 'XSmoothLongShowbreak', 'D')
325 let buf = RunVimInTerminal('-S XSmoothLongShowbreak', #{rows: 6, cols: 40})
326 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_1', {})
327
Bram Moolenaar75ac25b2022-11-17 19:00:14 +0000328 call term_sendkeys(buf, "\<C-E>")
329 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_2', {})
330
331 call term_sendkeys(buf, "0")
332 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_1', {})
333
334 call StopVimInTerminal(buf)
335endfunc
336
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000337" Test that if the current cursor is on a smooth scrolled line, we correctly
338" reposition it. Also check that we don't miscalculate the values by checking
339" the consistency between wincol() and col('.') as they are calculated
340" separately in code.
341func Test_smoothscroll_cursor_position()
342 call NewWindow(10, 20)
343 setl smoothscroll wrap
344 call setline(1, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
345
346 func s:check_col_calc(win_col, win_line, buf_col)
347 call assert_equal(a:win_col, wincol())
348 call assert_equal(a:win_line, winline())
349 call assert_equal(a:buf_col, col('.'))
350 endfunc
351
352 call s:check_col_calc(1, 1, 1)
353 exe "normal \<C-E>"
354
355 " Move down another line to avoid blocking the <<< display
356 call s:check_col_calc(1, 2, 41)
357 exe "normal \<C-Y>"
358 call s:check_col_calc(1, 3, 41)
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000359
360 normal gg3l
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000361 exe "normal \<C-E>"
362
363 " Move down only 1 line when we are out of the range of the <<< display
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000364 call s:check_col_calc(4, 1, 24)
365 exe "normal \<C-Y>"
366 call s:check_col_calc(4, 2, 24)
367 normal ggg$
368 exe "normal \<C-E>"
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000369 call s:check_col_calc(20, 1, 40)
370 exe "normal \<C-Y>"
371 call s:check_col_calc(20, 2, 40)
372 normal gg
373
374 " Test number, where we have indented lines
375 setl number
376 call s:check_col_calc(5, 1, 1)
377 exe "normal \<C-E>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000378
379 " Move down only 1 line when the <<< display is on the number column
380 call s:check_col_calc(5, 1, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000381 exe "normal \<C-Y>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000382 call s:check_col_calc(5, 2, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000383 normal ggg$
384 exe "normal \<C-E>"
385 call s:check_col_calc(20, 1, 32)
386 exe "normal \<C-Y>"
387 call s:check_col_calc(20, 2, 32)
388 normal gg
389
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000390 setl numberwidth=1
391
392 " Move down another line when numberwidth is too short to cover the whole
393 " <<< display
394 call s:check_col_calc(3, 1, 1)
395 exe "normal \<C-E>"
396 call s:check_col_calc(3, 2, 37)
397 exe "normal \<C-Y>"
398 call s:check_col_calc(3, 3, 37)
399 normal ggl
400
401 " Only move 1 line down when we are just past the <<< display
402 call s:check_col_calc(4, 1, 2)
403 exe "normal \<C-E>"
404 call s:check_col_calc(4, 1, 20)
405 exe "normal \<C-Y>"
406 call s:check_col_calc(4, 2, 20)
407 normal gg
408 setl numberwidth&
409
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000410 " Test number + showbreak, so test that the additional indentation works
411 setl number showbreak=+++
412 call s:check_col_calc(5, 1, 1)
413 exe "normal \<C-E>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000414 call s:check_col_calc(8, 1, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000415 exe "normal \<C-Y>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000416 call s:check_col_calc(8, 2, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000417 normal gg
418
419 " Test number + cpo+=n mode, where wrapped lines aren't indented
420 setl number cpo+=n showbreak=
421 call s:check_col_calc(5, 1, 1)
422 exe "normal \<C-E>"
423 call s:check_col_calc(1, 2, 37)
424 exe "normal \<C-Y>"
425 call s:check_col_calc(1, 3, 37)
426 normal gg
427
428 bwipeout!
429endfunc
430
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100431
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200432" vim: shiftwidth=2 sts=2 expandtab