blob: 7573db9ac3859671c56c8e40447fb6b2c3d7c5de [file] [log] [blame]
zeertzjq8e5f26e2023-10-04 21:45:33 +02001" Test for 'scroll', 'scrolloff', 'smoothscroll', etc.
Bram Moolenaarf6196f42022-10-02 21:29:55 +01002
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()
zeertzjq8e5f26e2023-10-04 21:45:33 +020042 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)
Bram Moolenaar1d6539c2023-02-14 17:41:20 +000054
zeertzjq8e5f26e2023-10-04 21:45:33 +020055 bwipe!
56endfunc
57
58func Test_mouse_scroll_inactive_with_cursorbind()
59 for scb in [0, 1]
60 for so in [0, 1, 2]
61 let msg = $'scb={scb} so={so}'
62
63 new | only
64 let w1 = win_getid()
65 setlocal cursorbind
66 let &l:scb = scb
67 let &l:so = so
68 call setline(1, range(101, 109))
69 rightbelow vnew
70 let w2 = win_getid()
71 setlocal cursorbind
72 let &l:scb = scb
73 let &l:so = so
74 call setline(1, range(101, 109))
75
76 normal! $
77 call assert_equal(3, col('.', w1), msg)
78 call assert_equal(3, col('.', w2), msg)
79 call test_setmouse(1, 1)
80 call feedkeys("\<ScrollWheelDown>", 'xt')
81 call assert_equal(4, line('w0', w1), msg)
82 call assert_equal(4 + so, line('.', w1), msg)
83 call assert_equal(1, line('w0', w2), msg)
84 call assert_equal(1, line('.', w2), msg)
85 call feedkeys("\<ScrollWheelDown>", 'xt')
86 call assert_equal(7, line('w0', w1), msg)
87 call assert_equal(7 + so, line('.', w1), msg)
88 call assert_equal(1, line('w0', w2), msg)
89 call assert_equal(1, line('.', w2), msg)
90 call feedkeys("\<ScrollWheelUp>", 'xt')
91 call assert_equal(4, line('w0', w1), msg)
92 call assert_equal(7 + so, line('.', w1), msg)
93 call assert_equal(1, line('w0', w2), msg)
94 call assert_equal(1, line('.', w2), msg)
95 call feedkeys("\<ScrollWheelUp>", 'xt')
96 call assert_equal(1, line('w0', w1), msg)
97 call assert_equal(7 + so, line('.', w1), msg)
98 call assert_equal(1, line('w0', w2), msg)
99 call assert_equal(1, line('.', w2), msg)
100 normal! 0
101 call assert_equal(1, line('.', w1), msg)
102 call assert_equal(1, col('.', w1), msg)
103 call assert_equal(1, line('.', w2), msg)
104 call assert_equal(1, col('.', w2), msg)
105
106 bwipe!
107 bwipe!
108 endfor
109 endfor
Bram Moolenaar1d6539c2023-02-14 17:41:20 +0000110endfunc
111
Bram Moolenaar8df97482022-10-03 12:11:13 +0100112func Test_CtrlE_CtrlY_stop_at_end()
113 enew
114 call setline(1, ['one', 'two'])
115 set number
116 exe "normal \<C-Y>"
117 call assert_equal([" 1 one "], ScreenLines(1, 10))
118 exe "normal \<C-E>\<C-E>\<C-E>"
119 call assert_equal([" 2 two "], ScreenLines(1, 10))
120
121 bwipe!
122 set nonumber
123endfunc
124
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100125func Test_smoothscroll_CtrlE_CtrlY()
126 CheckScreendump
127
128 let lines =<< trim END
129 vim9script
130 setline(1, [
131 'line one',
132 'word '->repeat(20),
133 'line three',
134 'long word '->repeat(7),
135 'line',
136 'line',
137 'line',
138 ])
139 set smoothscroll
140 :5
141 END
142 call writefile(lines, 'XSmoothScroll', 'D')
143 let buf = RunVimInTerminal('-S XSmoothScroll', #{rows: 12, cols: 40})
144
145 call term_sendkeys(buf, "\<C-E>")
146 call VerifyScreenDump(buf, 'Test_smoothscroll_1', {})
147 call term_sendkeys(buf, "\<C-E>")
148 call VerifyScreenDump(buf, 'Test_smoothscroll_2', {})
149 call term_sendkeys(buf, "\<C-E>")
150 call VerifyScreenDump(buf, 'Test_smoothscroll_3', {})
151 call term_sendkeys(buf, "\<C-E>")
152 call VerifyScreenDump(buf, 'Test_smoothscroll_4', {})
153
154 call term_sendkeys(buf, "\<C-Y>")
155 call VerifyScreenDump(buf, 'Test_smoothscroll_5', {})
156 call term_sendkeys(buf, "\<C-Y>")
157 call VerifyScreenDump(buf, 'Test_smoothscroll_6', {})
158 call term_sendkeys(buf, "\<C-Y>")
159 call VerifyScreenDump(buf, 'Test_smoothscroll_7', {})
160 call term_sendkeys(buf, "\<C-Y>")
161 call VerifyScreenDump(buf, 'Test_smoothscroll_8', {})
162
Bram Moolenaar6b2d4ff2022-10-03 14:06:02 +0100163 if has('folding')
164 call term_sendkeys(buf, ":set foldmethod=indent\<CR>")
165 " move the cursor so we can reuse the same dumps
166 call term_sendkeys(buf, "5G")
167 call term_sendkeys(buf, "\<C-E>")
168 call VerifyScreenDump(buf, 'Test_smoothscroll_1', {})
169 call term_sendkeys(buf, "\<C-E>")
170 call VerifyScreenDump(buf, 'Test_smoothscroll_2', {})
171 call term_sendkeys(buf, "7G")
172 call term_sendkeys(buf, "\<C-Y>")
173 call VerifyScreenDump(buf, 'Test_smoothscroll_7', {})
174 call term_sendkeys(buf, "\<C-Y>")
175 call VerifyScreenDump(buf, 'Test_smoothscroll_8', {})
176 endif
177
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100178 call StopVimInTerminal(buf)
179endfunc
180
Bram Moolenaar15d47472023-06-05 20:44:55 +0100181func Test_smoothscroll_multibyte()
182 CheckScreendump
183
184 let lines =<< trim END
185 set scrolloff=0 smoothscroll
186 call setline(1, [repeat('ϛ', 45), repeat('2', 36)])
187 exe "normal G35l\<C-E>k"
188 END
189 call writefile(lines, 'XSmoothMultibyte', 'D')
190 let buf = RunVimInTerminal('-S XSmoothMultibyte', #{rows: 6, cols: 40})
191 call VerifyScreenDump(buf, 'Test_smoothscroll_multi_1', {})
192
193 call StopVimInTerminal(buf)
194endfunc
195
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +0100196func Test_smoothscroll_number()
197 CheckScreendump
198
199 let lines =<< trim END
200 vim9script
201 setline(1, [
202 'one ' .. 'word '->repeat(20),
203 'two ' .. 'long word '->repeat(7),
204 'line',
205 'line',
206 'line',
207 ])
208 set smoothscroll
zeertzjq88bb3e02023-05-02 20:52:59 +0100209 set splitkeep=topline
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +0100210 set number cpo+=n
211 :3
Bram Moolenaareb4de622022-10-15 13:42:17 +0100212
213 def g:DoRel()
214 set number relativenumber scrolloff=0
215 :%del
216 setline(1, [
217 'one',
218 'very long text '->repeat(12),
219 'three',
220 ])
221 exe "normal 2Gzt\<C-E>"
222 enddef
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +0100223 END
224 call writefile(lines, 'XSmoothNumber', 'D')
225 let buf = RunVimInTerminal('-S XSmoothNumber', #{rows: 12, cols: 40})
226
227 call VerifyScreenDump(buf, 'Test_smooth_number_1', {})
228 call term_sendkeys(buf, "\<C-E>")
229 call VerifyScreenDump(buf, 'Test_smooth_number_2', {})
230 call term_sendkeys(buf, "\<C-E>")
231 call VerifyScreenDump(buf, 'Test_smooth_number_3', {})
232
233 call term_sendkeys(buf, ":set cpo-=n\<CR>")
234 call VerifyScreenDump(buf, 'Test_smooth_number_4', {})
235 call term_sendkeys(buf, "\<C-Y>")
236 call VerifyScreenDump(buf, 'Test_smooth_number_5', {})
237 call term_sendkeys(buf, "\<C-Y>")
238 call VerifyScreenDump(buf, 'Test_smooth_number_6', {})
239
zeertzjq88bb3e02023-05-02 20:52:59 +0100240 call term_sendkeys(buf, ":botright split\<CR>gg")
Bram Moolenaareb4de622022-10-15 13:42:17 +0100241 call VerifyScreenDump(buf, 'Test_smooth_number_7', {})
zeertzjq88bb3e02023-05-02 20:52:59 +0100242 call term_sendkeys(buf, "\<C-E>")
243 call VerifyScreenDump(buf, 'Test_smooth_number_8', {})
244 call term_sendkeys(buf, "\<C-E>")
245 call VerifyScreenDump(buf, 'Test_smooth_number_9', {})
246 call term_sendkeys(buf, ":close\<CR>")
247
248 call term_sendkeys(buf, ":call DoRel()\<CR>")
249 call VerifyScreenDump(buf, 'Test_smooth_number_10', {})
Bram Moolenaareb4de622022-10-15 13:42:17 +0100250
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +0100251 call StopVimInTerminal(buf)
252endfunc
253
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100254func Test_smoothscroll_list()
255 CheckScreendump
256
257 let lines =<< trim END
258 vim9script
259 set smoothscroll scrolloff=0
260 set list
261 setline(1, [
262 'one',
263 'very long text '->repeat(12),
264 'three',
265 ])
266 exe "normal 2Gzt\<C-E>"
267 END
268 call writefile(lines, 'XSmoothList', 'D')
269 let buf = RunVimInTerminal('-S XSmoothList', #{rows: 8, cols: 40})
270
271 call VerifyScreenDump(buf, 'Test_smooth_list_1', {})
272
273 call term_sendkeys(buf, ":set listchars+=precedes:#\<CR>")
274 call VerifyScreenDump(buf, 'Test_smooth_list_2', {})
275
276 call StopVimInTerminal(buf)
277endfunc
278
Bram Moolenaar1a58e1d2022-10-06 13:09:17 +0100279func Test_smoothscroll_diff_mode()
280 CheckScreendump
281
282 let lines =<< trim END
283 vim9script
284 var text = 'just some text here'
285 setline(1, text)
286 set smoothscroll
287 diffthis
288 new
289 setline(1, text)
290 set smoothscroll
291 diffthis
292 END
293 call writefile(lines, 'XSmoothDiff', 'D')
294 let buf = RunVimInTerminal('-S XSmoothDiff', #{rows: 8})
295
296 call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
297 call term_sendkeys(buf, "\<C-Y>")
298 call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
299 call term_sendkeys(buf, "\<C-E>")
300 call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
301
302 call StopVimInTerminal(buf)
303endfunc
304
zeertzjq47f85842024-10-01 19:35:47 +0200305func Test_smoothscroll_diff_change_line()
306 CheckScreendump
307
308 let lines =<< trim END
309 set diffopt+=followwrap smoothscroll
310 call setline(1, repeat(' abc', &columns))
311 call setline(2, 'bar')
312 call setline(3, repeat(' abc', &columns))
313 vnew
314 call setline(1, repeat(' abc', &columns))
315 call setline(2, 'foo')
316 call setline(3, 'bar')
317 call setline(4, repeat(' abc', &columns))
318 windo exe "normal! 2gg5\<C-E>"
319 windo diffthis
320 END
321 call writefile(lines, 'XSmoothDiffChangeLine', 'D')
322 let buf = RunVimInTerminal('-S XSmoothDiffChangeLine', #{rows: 20, columns: 55})
323
324 call VerifyScreenDump(buf, 'Test_smooth_diff_change_line_1', {})
325 call term_sendkeys(buf, "Abar")
326 call VerifyScreenDump(buf, 'Test_smooth_diff_change_line_2', {})
327 call term_sendkeys(buf, "\<Esc>")
328 call VerifyScreenDump(buf, 'Test_smooth_diff_change_line_3', {})
329 call term_sendkeys(buf, "yyp")
330 call VerifyScreenDump(buf, 'Test_smooth_diff_change_line_4', {})
331
332 call StopVimInTerminal(buf)
333endfunc
334
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100335func Test_smoothscroll_wrap_scrolloff_zero()
336 CheckScreendump
337
338 let lines =<< trim END
339 vim9script
340 setline(1, ['Line' .. (' with some text'->repeat(7))]->repeat(7))
341 set smoothscroll scrolloff=0
342 :3
343 END
344 call writefile(lines, 'XSmoothWrap', 'D')
345 let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 8, cols: 40})
346
347 call VerifyScreenDump(buf, 'Test_smooth_wrap_1', {})
348
Bram Moolenaar46b54742022-10-06 15:46:49 +0100349 " moving cursor down - whole bottom line shows
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100350 call term_sendkeys(buf, "j")
351 call VerifyScreenDump(buf, 'Test_smooth_wrap_2', {})
352
353 call term_sendkeys(buf, "\<C-E>j")
354 call VerifyScreenDump(buf, 'Test_smooth_wrap_3', {})
355
356 call term_sendkeys(buf, "G")
357 call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {})
358
Luuk van Baald49f6462023-05-19 14:04:47 +0100359 call term_sendkeys(buf, "4\<C-Y>G")
360 call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {})
361
362 " moving cursor up right after the <<< marker - no need to show whole line
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000363 call term_sendkeys(buf, "2gj3l2k")
Bram Moolenaar46b54742022-10-06 15:46:49 +0100364 call VerifyScreenDump(buf, 'Test_smooth_wrap_5', {})
365
Luuk van Baald49f6462023-05-19 14:04:47 +0100366 " moving cursor up where the <<< marker is - whole top line shows
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000367 call term_sendkeys(buf, "2j02k")
368 call VerifyScreenDump(buf, 'Test_smooth_wrap_6', {})
369
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100370 call StopVimInTerminal(buf)
371endfunc
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100372
Bram Moolenaar8cf34592022-10-08 21:13:40 +0100373func Test_smoothscroll_wrap_long_line()
374 CheckScreendump
375
376 let lines =<< trim END
377 vim9script
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000378 setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(30)) .. ' end', 'four'])
Bram Moolenaar8cf34592022-10-08 21:13:40 +0100379 set smoothscroll scrolloff=0
380 normal 3G10|zt
381 END
382 call writefile(lines, 'XSmoothWrap', 'D')
383 let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 6, cols: 40})
384 call VerifyScreenDump(buf, 'Test_smooth_long_1', {})
385
386 " scrolling up, cursor moves screen line down
387 call term_sendkeys(buf, "\<C-E>")
388 call VerifyScreenDump(buf, 'Test_smooth_long_2', {})
389 call term_sendkeys(buf, "5\<C-E>")
390 call VerifyScreenDump(buf, 'Test_smooth_long_3', {})
391
392 " scrolling down, cursor moves screen line up
393 call term_sendkeys(buf, "5\<C-Y>")
394 call VerifyScreenDump(buf, 'Test_smooth_long_4', {})
395 call term_sendkeys(buf, "\<C-Y>")
396 call VerifyScreenDump(buf, 'Test_smooth_long_5', {})
397
Bram Moolenaar118c2352022-10-09 17:19:27 +0100398 " 'scrolloff' set to 1, scrolling up, cursor moves screen line down
399 call term_sendkeys(buf, ":set scrolloff=1\<CR>")
400 call term_sendkeys(buf, "10|\<C-E>")
401 call VerifyScreenDump(buf, 'Test_smooth_long_6', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000402
Bram Moolenaar118c2352022-10-09 17:19:27 +0100403 " 'scrolloff' set to 1, scrolling down, cursor moves screen line up
404 call term_sendkeys(buf, "\<C-E>")
405 call term_sendkeys(buf, "gjgj")
406 call term_sendkeys(buf, "\<C-Y>")
407 call VerifyScreenDump(buf, 'Test_smooth_long_7', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000408
Bram Moolenaar118c2352022-10-09 17:19:27 +0100409 " 'scrolloff' set to 2, scrolling up, cursor moves screen line down
410 call term_sendkeys(buf, ":set scrolloff=2\<CR>")
411 call term_sendkeys(buf, "10|\<C-E>")
412 call VerifyScreenDump(buf, 'Test_smooth_long_8', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000413
Bram Moolenaar118c2352022-10-09 17:19:27 +0100414 " 'scrolloff' set to 2, scrolling down, cursor moves screen line up
415 call term_sendkeys(buf, "\<C-E>")
416 call term_sendkeys(buf, "gj")
417 call term_sendkeys(buf, "\<C-Y>")
418 call VerifyScreenDump(buf, 'Test_smooth_long_9', {})
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000419
420 " 'scrolloff' set to 0, move cursor down one line.
421 " Cursor should move properly, and since this is a really long line, it will
422 " be put on top of the screen.
423 call term_sendkeys(buf, ":set scrolloff=0\<CR>")
424 call term_sendkeys(buf, "0j")
425 call VerifyScreenDump(buf, 'Test_smooth_long_10', {})
426
Bram Moolenaardb4d88c2022-12-31 15:13:22 +0000427 " Test zt/zz/zb that they work properly when a long line is above it
Luuk van Baal6f37e532023-05-09 21:23:54 +0100428 call term_sendkeys(buf, "zt")
Bram Moolenaardb4d88c2022-12-31 15:13:22 +0000429 call VerifyScreenDump(buf, 'Test_smooth_long_11', {})
430 call term_sendkeys(buf, "zz")
431 call VerifyScreenDump(buf, 'Test_smooth_long_12', {})
Luuk van Baal6f37e532023-05-09 21:23:54 +0100432 call term_sendkeys(buf, "zb")
Bram Moolenaardb4d88c2022-12-31 15:13:22 +0000433 call VerifyScreenDump(buf, 'Test_smooth_long_13', {})
434
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000435 " Repeat the step and move the cursor down again.
436 " This time, use a shorter long line that is barely long enough to span more
437 " than one window. Note that the cursor is at the bottom this time because
438 " Vim prefers to do so if we are scrolling a few lines only.
439 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 +0100440 " Currently visible lines were replaced, test that the lines and cursor
441 " are correctly displayed.
442 call VerifyScreenDump(buf, 'Test_smooth_long_14', {})
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000443 call term_sendkeys(buf, "3Gzt")
444 call term_sendkeys(buf, "j")
Luuk van Baal5d01f862023-05-11 19:24:20 +0100445 call VerifyScreenDump(buf, 'Test_smooth_long_15', {})
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000446
447 " Repeat the step but this time start it when the line is smooth-scrolled by
448 " one line. This tests that the offset calculation is still correct and
449 " still end up scrolling down to the next line with cursor at bottom of
450 " screen.
451 call term_sendkeys(buf, "3Gzt")
452 call term_sendkeys(buf, "\<C-E>j")
Luuk van Baal5d01f862023-05-11 19:24:20 +0100453 call VerifyScreenDump(buf, 'Test_smooth_long_16', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000454
Bram Moolenaar8cf34592022-10-08 21:13:40 +0100455 call StopVimInTerminal(buf)
456endfunc
457
Bram Moolenaar2fbabd22022-10-12 19:53:38 +0100458func Test_smoothscroll_one_long_line()
459 CheckScreendump
460
461 let lines =<< trim END
462 vim9script
463 setline(1, 'with lots of text '->repeat(7))
464 set smoothscroll scrolloff=0
465 END
466 call writefile(lines, 'XSmoothOneLong', 'D')
467 let buf = RunVimInTerminal('-S XSmoothOneLong', #{rows: 6, cols: 40})
468 call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000469
Bram Moolenaar2fbabd22022-10-12 19:53:38 +0100470 call term_sendkeys(buf, "\<C-E>")
471 call VerifyScreenDump(buf, 'Test_smooth_one_long_2', {})
472
473 call term_sendkeys(buf, "0")
474 call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {})
475
476 call StopVimInTerminal(buf)
477endfunc
478
Bram Moolenaar75ac25b2022-11-17 19:00:14 +0000479func Test_smoothscroll_long_line_showbreak()
480 CheckScreendump
481
482 let lines =<< trim END
483 vim9script
484 # a line that spans four screen lines
485 setline(1, 'with lots of text in one line '->repeat(6))
486 set smoothscroll scrolloff=0 showbreak=+++\
487 END
488 call writefile(lines, 'XSmoothLongShowbreak', 'D')
489 let buf = RunVimInTerminal('-S XSmoothLongShowbreak', #{rows: 6, cols: 40})
490 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_1', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000491
Bram Moolenaar75ac25b2022-11-17 19:00:14 +0000492 call term_sendkeys(buf, "\<C-E>")
493 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_2', {})
494
495 call term_sendkeys(buf, "0")
496 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_1', {})
497
498 call StopVimInTerminal(buf)
499endfunc
500
zeertzjqecb87dd2023-06-03 19:45:06 +0100501" Check that 'smoothscroll' marker is drawn over double-width char correctly.
502" Run with multiple encodings.
503func Test_smoothscroll_marker_over_double_width()
504 " Run this in a separate Vim instance to avoid messing up.
505 let after =<< trim [CODE]
506 scriptencoding utf-8
507 call setline(1, 'a'->repeat(&columns) .. '口'->repeat(10))
508 setlocal smoothscroll
509 redraw
510 exe "norm \<C-E>"
511 redraw
512 " Check the chars one by one. Don't check the whole line concatenated.
513 call assert_equal('<', screenstring(1, 1))
514 call assert_equal('<', screenstring(1, 2))
515 call assert_equal('<', screenstring(1, 3))
516 call assert_equal(' ', screenstring(1, 4))
517 call assert_equal('', screenstring(1, 5))
518 call assert_equal('', screenstring(1, 7))
519 call assert_equal('', screenstring(1, 9))
520 call assert_equal('', screenstring(1, 11))
521 call assert_equal('', screenstring(1, 13))
522 call assert_equal('', screenstring(1, 15))
523 call writefile(v:errors, 'Xresult')
524 qall!
525 [CODE]
526
527 let encodings = ['utf-8', 'cp932', 'cp936', 'cp949', 'cp950']
528 if !has('win32')
529 let encodings += ['euc-jp']
530 endif
531 for enc in encodings
532 let msg = 'enc=' .. enc
533 if RunVim([], after, $'--clean --cmd "set encoding={enc}"')
534 call assert_equal([], readfile('Xresult'), msg)
535 endif
536 call delete('Xresult')
537 endfor
538endfunc
539
540" Same as the test above, but check the text actually shown on screen.
541" Only run with UTF-8 encoding.
542func Test_smoothscroll_marker_over_double_width_dump()
543 CheckScreendump
544
545 let lines =<< trim END
546 call setline(1, 'a'->repeat(&columns) .. ''->repeat(10))
547 setlocal smoothscroll
548 END
549 call writefile(lines, 'XSmoothMarkerOverDoubleWidth', 'D')
550 let buf = RunVimInTerminal('-S XSmoothMarkerOverDoubleWidth', #{rows: 6, cols: 40})
551 call VerifyScreenDump(buf, 'Test_smooth_marker_over_double_width_1', {})
552
553 call term_sendkeys(buf, "\<C-E>")
554 call VerifyScreenDump(buf, 'Test_smooth_marker_over_double_width_2', {})
555
556 call StopVimInTerminal(buf)
557endfunc
558
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000559func s:check_col_calc(win_col, win_line, buf_col)
560 call assert_equal(a:win_col, wincol())
561 call assert_equal(a:win_line, winline())
562 call assert_equal(a:buf_col, col('.'))
563endfunc
564
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000565" Test that if the current cursor is on a smooth scrolled line, we correctly
566" reposition it. Also check that we don't miscalculate the values by checking
567" the consistency between wincol() and col('.') as they are calculated
568" separately in code.
569func Test_smoothscroll_cursor_position()
570 call NewWindow(10, 20)
571 setl smoothscroll wrap
572 call setline(1, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
573
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000574 call s:check_col_calc(1, 1, 1)
575 exe "normal \<C-E>"
576
577 " Move down another line to avoid blocking the <<< display
578 call s:check_col_calc(1, 2, 41)
579 exe "normal \<C-Y>"
580 call s:check_col_calc(1, 3, 41)
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000581
Luuk van Baal8667a562023-05-12 15:47:25 +0100582 " Test "g0/g<Home>"
583 exe "normal gg\<C-E>"
584 norm $gkg0
Luuk van Baalcb204e62024-04-02 20:49:45 +0200585 call s:check_col_calc(4, 1, 24)
Luuk van Baal8667a562023-05-12 15:47:25 +0100586
587 " Test moving the cursor behind the <<< display with 'virtualedit'
588 set virtualedit=all
Luuk van Baalcb204e62024-04-02 20:49:45 +0200589 exe "normal \<C-E>gkh"
Luuk van Baal8667a562023-05-12 15:47:25 +0100590 call s:check_col_calc(3, 2, 23)
591 set virtualedit&
592
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000593 normal gg3l
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000594 exe "normal \<C-E>"
595
596 " Move down only 1 line when we are out of the range of the <<< display
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000597 call s:check_col_calc(4, 1, 24)
598 exe "normal \<C-Y>"
599 call s:check_col_calc(4, 2, 24)
600 normal ggg$
601 exe "normal \<C-E>"
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000602 call s:check_col_calc(20, 1, 40)
603 exe "normal \<C-Y>"
604 call s:check_col_calc(20, 2, 40)
605 normal gg
606
607 " Test number, where we have indented lines
608 setl number
609 call s:check_col_calc(5, 1, 1)
610 exe "normal \<C-E>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000611
612 " Move down only 1 line when the <<< display is on the number column
613 call s:check_col_calc(5, 1, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000614 exe "normal \<C-Y>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000615 call s:check_col_calc(5, 2, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000616 normal ggg$
617 exe "normal \<C-E>"
618 call s:check_col_calc(20, 1, 32)
619 exe "normal \<C-Y>"
620 call s:check_col_calc(20, 2, 32)
621 normal gg
622
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000623 setl numberwidth=1
624
625 " Move down another line when numberwidth is too short to cover the whole
626 " <<< display
627 call s:check_col_calc(3, 1, 1)
628 exe "normal \<C-E>"
629 call s:check_col_calc(3, 2, 37)
630 exe "normal \<C-Y>"
631 call s:check_col_calc(3, 3, 37)
632 normal ggl
633
634 " Only move 1 line down when we are just past the <<< display
635 call s:check_col_calc(4, 1, 2)
636 exe "normal \<C-E>"
637 call s:check_col_calc(4, 1, 20)
638 exe "normal \<C-Y>"
639 call s:check_col_calc(4, 2, 20)
640 normal gg
641 setl numberwidth&
642
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000643 " Test number + showbreak, so test that the additional indentation works
644 setl number showbreak=+++
645 call s:check_col_calc(5, 1, 1)
646 exe "normal \<C-E>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000647 call s:check_col_calc(8, 1, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000648 exe "normal \<C-Y>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000649 call s:check_col_calc(8, 2, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000650 normal gg
651
652 " Test number + cpo+=n mode, where wrapped lines aren't indented
653 setl number cpo+=n showbreak=
654 call s:check_col_calc(5, 1, 1)
655 exe "normal \<C-E>"
656 call s:check_col_calc(1, 2, 37)
657 exe "normal \<C-Y>"
658 call s:check_col_calc(1, 3, 37)
659 normal gg
660
Luuk van Baal24b62ec2023-05-13 14:12:15 +0100661 " Test list + listchars "precedes", where there is always 1 overlap
662 " regardless of number and cpo-=n.
663 setl number list listchars=precedes:< cpo-=n
664 call s:check_col_calc(5, 1, 1)
Luuk van Baal798fa762023-05-15 18:17:43 +0100665 exe "normal 3|\<C-E>h"
Luuk van Baal24b62ec2023-05-13 14:12:15 +0100666 call s:check_col_calc(6, 1, 18)
667 norm h
668 call s:check_col_calc(5, 2, 17)
669 normal gg
670
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000671 bwipe!
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000672endfunc
673
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000674func Test_smoothscroll_cursor_scrolloff()
675 call NewWindow(10, 20)
676 setl smoothscroll wrap
677 setl scrolloff=3
Bram Moolenaar94722c52023-01-28 19:19:03 +0000678
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000679 " 120 chars are 6 screen lines
680 call setline(1, "abcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRST")
681 call setline(2, "below")
682
683 call s:check_col_calc(1, 1, 1)
684
685 " CTRL-E shows "<<<DEFG...", cursor move four lines down
686 exe "normal \<C-E>"
687 call s:check_col_calc(1, 4, 81)
688
689 " cursor on start of second line, "gk" moves into first line, skipcol doesn't
690 " change
691 exe "normal G0gk"
692 call s:check_col_calc(1, 5, 101)
693
694 " move cursor left one window width worth, scrolls one screen line
695 exe "normal 20h"
696 call s:check_col_calc(1, 5, 81)
697
698 " move cursor left one window width worth, scrolls one screen line
699 exe "normal 20h"
700 call s:check_col_calc(1, 4, 61)
701
Bram Moolenaarb21b8e92022-12-03 18:35:07 +0000702 " cursor on last line, "gk" should not cause a scroll
703 set scrolloff=0
704 normal G0
705 call s:check_col_calc(1, 7, 1)
706 normal gk
707 call s:check_col_calc(1, 6, 101)
708
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000709 bwipe!
710endfunc
711
712
Yee Cheng Chine6392b12022-11-19 14:31:08 +0000713" Test that mouse picking is still accurate when we have smooth scrolled lines
714func Test_smoothscroll_mouse_pos()
715 CheckNotGui
716 CheckUnix
717
718 let save_mouse = &mouse
719 let save_term = &term
720 let save_ttymouse = &ttymouse
721 set mouse=a term=xterm ttymouse=xterm2
722
723 call NewWindow(10, 20)
724 setl smoothscroll wrap
725 " First line will wrap to 3 physical lines. 2nd/3rd lines are short lines.
726 call setline(1, ["abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", "line 2", "line 3"])
727
728 func s:check_mouse_click(row, col, buf_row, buf_col)
729 call MouseLeftClick(a:row, a:col)
730
731 call assert_equal(a:col, wincol())
732 call assert_equal(a:row, winline())
733 call assert_equal(a:buf_row, line('.'))
734 call assert_equal(a:buf_col, col('.'))
735 endfunc
736
737 " Check that clicking without scroll works first.
738 call s:check_mouse_click(3, 5, 1, 45)
739 call s:check_mouse_click(4, 1, 2, 1)
740 call s:check_mouse_click(4, 6, 2, 6)
741 call s:check_mouse_click(5, 1, 3, 1)
742 call s:check_mouse_click(5, 6, 3, 6)
743
744 " Smooth scroll, and checks that this didn't mess up mouse clicking
745 exe "normal \<C-E>"
746 call s:check_mouse_click(2, 5, 1, 45)
747 call s:check_mouse_click(3, 1, 2, 1)
748 call s:check_mouse_click(3, 6, 2, 6)
749 call s:check_mouse_click(4, 1, 3, 1)
750 call s:check_mouse_click(4, 6, 3, 6)
751
752 exe "normal \<C-E>"
753 call s:check_mouse_click(1, 5, 1, 45)
754 call s:check_mouse_click(2, 1, 2, 1)
755 call s:check_mouse_click(2, 6, 2, 6)
756 call s:check_mouse_click(3, 1, 3, 1)
757 call s:check_mouse_click(3, 6, 3, 6)
758
759 " Make a new first line 11 physical lines tall so it's taller than window
760 " height, to test overflow calculations with really long lines wrapping.
761 normal gg
762 call setline(1, "12345678901234567890"->repeat(11))
763 exe "normal 6\<C-E>"
764 call s:check_mouse_click(5, 1, 1, 201)
765 call s:check_mouse_click(6, 1, 2, 1)
766 call s:check_mouse_click(7, 1, 3, 1)
767
768 let &mouse = save_mouse
769 let &term = save_term
770 let &ttymouse = save_ttymouse
zeertzjqad493ef2024-03-29 10:23:19 +0100771 bwipe!
Yee Cheng Chine6392b12022-11-19 14:31:08 +0000772endfunc
773
Bram Moolenaar870219c2023-01-26 14:14:43 +0000774" this was dividing by zero
Luuk van Baalc8502f92023-05-06 12:40:15 +0100775func Test_smoothscroll_zero_width()
Bram Moolenaar870219c2023-01-26 14:14:43 +0000776 CheckScreendump
777
778 let lines =<< trim END
779 winsize 0 0
780 vsplit
781 vsplit
782 vsplit
783 vsplit
784 vsplit
785 sil norm H
786 set wrap
787 set smoothscroll
788 set number
789 END
790 call writefile(lines, 'XSmoothScrollZero', 'D')
791 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 +0000792 call VerifyScreenDump(buf, 'Test_smoothscroll_zero_1', {})
793
794 call term_sendkeys(buf, ":sil norm \<C-V>\<C-W>\<C-V>\<C-N>\<CR>")
795 call VerifyScreenDump(buf, 'Test_smoothscroll_zero_2', {})
796
797 call StopVimInTerminal(buf)
798endfunc
799
Luuk van Baalc8502f92023-05-06 12:40:15 +0100800" this was unnecessarily inserting lines
801func Test_smoothscroll_ins_lines()
802 CheckScreendump
803
804 let lines =<< trim END
805 set wrap
806 set smoothscroll
807 set scrolloff=0
808 set conceallevel=2
809 call setline(1, [
810 \'line one' .. 'with lots of text in one line '->repeat(2),
811 \'line two',
812 \'line three',
813 \'line four',
814 \'line five'
815 \])
816 END
817 call writefile(lines, 'XSmoothScrollInsLines', 'D')
818 let buf = RunVimInTerminal('-S XSmoothScrollInsLines', #{rows: 6, cols: 40})
819
820 call term_sendkeys(buf, "\<C-E>gjgk")
821 call VerifyScreenDump(buf, 'Test_smooth_ins_lines', {})
822
823 call StopVimInTerminal(buf)
824endfunc
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100825
Luuk van Baal3ce8c382023-05-08 15:51:14 +0100826" this placed the cursor in the command line
827func Test_smoothscroll_cursormoved_line()
828 CheckScreendump
829
830 let lines =<< trim END
831 set smoothscroll
832 call setline(1, [
833 \'',
834 \'_'->repeat(&lines * &columns),
835 \(('_')->repeat(&columns - 2) .. 'xxx')->repeat(2)
836 \])
837 autocmd CursorMoved * eval [line('w0'), line('w$')]
838 call search('xxx')
839 END
840 call writefile(lines, 'XSmoothCursorMovedLine', 'D')
841 let buf = RunVimInTerminal('-S XSmoothCursorMovedLine', #{rows: 6})
842
843 call VerifyScreenDump(buf, 'Test_smooth_cursormoved_line', {})
844
845 call StopVimInTerminal(buf)
846endfunc
847
848func Test_smoothscroll_eob()
849 CheckScreendump
850
851 let lines =<< trim END
852 set smoothscroll
853 call setline(1, ['']->repeat(100))
854 norm G
855 END
856 call writefile(lines, 'XSmoothEob', 'D')
857 let buf = RunVimInTerminal('-S XSmoothEob', #{rows: 10})
858
859 " does not scroll halfway when scrolling to end of buffer
860 call VerifyScreenDump(buf, 'Test_smooth_eob_1', {})
861
862 " cursor is not placed below window
Luuk van Baalb9f5b952024-03-26 18:46:45 +0100863 call term_sendkeys(buf, ":call setline(92, 'a'->repeat(100))\<CR>\<C-L>\<C-B>G")
Luuk van Baal3ce8c382023-05-08 15:51:14 +0100864 call VerifyScreenDump(buf, 'Test_smooth_eob_2', {})
865
866 call StopVimInTerminal(buf)
867endfunc
868
Luuk van Baald49f6462023-05-19 14:04:47 +0100869" skipcol should not reset when doing incremental search on the same word
870func Test_smoothscroll_incsearch()
871 CheckScreendump
872
873 let lines =<< trim END
874 set smoothscroll number scrolloff=0 incsearch
875 call setline(1, repeat([''], 20))
876 call setline(11, repeat('a', 100))
877 call setline(14, 'bbbb')
878 END
879 call writefile(lines, 'XSmoothIncsearch', 'D')
zeertzjq3c802272023-06-03 22:08:33 +0100880 let buf = RunVimInTerminal('-S XSmoothIncsearch', #{rows: 8, cols: 40})
Luuk van Baald49f6462023-05-19 14:04:47 +0100881
882 call term_sendkeys(buf, "/b")
883 call VerifyScreenDump(buf, 'Test_smooth_incsearch_1', {})
884 call term_sendkeys(buf, "b")
885 call VerifyScreenDump(buf, 'Test_smooth_incsearch_2', {})
886 call term_sendkeys(buf, "b")
887 call VerifyScreenDump(buf, 'Test_smooth_incsearch_3', {})
888 call term_sendkeys(buf, "b")
889 call VerifyScreenDump(buf, 'Test_smooth_incsearch_4', {})
890 call term_sendkeys(buf, "\<CR>")
891
892 call StopVimInTerminal(buf)
893endfunc
894
zeertzjq3c802272023-06-03 22:08:33 +0100895" Test scrolling multiple lines and stopping at non-zero skipcol.
896func Test_smoothscroll_multi_skipcol()
897 CheckScreendump
898
899 let lines =<< trim END
900 setlocal cursorline scrolloff=0 smoothscroll
zeertzjqd9a92dc2023-06-05 18:41:35 +0100901 call setline(1, repeat([''], 8))
zeertzjq3c802272023-06-03 22:08:33 +0100902 call setline(3, repeat('a', 50))
zeertzjqd9a92dc2023-06-05 18:41:35 +0100903 call setline(4, repeat('a', 50))
904 call setline(7, 'bbb')
905 call setline(8, 'ccc')
zeertzjq3c802272023-06-03 22:08:33 +0100906 redraw
907 END
908 call writefile(lines, 'XSmoothMultiSkipcol', 'D')
909 let buf = RunVimInTerminal('-S XSmoothMultiSkipcol', #{rows: 10, cols: 40})
910 call VerifyScreenDump(buf, 'Test_smooth_multi_skipcol_1', {})
911
912 call term_sendkeys(buf, "3\<C-E>")
913 call VerifyScreenDump(buf, 'Test_smooth_multi_skipcol_2', {})
914
zeertzjqd9a92dc2023-06-05 18:41:35 +0100915 call term_sendkeys(buf, "2\<C-E>")
916 call VerifyScreenDump(buf, 'Test_smooth_multi_skipcol_3', {})
917
zeertzjq3c802272023-06-03 22:08:33 +0100918 call StopVimInTerminal(buf)
919endfunc
920
fullwaywang8154e642023-06-24 21:58:09 +0100921" this was dividing by zero bug in scroll_cursor_bot
922func Test_smoothscroll_zero_width_scroll_cursor_bot()
923 CheckScreendump
924
925 let lines =<< trim END
926 silent normal yy
927 silent normal 19p
zeertzjqe4298932023-06-26 19:02:43 +0100928 set cpoptions+=n
fullwaywang8154e642023-06-24 21:58:09 +0100929 vsplit
930 vertical resize 0
931 set foldcolumn=1
932 set number
933 set smoothscroll
934 silent normal 20G
935 END
936 call writefile(lines, 'XSmoothScrollZeroBot', 'D')
zeertzjqe4298932023-06-26 19:02:43 +0100937 let buf = RunVimInTerminal('-u NONE -S XSmoothScrollZeroBot', #{rows: 19})
fullwaywang8154e642023-06-24 21:58:09 +0100938 call VerifyScreenDump(buf, 'Test_smoothscroll_zero_bot', {})
939
940 call StopVimInTerminal(buf)
941endfunc
942
Luuk van Baalbb800a72023-11-14 17:05:18 +0100943" scroll_cursor_top() should reset skipcol when it changes topline
944func Test_smoothscroll_cursor_top()
945 CheckScreendump
946
947 let lines =<< trim END
948 set smoothscroll scrolloff=2
949 new | 11resize | wincmd j
950 call setline(1, ['line1', 'line2', 'line3'->repeat(20), 'line4'])
951 exe "norm G3\<C-E>k"
952 END
953 call writefile(lines, 'XSmoothScrollCursorTop', 'D')
zeertzjq5b4d1fc2023-12-03 17:54:10 +0100954 let buf = RunVimInTerminal('-u NONE -S XSmoothScrollCursorTop', #{rows: 12, cols: 40})
Luuk van Baalbb800a72023-11-14 17:05:18 +0100955 call VerifyScreenDump(buf, 'Test_smoothscroll_cursor_top', {})
956
957 call StopVimInTerminal(buf)
958endfunc
959
Christian Brabandtcb0b99f2023-11-14 20:05:59 +0100960" Division by zero, shouldn't crash
961func Test_smoothscroll_crash()
962 CheckScreendump
963
964 let lines =<< trim END
965 20 new
966 vsp
967 put =repeat('aaaa', 20)
968 set nu fdc=1 smoothscroll cpo+=n
969 vert resize 0
970 exe "norm! 0\<c-e>"
971 END
972 call writefile(lines, 'XSmoothScrollCrash', 'D')
zeertzjq5b4d1fc2023-12-03 17:54:10 +0100973 let buf = RunVimInTerminal('-u NONE -S XSmoothScrollCrash', #{rows: 12, cols: 40})
Christian Brabandtcb0b99f2023-11-14 20:05:59 +0100974 call term_sendkeys(buf, "2\<C-E>\<C-L>")
975
976 call StopVimInTerminal(buf)
977endfunc
978
zeertzjq5b4d1fc2023-12-03 17:54:10 +0100979func Test_smoothscroll_insert_bottom()
980 CheckScreendump
981
982 let lines =<< trim END
983 call setline(1, repeat([repeat('A very long line ...', 10)], 5))
984 set wrap smoothscroll scrolloff=0
985 END
986 call writefile(lines, 'XSmoothScrollInsertBottom', 'D')
987 let buf = RunVimInTerminal('-u NONE -S XSmoothScrollInsertBottom', #{rows: 9, cols: 40})
988 call term_sendkeys(buf, "Go123456789\<CR>")
989 call VerifyScreenDump(buf, 'Test_smoothscroll_insert_bottom', {})
990
991 call StopVimInTerminal(buf)
992endfunc
993
zeertzjqc7a8eb52024-05-08 20:22:40 +0200994func Test_smoothscroll_in_qf_window()
995 CheckFeature quickfix
996 CheckScreendump
997
998 let lines =<< trim END
999 set nocompatible display=lastline
1000 copen 5
1001 setlocal number smoothscroll
1002 let g:l = [{'text': 'foo'}] + repeat([{'text': join(range(30))}], 10)
1003 call setqflist(g:l, 'r')
1004 normal! G
1005 wincmd t
1006 let g:l1 = [{'text': join(range(1000))}]
1007 END
1008 call writefile(lines, 'XSmoothScrollInQfWindow', 'D')
1009 let buf = RunVimInTerminal('-u NONE -S XSmoothScrollInQfWindow', #{rows: 20, cols: 60})
1010 call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_1', {})
1011
1012 call term_sendkeys(buf, ":call setqflist([], 'r')\<CR>")
1013 call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_2', {})
1014
1015 call term_sendkeys(buf, ":call setqflist(g:l, 'r')\<CR>")
1016 call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_3', {})
1017
1018 call term_sendkeys(buf, ":call setqflist(g:l1, 'r')\<CR>")
1019 call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_4', {})
1020
1021 call term_sendkeys(buf, "\<C-W>b$\<C-W>t")
1022 call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_5', {})
1023
1024 call term_sendkeys(buf, ":call setqflist([], 'r')\<CR>")
1025 call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_2', {})
1026
1027 call term_sendkeys(buf, ":call setqflist(g:l1, 'r')\<CR>")
1028 call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_4', {})
1029
1030 call term_sendkeys(buf, "\<C-W>b$\<C-W>t")
1031 call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_5', {})
1032
1033 call term_sendkeys(buf, ":call setqflist(g:l, 'r')\<CR>")
1034 call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_3', {})
1035
1036 call StopVimInTerminal(buf)
1037endfunc
1038
Sean Dewar02fcae02024-02-21 19:40:44 +01001039func Test_smoothscroll_in_zero_width_window()
1040 set cpo+=n number smoothscroll
1041 set winwidth=99999 winminwidth=0
1042
1043 vsplit
1044 call assert_equal(0, winwidth(winnr('#')))
1045 call win_execute(win_getid(winnr('#')), "norm! \<C-Y>")
1046
1047 only!
1048 set winwidth& winminwidth&
1049 set cpo-=n nonumber nosmoothscroll
1050endfunc
1051
1052func Test_smoothscroll_textoff_small_winwidth()
1053 set smoothscroll number
1054 call setline(1, 'llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch')
1055 vsplit
1056
1057 let textoff = getwininfo(win_getid())[0].textoff
1058 execute 'vertical resize' textoff + 1
1059 redraw
1060 call assert_equal(0, winsaveview().skipcol)
1061 execute "normal! 0\<C-E>"
1062 redraw
1063 call assert_equal(1, winsaveview().skipcol)
1064 execute 'vertical resize' textoff - 1
1065 " This caused a signed integer overflow.
1066 redraw
1067 call assert_equal(1, winsaveview().skipcol)
1068 execute 'vertical resize' textoff
1069 " This caused an infinite loop.
1070 redraw
1071 call assert_equal(1, winsaveview().skipcol)
1072
1073 %bw!
1074 set smoothscroll& number&
1075endfunc
1076
Luuk van Baalb9f5b952024-03-26 18:46:45 +01001077func Test_smoothscroll_page()
zeertzjqad493ef2024-03-29 10:23:19 +01001078 call NewWindow(10, 40)
1079 setlocal smoothscroll
Luuk van Baalb9f5b952024-03-26 18:46:45 +01001080 call setline(1, 'abcde '->repeat(150))
1081
1082 exe "norm! \<C-F>"
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001083 call assert_equal(400, winsaveview().skipcol)
Luuk van Baalb9f5b952024-03-26 18:46:45 +01001084 exe "norm! \<C-F>"
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001085 call assert_equal(800, winsaveview().skipcol)
Luuk van Baalb9f5b952024-03-26 18:46:45 +01001086 exe "norm! \<C-F>"
1087 call assert_equal(880, winsaveview().skipcol)
1088 exe "norm! \<C-B>"
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001089 call assert_equal(480, winsaveview().skipcol)
Luuk van Baalb9f5b952024-03-26 18:46:45 +01001090 exe "norm! \<C-B>"
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001091 call assert_equal(80, winsaveview().skipcol)
Luuk van Baalb9f5b952024-03-26 18:46:45 +01001092 exe "norm! \<C-B>"
1093 call assert_equal(0, winsaveview().skipcol)
1094
Luuk van Baalcb204e62024-04-02 20:49:45 +02001095 " Half-page scrolling does not go beyond end of buffer and moves the cursor.
Luuk van Baalbd28cae2024-04-03 22:50:40 +02001096 " Even with 'nostartofline', the correct amount of lines is scrolled.
1097 setl nostartofline
Luuk van Baal9148ba82024-04-08 22:27:41 +02001098 exe "norm! 15|\<C-D>"
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001099 call assert_equal(200, winsaveview().skipcol)
Luuk van Baal9148ba82024-04-08 22:27:41 +02001100 call assert_equal(215, col('.'))
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001101 exe "norm! \<C-D>"
1102 call assert_equal(400, winsaveview().skipcol)
Luuk van Baal9148ba82024-04-08 22:27:41 +02001103 call assert_equal(415, col('.'))
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001104 exe "norm! \<C-D>"
Luuk van Baalcb204e62024-04-02 20:49:45 +02001105 call assert_equal(520, winsaveview().skipcol)
Luuk van Baal78c51502024-04-09 21:30:19 +02001106 call assert_equal(615, col('.'))
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001107 exe "norm! \<C-D>"
Luuk van Baalcb204e62024-04-02 20:49:45 +02001108 call assert_equal(520, winsaveview().skipcol)
Luuk van Baal78c51502024-04-09 21:30:19 +02001109 call assert_equal(815, col('.'))
Luuk van Baal9148ba82024-04-08 22:27:41 +02001110 exe "norm! \<C-D>"
Luuk van Baalcb204e62024-04-02 20:49:45 +02001111 call assert_equal(520, winsaveview().skipcol)
Luuk van Baal9148ba82024-04-08 22:27:41 +02001112 call assert_equal(895, col('.'))
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001113 exe "norm! \<C-U>"
Luuk van Baal9148ba82024-04-08 22:27:41 +02001114 call assert_equal(320, winsaveview().skipcol)
1115 call assert_equal(695, col('.'))
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001116 exe "norm! \<C-U>"
Luuk van Baal9148ba82024-04-08 22:27:41 +02001117 call assert_equal(120, winsaveview().skipcol)
1118 call assert_equal(495, col('.'))
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001119 exe "norm! \<C-U>"
1120 call assert_equal(0, winsaveview().skipcol)
Luuk van Baal78c51502024-04-09 21:30:19 +02001121 call assert_equal(295, col('.'))
Luuk van Baal9148ba82024-04-08 22:27:41 +02001122 exe "norm! \<C-U>"
1123 call assert_equal(0, winsaveview().skipcol)
Luuk van Baal78c51502024-04-09 21:30:19 +02001124 call assert_equal(95, col('.'))
Luuk van Baal9148ba82024-04-08 22:27:41 +02001125 exe "norm! \<C-U>"
1126 call assert_equal(0, winsaveview().skipcol)
1127 call assert_equal(15, col('.'))
Luuk van Baalcb204e62024-04-02 20:49:45 +02001128
1129 bwipe!
1130endfunc
1131
1132func Test_smoothscroll_next_topline()
1133 call NewWindow(10, 40)
1134 setlocal smoothscroll
1135 call setline(1, ['abcde '->repeat(150)]->repeat(2))
1136
1137 " Scrolling a screenline that causes the cursor to move to the next buffer
1138 " line should not skip part of that line to bring the cursor into view.
1139 exe "norm! 22\<C-E>"
1140 call assert_equal(880, winsaveview().skipcol)
1141 exe "norm! \<C-E>"
1142 redraw
1143 call assert_equal(0, winsaveview().skipcol)
1144
Luuk van Baalbd28cae2024-04-03 22:50:40 +02001145 " Also when scrolling back.
1146 exe "norm! G\<C-Y>"
1147 redraw
1148 call assert_equal(880, winsaveview().skipcol)
1149
Luuk van Baalcb204e62024-04-02 20:49:45 +02001150 " Cursor in correct place when not in the first screenline of a buffer line.
1151 exe "norm! gg4gj20\<C-D>\<C-D>"
1152 redraw
1153 call assert_equal(2, line('w0'))
1154
Luuk van Baal9148ba82024-04-08 22:27:41 +02001155 " Cursor does not end up above topline, adjusting topline later.
1156 setlocal nu cpo+=n
1157 exe "norm! G$g013\<C-Y>"
1158 redraw
1159 call assert_equal(2, line('.'))
1160 call assert_equal(0, winsaveview().skipcol)
1161
1162 set cpo-=n
Luuk van Baalcb204e62024-04-02 20:49:45 +02001163 bwipe!
1164endfunc
1165
1166func Test_smoothscroll_long_line_zb()
1167 call NewWindow(10, 40)
1168 call setline(1, 'abcde '->repeat(150))
1169
1170 " Also works without 'smoothscroll' when last line of buffer doesn't fit.
1171 " Used to set topline to buffer line count plus one, causing an empty screen.
1172 norm zb
1173 redraw
1174 call assert_equal(1, winsaveview().topline)
1175
1176 " Moving cursor to bottom works on line that doesn't fit with 'smoothscroll'.
1177 " Skipcol was adjusted later for cursor being on not visible part of line.
1178 setlocal smoothscroll
1179 norm zb
1180 redraw
1181 call assert_equal(520, winsaveview().skipcol)
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001182
zeertzjqad493ef2024-03-29 10:23:19 +01001183 bwipe!
Luuk van Baalb9f5b952024-03-26 18:46:45 +01001184endfunc
1185
Luuk van Baalb32055e2024-05-16 20:44:09 +02001186func Test_smooth_long_scrolloff()
1187 CheckScreendump
1188
1189 let lines =<< trim END
1190 set smoothscroll scrolloff=3
Luuk van Baal2e642732024-05-17 18:25:13 +02001191 call setline(1, ['one', 'two long '->repeat(100), 'three', 'four', 'five', 'six'])
Luuk van Baalb32055e2024-05-16 20:44:09 +02001192 END
1193 call writefile(lines, 'XSmoothLongScrolloff', 'D')
1194 let buf = RunVimInTerminal('-u NONE -S XSmoothLongScrolloff', #{rows: 8, cols: 40})
Luuk van Baal2e642732024-05-17 18:25:13 +02001195 call term_sendkeys(buf, ":norm j721|\<CR>")
Luuk van Baalb32055e2024-05-16 20:44:09 +02001196 call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_1', {})
1197
1198 call term_sendkeys(buf, "gj")
1199 call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_2', {})
1200
1201 call term_sendkeys(buf, "gj")
1202 call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_3', {})
1203
1204 call term_sendkeys(buf, "gj")
1205 call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_4', {})
1206
1207 call term_sendkeys(buf, "gj")
1208 call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_5', {})
1209
1210 call term_sendkeys(buf, "gj")
1211 call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_6', {})
1212
1213 call term_sendkeys(buf, "gk")
Luuk van Baalb32055e2024-05-16 20:44:09 +02001214 call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_7', {})
1215
1216 call StopVimInTerminal(buf)
1217endfunc
1218
zeertzjq2c47ab82025-02-13 20:34:34 +01001219func Test_smoothscroll_listchars_eol()
1220 call NewWindow(10, 40)
1221 setlocal list listchars=eol:$ scrolloff=0 smoothscroll
1222 call setline(1, repeat('-', 40))
1223 call append(1, repeat(['foobar'], 10))
1224
1225 normal! G
1226 call assert_equal(2, line('w0'))
1227 call assert_equal(0, winsaveview().skipcol)
1228
1229 exe "normal! \<C-Y>"
1230 call assert_equal(1, line('w0'))
1231 call assert_equal(40, winsaveview().skipcol)
1232
1233 exe "normal! \<C-Y>"
1234 call assert_equal(1, line('w0'))
1235 call assert_equal(0, winsaveview().skipcol)
1236
1237 exe "normal! \<C-Y>"
1238 call assert_equal(1, line('w0'))
1239 call assert_equal(0, winsaveview().skipcol)
1240
1241 exe "normal! \<C-E>"
1242 call assert_equal(1, line('w0'))
1243 call assert_equal(40, winsaveview().skipcol)
1244
1245 exe "normal! \<C-E>"
1246 call assert_equal(2, line('w0'))
1247 call assert_equal(0, winsaveview().skipcol)
1248
1249 for ve in ['', 'all', 'onemore']
1250 let &virtualedit = ve
1251 normal! gg
1252 call assert_equal(1, line('w0'))
1253 call assert_equal(0, winsaveview().skipcol)
1254
1255 exe "normal! \<C-E>"
1256 redraw " redrawing should not cause another scroll
1257 call assert_equal(1, line('w0'))
1258 call assert_equal(40, winsaveview().skipcol)
1259
1260 exe "normal! \<C-E>"
1261 redraw
1262 call assert_equal(2, line('w0'))
1263 call assert_equal(0, winsaveview().skipcol)
1264
1265 if ve != 'all'
1266 call assert_equal([0, 2, 1, 0], getpos('.'))
1267 endif
1268 endfor
1269
1270 set virtualedit&
1271 bwipe!
1272endfunc
1273
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001274" vim: shiftwidth=2 sts=2 expandtab