blob: 460416665d7ff0b66f07d9397e8449d5d75cf0bc [file] [log] [blame]
Bram Moolenaarf6196f42022-10-02 21:29:55 +01001" Test for reset 'scroll' and 'smoothscroll'
2
3source check.vim
4source screendump.vim
Yee Cheng Chine6392b12022-11-19 14:31:08 +00005source mouse.vim
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01006
7func Test_reset_scroll()
8 let scr = &l:scroll
9
10 setlocal scroll=1
11 setlocal scroll&
12 call assert_equal(scr, &l:scroll)
13
14 setlocal scroll=1
15 setlocal scroll=0
16 call assert_equal(scr, &l:scroll)
17
18 try
19 execute 'setlocal scroll=' . (winheight(0) + 1)
20 " not reached
21 call assert_false(1)
22 catch
23 call assert_exception('E49:')
24 endtry
25
26 split
27
28 let scr = &l:scroll
29
30 setlocal scroll=1
31 setlocal scroll&
32 call assert_equal(scr, &l:scroll)
33
34 setlocal scroll=1
35 setlocal scroll=0
36 call assert_equal(scr, &l:scroll)
37
38 quit!
39endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020040
Bram Moolenaar1d6539c2023-02-14 17:41:20 +000041func Test_scolloff_even_line_count()
42 new
43 resize 6
44 setlocal scrolloff=3
45 call setline(1, range(20))
46 normal 2j
47 call assert_equal(1, getwininfo(win_getid())[0].topline)
48 normal j
49 call assert_equal(1, getwininfo(win_getid())[0].topline)
50 normal j
51 call assert_equal(2, getwininfo(win_getid())[0].topline)
52 normal j
53 call assert_equal(3, getwininfo(win_getid())[0].topline)
54
55 bwipe!
56endfunc
57
Bram Moolenaar8df97482022-10-03 12:11:13 +010058func Test_CtrlE_CtrlY_stop_at_end()
59 enew
60 call setline(1, ['one', 'two'])
61 set number
62 exe "normal \<C-Y>"
63 call assert_equal([" 1 one "], ScreenLines(1, 10))
64 exe "normal \<C-E>\<C-E>\<C-E>"
65 call assert_equal([" 2 two "], ScreenLines(1, 10))
66
67 bwipe!
68 set nonumber
69endfunc
70
Bram Moolenaarf6196f42022-10-02 21:29:55 +010071func Test_smoothscroll_CtrlE_CtrlY()
72 CheckScreendump
73
74 let lines =<< trim END
75 vim9script
76 setline(1, [
77 'line one',
78 'word '->repeat(20),
79 'line three',
80 'long word '->repeat(7),
81 'line',
82 'line',
83 'line',
84 ])
85 set smoothscroll
86 :5
87 END
88 call writefile(lines, 'XSmoothScroll', 'D')
89 let buf = RunVimInTerminal('-S XSmoothScroll', #{rows: 12, cols: 40})
90
91 call term_sendkeys(buf, "\<C-E>")
92 call VerifyScreenDump(buf, 'Test_smoothscroll_1', {})
93 call term_sendkeys(buf, "\<C-E>")
94 call VerifyScreenDump(buf, 'Test_smoothscroll_2', {})
95 call term_sendkeys(buf, "\<C-E>")
96 call VerifyScreenDump(buf, 'Test_smoothscroll_3', {})
97 call term_sendkeys(buf, "\<C-E>")
98 call VerifyScreenDump(buf, 'Test_smoothscroll_4', {})
99
100 call term_sendkeys(buf, "\<C-Y>")
101 call VerifyScreenDump(buf, 'Test_smoothscroll_5', {})
102 call term_sendkeys(buf, "\<C-Y>")
103 call VerifyScreenDump(buf, 'Test_smoothscroll_6', {})
104 call term_sendkeys(buf, "\<C-Y>")
105 call VerifyScreenDump(buf, 'Test_smoothscroll_7', {})
106 call term_sendkeys(buf, "\<C-Y>")
107 call VerifyScreenDump(buf, 'Test_smoothscroll_8', {})
108
Bram Moolenaar6b2d4ff2022-10-03 14:06:02 +0100109 if has('folding')
110 call term_sendkeys(buf, ":set foldmethod=indent\<CR>")
111 " move the cursor so we can reuse the same dumps
112 call term_sendkeys(buf, "5G")
113 call term_sendkeys(buf, "\<C-E>")
114 call VerifyScreenDump(buf, 'Test_smoothscroll_1', {})
115 call term_sendkeys(buf, "\<C-E>")
116 call VerifyScreenDump(buf, 'Test_smoothscroll_2', {})
117 call term_sendkeys(buf, "7G")
118 call term_sendkeys(buf, "\<C-Y>")
119 call VerifyScreenDump(buf, 'Test_smoothscroll_7', {})
120 call term_sendkeys(buf, "\<C-Y>")
121 call VerifyScreenDump(buf, 'Test_smoothscroll_8', {})
122 endif
123
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100124 call StopVimInTerminal(buf)
125endfunc
126
Bram Moolenaar15d47472023-06-05 20:44:55 +0100127func Test_smoothscroll_multibyte()
128 CheckScreendump
129
130 let lines =<< trim END
131 set scrolloff=0 smoothscroll
132 call setline(1, [repeat('ϛ', 45), repeat('2', 36)])
133 exe "normal G35l\<C-E>k"
134 END
135 call writefile(lines, 'XSmoothMultibyte', 'D')
136 let buf = RunVimInTerminal('-S XSmoothMultibyte', #{rows: 6, cols: 40})
137 call VerifyScreenDump(buf, 'Test_smoothscroll_multi_1', {})
138
139 call StopVimInTerminal(buf)
140endfunc
141
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +0100142func Test_smoothscroll_number()
143 CheckScreendump
144
145 let lines =<< trim END
146 vim9script
147 setline(1, [
148 'one ' .. 'word '->repeat(20),
149 'two ' .. 'long word '->repeat(7),
150 'line',
151 'line',
152 'line',
153 ])
154 set smoothscroll
zeertzjq88bb3e02023-05-02 20:52:59 +0100155 set splitkeep=topline
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +0100156 set number cpo+=n
157 :3
Bram Moolenaareb4de622022-10-15 13:42:17 +0100158
159 def g:DoRel()
160 set number relativenumber scrolloff=0
161 :%del
162 setline(1, [
163 'one',
164 'very long text '->repeat(12),
165 'three',
166 ])
167 exe "normal 2Gzt\<C-E>"
168 enddef
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +0100169 END
170 call writefile(lines, 'XSmoothNumber', 'D')
171 let buf = RunVimInTerminal('-S XSmoothNumber', #{rows: 12, cols: 40})
172
173 call VerifyScreenDump(buf, 'Test_smooth_number_1', {})
174 call term_sendkeys(buf, "\<C-E>")
175 call VerifyScreenDump(buf, 'Test_smooth_number_2', {})
176 call term_sendkeys(buf, "\<C-E>")
177 call VerifyScreenDump(buf, 'Test_smooth_number_3', {})
178
179 call term_sendkeys(buf, ":set cpo-=n\<CR>")
180 call VerifyScreenDump(buf, 'Test_smooth_number_4', {})
181 call term_sendkeys(buf, "\<C-Y>")
182 call VerifyScreenDump(buf, 'Test_smooth_number_5', {})
183 call term_sendkeys(buf, "\<C-Y>")
184 call VerifyScreenDump(buf, 'Test_smooth_number_6', {})
185
zeertzjq88bb3e02023-05-02 20:52:59 +0100186 call term_sendkeys(buf, ":botright split\<CR>gg")
Bram Moolenaareb4de622022-10-15 13:42:17 +0100187 call VerifyScreenDump(buf, 'Test_smooth_number_7', {})
zeertzjq88bb3e02023-05-02 20:52:59 +0100188 call term_sendkeys(buf, "\<C-E>")
189 call VerifyScreenDump(buf, 'Test_smooth_number_8', {})
190 call term_sendkeys(buf, "\<C-E>")
191 call VerifyScreenDump(buf, 'Test_smooth_number_9', {})
192 call term_sendkeys(buf, ":close\<CR>")
193
194 call term_sendkeys(buf, ":call DoRel()\<CR>")
195 call VerifyScreenDump(buf, 'Test_smooth_number_10', {})
Bram Moolenaareb4de622022-10-15 13:42:17 +0100196
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +0100197 call StopVimInTerminal(buf)
198endfunc
199
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100200func Test_smoothscroll_list()
201 CheckScreendump
202
203 let lines =<< trim END
204 vim9script
205 set smoothscroll scrolloff=0
206 set list
207 setline(1, [
208 'one',
209 'very long text '->repeat(12),
210 'three',
211 ])
212 exe "normal 2Gzt\<C-E>"
213 END
214 call writefile(lines, 'XSmoothList', 'D')
215 let buf = RunVimInTerminal('-S XSmoothList', #{rows: 8, cols: 40})
216
217 call VerifyScreenDump(buf, 'Test_smooth_list_1', {})
218
219 call term_sendkeys(buf, ":set listchars+=precedes:#\<CR>")
220 call VerifyScreenDump(buf, 'Test_smooth_list_2', {})
221
222 call StopVimInTerminal(buf)
223endfunc
224
Bram Moolenaar1a58e1d2022-10-06 13:09:17 +0100225func Test_smoothscroll_diff_mode()
226 CheckScreendump
227
228 let lines =<< trim END
229 vim9script
230 var text = 'just some text here'
231 setline(1, text)
232 set smoothscroll
233 diffthis
234 new
235 setline(1, text)
236 set smoothscroll
237 diffthis
238 END
239 call writefile(lines, 'XSmoothDiff', 'D')
240 let buf = RunVimInTerminal('-S XSmoothDiff', #{rows: 8})
241
242 call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
243 call term_sendkeys(buf, "\<C-Y>")
244 call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
245 call term_sendkeys(buf, "\<C-E>")
246 call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
247
248 call StopVimInTerminal(buf)
249endfunc
250
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100251func Test_smoothscroll_wrap_scrolloff_zero()
252 CheckScreendump
253
254 let lines =<< trim END
255 vim9script
256 setline(1, ['Line' .. (' with some text'->repeat(7))]->repeat(7))
257 set smoothscroll scrolloff=0
258 :3
259 END
260 call writefile(lines, 'XSmoothWrap', 'D')
261 let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 8, cols: 40})
262
263 call VerifyScreenDump(buf, 'Test_smooth_wrap_1', {})
264
Bram Moolenaar46b54742022-10-06 15:46:49 +0100265 " moving cursor down - whole bottom line shows
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100266 call term_sendkeys(buf, "j")
267 call VerifyScreenDump(buf, 'Test_smooth_wrap_2', {})
268
269 call term_sendkeys(buf, "\<C-E>j")
270 call VerifyScreenDump(buf, 'Test_smooth_wrap_3', {})
271
272 call term_sendkeys(buf, "G")
273 call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {})
274
Luuk van Baald49f6462023-05-19 14:04:47 +0100275 call term_sendkeys(buf, "4\<C-Y>G")
276 call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {})
277
278 " moving cursor up right after the <<< marker - no need to show whole line
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000279 call term_sendkeys(buf, "2gj3l2k")
Bram Moolenaar46b54742022-10-06 15:46:49 +0100280 call VerifyScreenDump(buf, 'Test_smooth_wrap_5', {})
281
Luuk van Baald49f6462023-05-19 14:04:47 +0100282 " moving cursor up where the <<< marker is - whole top line shows
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000283 call term_sendkeys(buf, "2j02k")
284 call VerifyScreenDump(buf, 'Test_smooth_wrap_6', {})
285
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100286 call StopVimInTerminal(buf)
287endfunc
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100288
Bram Moolenaar8cf34592022-10-08 21:13:40 +0100289func Test_smoothscroll_wrap_long_line()
290 CheckScreendump
291
292 let lines =<< trim END
293 vim9script
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000294 setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(30)) .. ' end', 'four'])
Bram Moolenaar8cf34592022-10-08 21:13:40 +0100295 set smoothscroll scrolloff=0
296 normal 3G10|zt
297 END
298 call writefile(lines, 'XSmoothWrap', 'D')
299 let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 6, cols: 40})
300 call VerifyScreenDump(buf, 'Test_smooth_long_1', {})
301
302 " scrolling up, cursor moves screen line down
303 call term_sendkeys(buf, "\<C-E>")
304 call VerifyScreenDump(buf, 'Test_smooth_long_2', {})
305 call term_sendkeys(buf, "5\<C-E>")
306 call VerifyScreenDump(buf, 'Test_smooth_long_3', {})
307
308 " scrolling down, cursor moves screen line up
309 call term_sendkeys(buf, "5\<C-Y>")
310 call VerifyScreenDump(buf, 'Test_smooth_long_4', {})
311 call term_sendkeys(buf, "\<C-Y>")
312 call VerifyScreenDump(buf, 'Test_smooth_long_5', {})
313
Bram Moolenaar118c2352022-10-09 17:19:27 +0100314 " 'scrolloff' set to 1, scrolling up, cursor moves screen line down
315 call term_sendkeys(buf, ":set scrolloff=1\<CR>")
316 call term_sendkeys(buf, "10|\<C-E>")
317 call VerifyScreenDump(buf, 'Test_smooth_long_6', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000318
Bram Moolenaar118c2352022-10-09 17:19:27 +0100319 " 'scrolloff' set to 1, scrolling down, cursor moves screen line up
320 call term_sendkeys(buf, "\<C-E>")
321 call term_sendkeys(buf, "gjgj")
322 call term_sendkeys(buf, "\<C-Y>")
323 call VerifyScreenDump(buf, 'Test_smooth_long_7', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000324
Bram Moolenaar118c2352022-10-09 17:19:27 +0100325 " 'scrolloff' set to 2, scrolling up, cursor moves screen line down
326 call term_sendkeys(buf, ":set scrolloff=2\<CR>")
327 call term_sendkeys(buf, "10|\<C-E>")
328 call VerifyScreenDump(buf, 'Test_smooth_long_8', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000329
Bram Moolenaar118c2352022-10-09 17:19:27 +0100330 " 'scrolloff' set to 2, scrolling down, cursor moves screen line up
331 call term_sendkeys(buf, "\<C-E>")
332 call term_sendkeys(buf, "gj")
333 call term_sendkeys(buf, "\<C-Y>")
334 call VerifyScreenDump(buf, 'Test_smooth_long_9', {})
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000335
336 " 'scrolloff' set to 0, move cursor down one line.
337 " Cursor should move properly, and since this is a really long line, it will
338 " be put on top of the screen.
339 call term_sendkeys(buf, ":set scrolloff=0\<CR>")
340 call term_sendkeys(buf, "0j")
341 call VerifyScreenDump(buf, 'Test_smooth_long_10', {})
342
Bram Moolenaardb4d88c2022-12-31 15:13:22 +0000343 " Test zt/zz/zb that they work properly when a long line is above it
Luuk van Baal6f37e532023-05-09 21:23:54 +0100344 call term_sendkeys(buf, "zt")
Bram Moolenaardb4d88c2022-12-31 15:13:22 +0000345 call VerifyScreenDump(buf, 'Test_smooth_long_11', {})
346 call term_sendkeys(buf, "zz")
347 call VerifyScreenDump(buf, 'Test_smooth_long_12', {})
Luuk van Baal6f37e532023-05-09 21:23:54 +0100348 call term_sendkeys(buf, "zb")
Bram Moolenaardb4d88c2022-12-31 15:13:22 +0000349 call VerifyScreenDump(buf, 'Test_smooth_long_13', {})
350
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000351 " Repeat the step and move the cursor down again.
352 " This time, use a shorter long line that is barely long enough to span more
353 " than one window. Note that the cursor is at the bottom this time because
354 " Vim prefers to do so if we are scrolling a few lines only.
355 call term_sendkeys(buf, ":call setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(10)) .. ' end', 'four'])\<CR>")
Luuk van Baal5d01f862023-05-11 19:24:20 +0100356 " Currently visible lines were replaced, test that the lines and cursor
357 " are correctly displayed.
358 call VerifyScreenDump(buf, 'Test_smooth_long_14', {})
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000359 call term_sendkeys(buf, "3Gzt")
360 call term_sendkeys(buf, "j")
Luuk van Baal5d01f862023-05-11 19:24:20 +0100361 call VerifyScreenDump(buf, 'Test_smooth_long_15', {})
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000362
363 " Repeat the step but this time start it when the line is smooth-scrolled by
364 " one line. This tests that the offset calculation is still correct and
365 " still end up scrolling down to the next line with cursor at bottom of
366 " screen.
367 call term_sendkeys(buf, "3Gzt")
368 call term_sendkeys(buf, "\<C-E>j")
Luuk van Baal5d01f862023-05-11 19:24:20 +0100369 call VerifyScreenDump(buf, 'Test_smooth_long_16', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000370
Bram Moolenaar8cf34592022-10-08 21:13:40 +0100371 call StopVimInTerminal(buf)
372endfunc
373
Bram Moolenaar2fbabd22022-10-12 19:53:38 +0100374func Test_smoothscroll_one_long_line()
375 CheckScreendump
376
377 let lines =<< trim END
378 vim9script
379 setline(1, 'with lots of text '->repeat(7))
380 set smoothscroll scrolloff=0
381 END
382 call writefile(lines, 'XSmoothOneLong', 'D')
383 let buf = RunVimInTerminal('-S XSmoothOneLong', #{rows: 6, cols: 40})
384 call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000385
Bram Moolenaar2fbabd22022-10-12 19:53:38 +0100386 call term_sendkeys(buf, "\<C-E>")
387 call VerifyScreenDump(buf, 'Test_smooth_one_long_2', {})
388
389 call term_sendkeys(buf, "0")
390 call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {})
391
392 call StopVimInTerminal(buf)
393endfunc
394
Bram Moolenaar75ac25b2022-11-17 19:00:14 +0000395func Test_smoothscroll_long_line_showbreak()
396 CheckScreendump
397
398 let lines =<< trim END
399 vim9script
400 # a line that spans four screen lines
401 setline(1, 'with lots of text in one line '->repeat(6))
402 set smoothscroll scrolloff=0 showbreak=+++\
403 END
404 call writefile(lines, 'XSmoothLongShowbreak', 'D')
405 let buf = RunVimInTerminal('-S XSmoothLongShowbreak', #{rows: 6, cols: 40})
406 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_1', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000407
Bram Moolenaar75ac25b2022-11-17 19:00:14 +0000408 call term_sendkeys(buf, "\<C-E>")
409 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_2', {})
410
411 call term_sendkeys(buf, "0")
412 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_1', {})
413
414 call StopVimInTerminal(buf)
415endfunc
416
zeertzjqecb87dd2023-06-03 19:45:06 +0100417" Check that 'smoothscroll' marker is drawn over double-width char correctly.
418" Run with multiple encodings.
419func Test_smoothscroll_marker_over_double_width()
420 " Run this in a separate Vim instance to avoid messing up.
421 let after =<< trim [CODE]
422 scriptencoding utf-8
423 call setline(1, 'a'->repeat(&columns) .. '口'->repeat(10))
424 setlocal smoothscroll
425 redraw
426 exe "norm \<C-E>"
427 redraw
428 " Check the chars one by one. Don't check the whole line concatenated.
429 call assert_equal('<', screenstring(1, 1))
430 call assert_equal('<', screenstring(1, 2))
431 call assert_equal('<', screenstring(1, 3))
432 call assert_equal(' ', screenstring(1, 4))
433 call assert_equal('', screenstring(1, 5))
434 call assert_equal('', screenstring(1, 7))
435 call assert_equal('', screenstring(1, 9))
436 call assert_equal('', screenstring(1, 11))
437 call assert_equal('', screenstring(1, 13))
438 call assert_equal('', screenstring(1, 15))
439 call writefile(v:errors, 'Xresult')
440 qall!
441 [CODE]
442
443 let encodings = ['utf-8', 'cp932', 'cp936', 'cp949', 'cp950']
444 if !has('win32')
445 let encodings += ['euc-jp']
446 endif
447 for enc in encodings
448 let msg = 'enc=' .. enc
449 if RunVim([], after, $'--clean --cmd "set encoding={enc}"')
450 call assert_equal([], readfile('Xresult'), msg)
451 endif
452 call delete('Xresult')
453 endfor
454endfunc
455
456" Same as the test above, but check the text actually shown on screen.
457" Only run with UTF-8 encoding.
458func Test_smoothscroll_marker_over_double_width_dump()
459 CheckScreendump
460
461 let lines =<< trim END
462 call setline(1, 'a'->repeat(&columns) .. ''->repeat(10))
463 setlocal smoothscroll
464 END
465 call writefile(lines, 'XSmoothMarkerOverDoubleWidth', 'D')
466 let buf = RunVimInTerminal('-S XSmoothMarkerOverDoubleWidth', #{rows: 6, cols: 40})
467 call VerifyScreenDump(buf, 'Test_smooth_marker_over_double_width_1', {})
468
469 call term_sendkeys(buf, "\<C-E>")
470 call VerifyScreenDump(buf, 'Test_smooth_marker_over_double_width_2', {})
471
472 call StopVimInTerminal(buf)
473endfunc
474
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000475func s:check_col_calc(win_col, win_line, buf_col)
476 call assert_equal(a:win_col, wincol())
477 call assert_equal(a:win_line, winline())
478 call assert_equal(a:buf_col, col('.'))
479endfunc
480
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000481" Test that if the current cursor is on a smooth scrolled line, we correctly
482" reposition it. Also check that we don't miscalculate the values by checking
483" the consistency between wincol() and col('.') as they are calculated
484" separately in code.
485func Test_smoothscroll_cursor_position()
486 call NewWindow(10, 20)
487 setl smoothscroll wrap
488 call setline(1, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
489
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000490 call s:check_col_calc(1, 1, 1)
491 exe "normal \<C-E>"
492
493 " Move down another line to avoid blocking the <<< display
494 call s:check_col_calc(1, 2, 41)
495 exe "normal \<C-Y>"
496 call s:check_col_calc(1, 3, 41)
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000497
Luuk van Baal8667a562023-05-12 15:47:25 +0100498 " Test "g0/g<Home>"
499 exe "normal gg\<C-E>"
500 norm $gkg0
501 call s:check_col_calc(1, 2, 21)
502
503 " Test moving the cursor behind the <<< display with 'virtualedit'
504 set virtualedit=all
Luuk van Baal24b62ec2023-05-13 14:12:15 +0100505 exe "normal \<C-E>3lgkh"
Luuk van Baal8667a562023-05-12 15:47:25 +0100506 call s:check_col_calc(3, 2, 23)
507 set virtualedit&
508
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000509 normal gg3l
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000510 exe "normal \<C-E>"
511
512 " Move down only 1 line when we are out of the range of the <<< display
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000513 call s:check_col_calc(4, 1, 24)
514 exe "normal \<C-Y>"
515 call s:check_col_calc(4, 2, 24)
516 normal ggg$
517 exe "normal \<C-E>"
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000518 call s:check_col_calc(20, 1, 40)
519 exe "normal \<C-Y>"
520 call s:check_col_calc(20, 2, 40)
521 normal gg
522
523 " Test number, where we have indented lines
524 setl number
525 call s:check_col_calc(5, 1, 1)
526 exe "normal \<C-E>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000527
528 " Move down only 1 line when the <<< display is on the number column
529 call s:check_col_calc(5, 1, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000530 exe "normal \<C-Y>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000531 call s:check_col_calc(5, 2, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000532 normal ggg$
533 exe "normal \<C-E>"
534 call s:check_col_calc(20, 1, 32)
535 exe "normal \<C-Y>"
536 call s:check_col_calc(20, 2, 32)
537 normal gg
538
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000539 setl numberwidth=1
540
541 " Move down another line when numberwidth is too short to cover the whole
542 " <<< display
543 call s:check_col_calc(3, 1, 1)
544 exe "normal \<C-E>"
545 call s:check_col_calc(3, 2, 37)
546 exe "normal \<C-Y>"
547 call s:check_col_calc(3, 3, 37)
548 normal ggl
549
550 " Only move 1 line down when we are just past the <<< display
551 call s:check_col_calc(4, 1, 2)
552 exe "normal \<C-E>"
553 call s:check_col_calc(4, 1, 20)
554 exe "normal \<C-Y>"
555 call s:check_col_calc(4, 2, 20)
556 normal gg
557 setl numberwidth&
558
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000559 " Test number + showbreak, so test that the additional indentation works
560 setl number showbreak=+++
561 call s:check_col_calc(5, 1, 1)
562 exe "normal \<C-E>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000563 call s:check_col_calc(8, 1, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000564 exe "normal \<C-Y>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000565 call s:check_col_calc(8, 2, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000566 normal gg
567
568 " Test number + cpo+=n mode, where wrapped lines aren't indented
569 setl number cpo+=n showbreak=
570 call s:check_col_calc(5, 1, 1)
571 exe "normal \<C-E>"
572 call s:check_col_calc(1, 2, 37)
573 exe "normal \<C-Y>"
574 call s:check_col_calc(1, 3, 37)
575 normal gg
576
Luuk van Baal24b62ec2023-05-13 14:12:15 +0100577 " Test list + listchars "precedes", where there is always 1 overlap
578 " regardless of number and cpo-=n.
579 setl number list listchars=precedes:< cpo-=n
580 call s:check_col_calc(5, 1, 1)
Luuk van Baal798fa762023-05-15 18:17:43 +0100581 exe "normal 3|\<C-E>h"
Luuk van Baal24b62ec2023-05-13 14:12:15 +0100582 call s:check_col_calc(6, 1, 18)
583 norm h
584 call s:check_col_calc(5, 2, 17)
585 normal gg
586
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000587 bwipe!
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000588endfunc
589
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000590func Test_smoothscroll_cursor_scrolloff()
591 call NewWindow(10, 20)
592 setl smoothscroll wrap
593 setl scrolloff=3
Bram Moolenaar94722c52023-01-28 19:19:03 +0000594
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000595 " 120 chars are 6 screen lines
596 call setline(1, "abcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRST")
597 call setline(2, "below")
598
599 call s:check_col_calc(1, 1, 1)
600
601 " CTRL-E shows "<<<DEFG...", cursor move four lines down
602 exe "normal \<C-E>"
603 call s:check_col_calc(1, 4, 81)
604
605 " cursor on start of second line, "gk" moves into first line, skipcol doesn't
606 " change
607 exe "normal G0gk"
608 call s:check_col_calc(1, 5, 101)
609
610 " move cursor left one window width worth, scrolls one screen line
611 exe "normal 20h"
612 call s:check_col_calc(1, 5, 81)
613
614 " move cursor left one window width worth, scrolls one screen line
615 exe "normal 20h"
616 call s:check_col_calc(1, 4, 61)
617
Bram Moolenaarb21b8e92022-12-03 18:35:07 +0000618 " cursor on last line, "gk" should not cause a scroll
619 set scrolloff=0
620 normal G0
621 call s:check_col_calc(1, 7, 1)
622 normal gk
623 call s:check_col_calc(1, 6, 101)
624
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000625 bwipe!
626endfunc
627
628
Yee Cheng Chine6392b12022-11-19 14:31:08 +0000629" Test that mouse picking is still accurate when we have smooth scrolled lines
630func Test_smoothscroll_mouse_pos()
631 CheckNotGui
632 CheckUnix
633
634 let save_mouse = &mouse
635 let save_term = &term
636 let save_ttymouse = &ttymouse
637 set mouse=a term=xterm ttymouse=xterm2
638
639 call NewWindow(10, 20)
640 setl smoothscroll wrap
641 " First line will wrap to 3 physical lines. 2nd/3rd lines are short lines.
642 call setline(1, ["abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", "line 2", "line 3"])
643
644 func s:check_mouse_click(row, col, buf_row, buf_col)
645 call MouseLeftClick(a:row, a:col)
646
647 call assert_equal(a:col, wincol())
648 call assert_equal(a:row, winline())
649 call assert_equal(a:buf_row, line('.'))
650 call assert_equal(a:buf_col, col('.'))
651 endfunc
652
653 " Check that clicking without scroll works first.
654 call s:check_mouse_click(3, 5, 1, 45)
655 call s:check_mouse_click(4, 1, 2, 1)
656 call s:check_mouse_click(4, 6, 2, 6)
657 call s:check_mouse_click(5, 1, 3, 1)
658 call s:check_mouse_click(5, 6, 3, 6)
659
660 " Smooth scroll, and checks that this didn't mess up mouse clicking
661 exe "normal \<C-E>"
662 call s:check_mouse_click(2, 5, 1, 45)
663 call s:check_mouse_click(3, 1, 2, 1)
664 call s:check_mouse_click(3, 6, 2, 6)
665 call s:check_mouse_click(4, 1, 3, 1)
666 call s:check_mouse_click(4, 6, 3, 6)
667
668 exe "normal \<C-E>"
669 call s:check_mouse_click(1, 5, 1, 45)
670 call s:check_mouse_click(2, 1, 2, 1)
671 call s:check_mouse_click(2, 6, 2, 6)
672 call s:check_mouse_click(3, 1, 3, 1)
673 call s:check_mouse_click(3, 6, 3, 6)
674
675 " Make a new first line 11 physical lines tall so it's taller than window
676 " height, to test overflow calculations with really long lines wrapping.
677 normal gg
678 call setline(1, "12345678901234567890"->repeat(11))
679 exe "normal 6\<C-E>"
680 call s:check_mouse_click(5, 1, 1, 201)
681 call s:check_mouse_click(6, 1, 2, 1)
682 call s:check_mouse_click(7, 1, 3, 1)
683
684 let &mouse = save_mouse
685 let &term = save_term
686 let &ttymouse = save_ttymouse
687endfunc
688
Bram Moolenaar870219c2023-01-26 14:14:43 +0000689" this was dividing by zero
Luuk van Baalc8502f92023-05-06 12:40:15 +0100690func Test_smoothscroll_zero_width()
Bram Moolenaar870219c2023-01-26 14:14:43 +0000691 CheckScreendump
692
693 let lines =<< trim END
694 winsize 0 0
695 vsplit
696 vsplit
697 vsplit
698 vsplit
699 vsplit
700 sil norm H
701 set wrap
702 set smoothscroll
703 set number
704 END
705 call writefile(lines, 'XSmoothScrollZero', 'D')
706 let buf = RunVimInTerminal('-u NONE -i NONE -n -m -X -Z -e -s -S XSmoothScrollZero', #{rows: 6, cols: 60, wait_for_ruler: 0})
Bram Moolenaar870219c2023-01-26 14:14:43 +0000707 call VerifyScreenDump(buf, 'Test_smoothscroll_zero_1', {})
708
709 call term_sendkeys(buf, ":sil norm \<C-V>\<C-W>\<C-V>\<C-N>\<CR>")
710 call VerifyScreenDump(buf, 'Test_smoothscroll_zero_2', {})
711
712 call StopVimInTerminal(buf)
713endfunc
714
Luuk van Baalc8502f92023-05-06 12:40:15 +0100715" this was unnecessarily inserting lines
716func Test_smoothscroll_ins_lines()
717 CheckScreendump
718
719 let lines =<< trim END
720 set wrap
721 set smoothscroll
722 set scrolloff=0
723 set conceallevel=2
724 call setline(1, [
725 \'line one' .. 'with lots of text in one line '->repeat(2),
726 \'line two',
727 \'line three',
728 \'line four',
729 \'line five'
730 \])
731 END
732 call writefile(lines, 'XSmoothScrollInsLines', 'D')
733 let buf = RunVimInTerminal('-S XSmoothScrollInsLines', #{rows: 6, cols: 40})
734
735 call term_sendkeys(buf, "\<C-E>gjgk")
736 call VerifyScreenDump(buf, 'Test_smooth_ins_lines', {})
737
738 call StopVimInTerminal(buf)
739endfunc
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100740
Luuk van Baal3ce8c382023-05-08 15:51:14 +0100741" this placed the cursor in the command line
742func Test_smoothscroll_cursormoved_line()
743 CheckScreendump
744
745 let lines =<< trim END
746 set smoothscroll
747 call setline(1, [
748 \'',
749 \'_'->repeat(&lines * &columns),
750 \(('_')->repeat(&columns - 2) .. 'xxx')->repeat(2)
751 \])
752 autocmd CursorMoved * eval [line('w0'), line('w$')]
753 call search('xxx')
754 END
755 call writefile(lines, 'XSmoothCursorMovedLine', 'D')
756 let buf = RunVimInTerminal('-S XSmoothCursorMovedLine', #{rows: 6})
757
758 call VerifyScreenDump(buf, 'Test_smooth_cursormoved_line', {})
759
760 call StopVimInTerminal(buf)
761endfunc
762
763func Test_smoothscroll_eob()
764 CheckScreendump
765
766 let lines =<< trim END
767 set smoothscroll
768 call setline(1, ['']->repeat(100))
769 norm G
770 END
771 call writefile(lines, 'XSmoothEob', 'D')
772 let buf = RunVimInTerminal('-S XSmoothEob', #{rows: 10})
773
774 " does not scroll halfway when scrolling to end of buffer
775 call VerifyScreenDump(buf, 'Test_smooth_eob_1', {})
776
777 " cursor is not placed below window
778 call term_sendkeys(buf, ":call setline(92, 'a'->repeat(100))\<CR>\<C-B>G")
779 call VerifyScreenDump(buf, 'Test_smooth_eob_2', {})
780
781 call StopVimInTerminal(buf)
782endfunc
783
Luuk van Baald49f6462023-05-19 14:04:47 +0100784" skipcol should not reset when doing incremental search on the same word
785func Test_smoothscroll_incsearch()
786 CheckScreendump
787
788 let lines =<< trim END
789 set smoothscroll number scrolloff=0 incsearch
790 call setline(1, repeat([''], 20))
791 call setline(11, repeat('a', 100))
792 call setline(14, 'bbbb')
793 END
794 call writefile(lines, 'XSmoothIncsearch', 'D')
zeertzjq3c802272023-06-03 22:08:33 +0100795 let buf = RunVimInTerminal('-S XSmoothIncsearch', #{rows: 8, cols: 40})
Luuk van Baald49f6462023-05-19 14:04:47 +0100796
797 call term_sendkeys(buf, "/b")
798 call VerifyScreenDump(buf, 'Test_smooth_incsearch_1', {})
799 call term_sendkeys(buf, "b")
800 call VerifyScreenDump(buf, 'Test_smooth_incsearch_2', {})
801 call term_sendkeys(buf, "b")
802 call VerifyScreenDump(buf, 'Test_smooth_incsearch_3', {})
803 call term_sendkeys(buf, "b")
804 call VerifyScreenDump(buf, 'Test_smooth_incsearch_4', {})
805 call term_sendkeys(buf, "\<CR>")
806
807 call StopVimInTerminal(buf)
808endfunc
809
zeertzjq3c802272023-06-03 22:08:33 +0100810" Test scrolling multiple lines and stopping at non-zero skipcol.
811func Test_smoothscroll_multi_skipcol()
812 CheckScreendump
813
814 let lines =<< trim END
815 setlocal cursorline scrolloff=0 smoothscroll
zeertzjqd9a92dc2023-06-05 18:41:35 +0100816 call setline(1, repeat([''], 8))
zeertzjq3c802272023-06-03 22:08:33 +0100817 call setline(3, repeat('a', 50))
zeertzjqd9a92dc2023-06-05 18:41:35 +0100818 call setline(4, repeat('a', 50))
819 call setline(7, 'bbb')
820 call setline(8, 'ccc')
zeertzjq3c802272023-06-03 22:08:33 +0100821 redraw
822 END
823 call writefile(lines, 'XSmoothMultiSkipcol', 'D')
824 let buf = RunVimInTerminal('-S XSmoothMultiSkipcol', #{rows: 10, cols: 40})
825 call VerifyScreenDump(buf, 'Test_smooth_multi_skipcol_1', {})
826
827 call term_sendkeys(buf, "3\<C-E>")
828 call VerifyScreenDump(buf, 'Test_smooth_multi_skipcol_2', {})
829
zeertzjqd9a92dc2023-06-05 18:41:35 +0100830 call term_sendkeys(buf, "2\<C-E>")
831 call VerifyScreenDump(buf, 'Test_smooth_multi_skipcol_3', {})
832
zeertzjq3c802272023-06-03 22:08:33 +0100833 call StopVimInTerminal(buf)
834endfunc
835
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200836" vim: shiftwidth=2 sts=2 expandtab