blob: fa1d032c24847ddea966094d262fef4dc857f8a3 [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
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100305func Test_smoothscroll_wrap_scrolloff_zero()
306 CheckScreendump
307
308 let lines =<< trim END
309 vim9script
310 setline(1, ['Line' .. (' with some text'->repeat(7))]->repeat(7))
311 set smoothscroll scrolloff=0
312 :3
313 END
314 call writefile(lines, 'XSmoothWrap', 'D')
315 let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 8, cols: 40})
316
317 call VerifyScreenDump(buf, 'Test_smooth_wrap_1', {})
318
Bram Moolenaar46b54742022-10-06 15:46:49 +0100319 " moving cursor down - whole bottom line shows
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100320 call term_sendkeys(buf, "j")
321 call VerifyScreenDump(buf, 'Test_smooth_wrap_2', {})
322
323 call term_sendkeys(buf, "\<C-E>j")
324 call VerifyScreenDump(buf, 'Test_smooth_wrap_3', {})
325
326 call term_sendkeys(buf, "G")
327 call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {})
328
Luuk van Baald49f6462023-05-19 14:04:47 +0100329 call term_sendkeys(buf, "4\<C-Y>G")
330 call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {})
331
332 " moving cursor up right after the <<< marker - no need to show whole line
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000333 call term_sendkeys(buf, "2gj3l2k")
Bram Moolenaar46b54742022-10-06 15:46:49 +0100334 call VerifyScreenDump(buf, 'Test_smooth_wrap_5', {})
335
Luuk van Baald49f6462023-05-19 14:04:47 +0100336 " moving cursor up where the <<< marker is - whole top line shows
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000337 call term_sendkeys(buf, "2j02k")
338 call VerifyScreenDump(buf, 'Test_smooth_wrap_6', {})
339
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100340 call StopVimInTerminal(buf)
341endfunc
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100342
Bram Moolenaar8cf34592022-10-08 21:13:40 +0100343func Test_smoothscroll_wrap_long_line()
344 CheckScreendump
345
346 let lines =<< trim END
347 vim9script
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000348 setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(30)) .. ' end', 'four'])
Bram Moolenaar8cf34592022-10-08 21:13:40 +0100349 set smoothscroll scrolloff=0
350 normal 3G10|zt
351 END
352 call writefile(lines, 'XSmoothWrap', 'D')
353 let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 6, cols: 40})
354 call VerifyScreenDump(buf, 'Test_smooth_long_1', {})
355
356 " scrolling up, cursor moves screen line down
357 call term_sendkeys(buf, "\<C-E>")
358 call VerifyScreenDump(buf, 'Test_smooth_long_2', {})
359 call term_sendkeys(buf, "5\<C-E>")
360 call VerifyScreenDump(buf, 'Test_smooth_long_3', {})
361
362 " scrolling down, cursor moves screen line up
363 call term_sendkeys(buf, "5\<C-Y>")
364 call VerifyScreenDump(buf, 'Test_smooth_long_4', {})
365 call term_sendkeys(buf, "\<C-Y>")
366 call VerifyScreenDump(buf, 'Test_smooth_long_5', {})
367
Bram Moolenaar118c2352022-10-09 17:19:27 +0100368 " 'scrolloff' set to 1, scrolling up, cursor moves screen line down
369 call term_sendkeys(buf, ":set scrolloff=1\<CR>")
370 call term_sendkeys(buf, "10|\<C-E>")
371 call VerifyScreenDump(buf, 'Test_smooth_long_6', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000372
Bram Moolenaar118c2352022-10-09 17:19:27 +0100373 " 'scrolloff' set to 1, scrolling down, cursor moves screen line up
374 call term_sendkeys(buf, "\<C-E>")
375 call term_sendkeys(buf, "gjgj")
376 call term_sendkeys(buf, "\<C-Y>")
377 call VerifyScreenDump(buf, 'Test_smooth_long_7', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000378
Bram Moolenaar118c2352022-10-09 17:19:27 +0100379 " 'scrolloff' set to 2, scrolling up, cursor moves screen line down
380 call term_sendkeys(buf, ":set scrolloff=2\<CR>")
381 call term_sendkeys(buf, "10|\<C-E>")
382 call VerifyScreenDump(buf, 'Test_smooth_long_8', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000383
Bram Moolenaar118c2352022-10-09 17:19:27 +0100384 " 'scrolloff' set to 2, scrolling down, cursor moves screen line up
385 call term_sendkeys(buf, "\<C-E>")
386 call term_sendkeys(buf, "gj")
387 call term_sendkeys(buf, "\<C-Y>")
388 call VerifyScreenDump(buf, 'Test_smooth_long_9', {})
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000389
390 " 'scrolloff' set to 0, move cursor down one line.
391 " Cursor should move properly, and since this is a really long line, it will
392 " be put on top of the screen.
393 call term_sendkeys(buf, ":set scrolloff=0\<CR>")
394 call term_sendkeys(buf, "0j")
395 call VerifyScreenDump(buf, 'Test_smooth_long_10', {})
396
Bram Moolenaardb4d88c2022-12-31 15:13:22 +0000397 " Test zt/zz/zb that they work properly when a long line is above it
Luuk van Baal6f37e532023-05-09 21:23:54 +0100398 call term_sendkeys(buf, "zt")
Bram Moolenaardb4d88c2022-12-31 15:13:22 +0000399 call VerifyScreenDump(buf, 'Test_smooth_long_11', {})
400 call term_sendkeys(buf, "zz")
401 call VerifyScreenDump(buf, 'Test_smooth_long_12', {})
Luuk van Baal6f37e532023-05-09 21:23:54 +0100402 call term_sendkeys(buf, "zb")
Bram Moolenaardb4d88c2022-12-31 15:13:22 +0000403 call VerifyScreenDump(buf, 'Test_smooth_long_13', {})
404
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000405 " Repeat the step and move the cursor down again.
406 " This time, use a shorter long line that is barely long enough to span more
407 " than one window. Note that the cursor is at the bottom this time because
408 " Vim prefers to do so if we are scrolling a few lines only.
409 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 +0100410 " Currently visible lines were replaced, test that the lines and cursor
411 " are correctly displayed.
412 call VerifyScreenDump(buf, 'Test_smooth_long_14', {})
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000413 call term_sendkeys(buf, "3Gzt")
414 call term_sendkeys(buf, "j")
Luuk van Baal5d01f862023-05-11 19:24:20 +0100415 call VerifyScreenDump(buf, 'Test_smooth_long_15', {})
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000416
417 " Repeat the step but this time start it when the line is smooth-scrolled by
418 " one line. This tests that the offset calculation is still correct and
419 " still end up scrolling down to the next line with cursor at bottom of
420 " screen.
421 call term_sendkeys(buf, "3Gzt")
422 call term_sendkeys(buf, "\<C-E>j")
Luuk van Baal5d01f862023-05-11 19:24:20 +0100423 call VerifyScreenDump(buf, 'Test_smooth_long_16', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000424
Bram Moolenaar8cf34592022-10-08 21:13:40 +0100425 call StopVimInTerminal(buf)
426endfunc
427
Bram Moolenaar2fbabd22022-10-12 19:53:38 +0100428func Test_smoothscroll_one_long_line()
429 CheckScreendump
430
431 let lines =<< trim END
432 vim9script
433 setline(1, 'with lots of text '->repeat(7))
434 set smoothscroll scrolloff=0
435 END
436 call writefile(lines, 'XSmoothOneLong', 'D')
437 let buf = RunVimInTerminal('-S XSmoothOneLong', #{rows: 6, cols: 40})
438 call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000439
Bram Moolenaar2fbabd22022-10-12 19:53:38 +0100440 call term_sendkeys(buf, "\<C-E>")
441 call VerifyScreenDump(buf, 'Test_smooth_one_long_2', {})
442
443 call term_sendkeys(buf, "0")
444 call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {})
445
446 call StopVimInTerminal(buf)
447endfunc
448
Bram Moolenaar75ac25b2022-11-17 19:00:14 +0000449func Test_smoothscroll_long_line_showbreak()
450 CheckScreendump
451
452 let lines =<< trim END
453 vim9script
454 # a line that spans four screen lines
455 setline(1, 'with lots of text in one line '->repeat(6))
456 set smoothscroll scrolloff=0 showbreak=+++\
457 END
458 call writefile(lines, 'XSmoothLongShowbreak', 'D')
459 let buf = RunVimInTerminal('-S XSmoothLongShowbreak', #{rows: 6, cols: 40})
460 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_1', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000461
Bram Moolenaar75ac25b2022-11-17 19:00:14 +0000462 call term_sendkeys(buf, "\<C-E>")
463 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_2', {})
464
465 call term_sendkeys(buf, "0")
466 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_1', {})
467
468 call StopVimInTerminal(buf)
469endfunc
470
zeertzjqecb87dd2023-06-03 19:45:06 +0100471" Check that 'smoothscroll' marker is drawn over double-width char correctly.
472" Run with multiple encodings.
473func Test_smoothscroll_marker_over_double_width()
474 " Run this in a separate Vim instance to avoid messing up.
475 let after =<< trim [CODE]
476 scriptencoding utf-8
477 call setline(1, 'a'->repeat(&columns) .. '口'->repeat(10))
478 setlocal smoothscroll
479 redraw
480 exe "norm \<C-E>"
481 redraw
482 " Check the chars one by one. Don't check the whole line concatenated.
483 call assert_equal('<', screenstring(1, 1))
484 call assert_equal('<', screenstring(1, 2))
485 call assert_equal('<', screenstring(1, 3))
486 call assert_equal(' ', screenstring(1, 4))
487 call assert_equal('', screenstring(1, 5))
488 call assert_equal('', screenstring(1, 7))
489 call assert_equal('', screenstring(1, 9))
490 call assert_equal('', screenstring(1, 11))
491 call assert_equal('', screenstring(1, 13))
492 call assert_equal('', screenstring(1, 15))
493 call writefile(v:errors, 'Xresult')
494 qall!
495 [CODE]
496
497 let encodings = ['utf-8', 'cp932', 'cp936', 'cp949', 'cp950']
498 if !has('win32')
499 let encodings += ['euc-jp']
500 endif
501 for enc in encodings
502 let msg = 'enc=' .. enc
503 if RunVim([], after, $'--clean --cmd "set encoding={enc}"')
504 call assert_equal([], readfile('Xresult'), msg)
505 endif
506 call delete('Xresult')
507 endfor
508endfunc
509
510" Same as the test above, but check the text actually shown on screen.
511" Only run with UTF-8 encoding.
512func Test_smoothscroll_marker_over_double_width_dump()
513 CheckScreendump
514
515 let lines =<< trim END
516 call setline(1, 'a'->repeat(&columns) .. ''->repeat(10))
517 setlocal smoothscroll
518 END
519 call writefile(lines, 'XSmoothMarkerOverDoubleWidth', 'D')
520 let buf = RunVimInTerminal('-S XSmoothMarkerOverDoubleWidth', #{rows: 6, cols: 40})
521 call VerifyScreenDump(buf, 'Test_smooth_marker_over_double_width_1', {})
522
523 call term_sendkeys(buf, "\<C-E>")
524 call VerifyScreenDump(buf, 'Test_smooth_marker_over_double_width_2', {})
525
526 call StopVimInTerminal(buf)
527endfunc
528
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000529func s:check_col_calc(win_col, win_line, buf_col)
530 call assert_equal(a:win_col, wincol())
531 call assert_equal(a:win_line, winline())
532 call assert_equal(a:buf_col, col('.'))
533endfunc
534
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000535" Test that if the current cursor is on a smooth scrolled line, we correctly
536" reposition it. Also check that we don't miscalculate the values by checking
537" the consistency between wincol() and col('.') as they are calculated
538" separately in code.
539func Test_smoothscroll_cursor_position()
540 call NewWindow(10, 20)
541 setl smoothscroll wrap
542 call setline(1, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
543
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000544 call s:check_col_calc(1, 1, 1)
545 exe "normal \<C-E>"
546
547 " Move down another line to avoid blocking the <<< display
548 call s:check_col_calc(1, 2, 41)
549 exe "normal \<C-Y>"
550 call s:check_col_calc(1, 3, 41)
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000551
Luuk van Baal8667a562023-05-12 15:47:25 +0100552 " Test "g0/g<Home>"
553 exe "normal gg\<C-E>"
554 norm $gkg0
Luuk van Baalcb204e62024-04-02 20:49:45 +0200555 call s:check_col_calc(4, 1, 24)
Luuk van Baal8667a562023-05-12 15:47:25 +0100556
557 " Test moving the cursor behind the <<< display with 'virtualedit'
558 set virtualedit=all
Luuk van Baalcb204e62024-04-02 20:49:45 +0200559 exe "normal \<C-E>gkh"
Luuk van Baal8667a562023-05-12 15:47:25 +0100560 call s:check_col_calc(3, 2, 23)
561 set virtualedit&
562
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000563 normal gg3l
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000564 exe "normal \<C-E>"
565
566 " Move down only 1 line when we are out of the range of the <<< display
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000567 call s:check_col_calc(4, 1, 24)
568 exe "normal \<C-Y>"
569 call s:check_col_calc(4, 2, 24)
570 normal ggg$
571 exe "normal \<C-E>"
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000572 call s:check_col_calc(20, 1, 40)
573 exe "normal \<C-Y>"
574 call s:check_col_calc(20, 2, 40)
575 normal gg
576
577 " Test number, where we have indented lines
578 setl number
579 call s:check_col_calc(5, 1, 1)
580 exe "normal \<C-E>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000581
582 " Move down only 1 line when the <<< display is on the number column
583 call s:check_col_calc(5, 1, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000584 exe "normal \<C-Y>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000585 call s:check_col_calc(5, 2, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000586 normal ggg$
587 exe "normal \<C-E>"
588 call s:check_col_calc(20, 1, 32)
589 exe "normal \<C-Y>"
590 call s:check_col_calc(20, 2, 32)
591 normal gg
592
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000593 setl numberwidth=1
594
595 " Move down another line when numberwidth is too short to cover the whole
596 " <<< display
597 call s:check_col_calc(3, 1, 1)
598 exe "normal \<C-E>"
599 call s:check_col_calc(3, 2, 37)
600 exe "normal \<C-Y>"
601 call s:check_col_calc(3, 3, 37)
602 normal ggl
603
604 " Only move 1 line down when we are just past the <<< display
605 call s:check_col_calc(4, 1, 2)
606 exe "normal \<C-E>"
607 call s:check_col_calc(4, 1, 20)
608 exe "normal \<C-Y>"
609 call s:check_col_calc(4, 2, 20)
610 normal gg
611 setl numberwidth&
612
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000613 " Test number + showbreak, so test that the additional indentation works
614 setl number showbreak=+++
615 call s:check_col_calc(5, 1, 1)
616 exe "normal \<C-E>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000617 call s:check_col_calc(8, 1, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000618 exe "normal \<C-Y>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000619 call s:check_col_calc(8, 2, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000620 normal gg
621
622 " Test number + cpo+=n mode, where wrapped lines aren't indented
623 setl number cpo+=n showbreak=
624 call s:check_col_calc(5, 1, 1)
625 exe "normal \<C-E>"
626 call s:check_col_calc(1, 2, 37)
627 exe "normal \<C-Y>"
628 call s:check_col_calc(1, 3, 37)
629 normal gg
630
Luuk van Baal24b62ec2023-05-13 14:12:15 +0100631 " Test list + listchars "precedes", where there is always 1 overlap
632 " regardless of number and cpo-=n.
633 setl number list listchars=precedes:< cpo-=n
634 call s:check_col_calc(5, 1, 1)
Luuk van Baal798fa762023-05-15 18:17:43 +0100635 exe "normal 3|\<C-E>h"
Luuk van Baal24b62ec2023-05-13 14:12:15 +0100636 call s:check_col_calc(6, 1, 18)
637 norm h
638 call s:check_col_calc(5, 2, 17)
639 normal gg
640
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000641 bwipe!
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000642endfunc
643
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000644func Test_smoothscroll_cursor_scrolloff()
645 call NewWindow(10, 20)
646 setl smoothscroll wrap
647 setl scrolloff=3
Bram Moolenaar94722c52023-01-28 19:19:03 +0000648
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000649 " 120 chars are 6 screen lines
650 call setline(1, "abcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRST")
651 call setline(2, "below")
652
653 call s:check_col_calc(1, 1, 1)
654
655 " CTRL-E shows "<<<DEFG...", cursor move four lines down
656 exe "normal \<C-E>"
657 call s:check_col_calc(1, 4, 81)
658
659 " cursor on start of second line, "gk" moves into first line, skipcol doesn't
660 " change
661 exe "normal G0gk"
662 call s:check_col_calc(1, 5, 101)
663
664 " move cursor left one window width worth, scrolls one screen line
665 exe "normal 20h"
666 call s:check_col_calc(1, 5, 81)
667
668 " move cursor left one window width worth, scrolls one screen line
669 exe "normal 20h"
670 call s:check_col_calc(1, 4, 61)
671
Bram Moolenaarb21b8e92022-12-03 18:35:07 +0000672 " cursor on last line, "gk" should not cause a scroll
673 set scrolloff=0
674 normal G0
675 call s:check_col_calc(1, 7, 1)
676 normal gk
677 call s:check_col_calc(1, 6, 101)
678
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000679 bwipe!
680endfunc
681
682
Yee Cheng Chine6392b12022-11-19 14:31:08 +0000683" Test that mouse picking is still accurate when we have smooth scrolled lines
684func Test_smoothscroll_mouse_pos()
685 CheckNotGui
686 CheckUnix
687
688 let save_mouse = &mouse
689 let save_term = &term
690 let save_ttymouse = &ttymouse
691 set mouse=a term=xterm ttymouse=xterm2
692
693 call NewWindow(10, 20)
694 setl smoothscroll wrap
695 " First line will wrap to 3 physical lines. 2nd/3rd lines are short lines.
696 call setline(1, ["abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", "line 2", "line 3"])
697
698 func s:check_mouse_click(row, col, buf_row, buf_col)
699 call MouseLeftClick(a:row, a:col)
700
701 call assert_equal(a:col, wincol())
702 call assert_equal(a:row, winline())
703 call assert_equal(a:buf_row, line('.'))
704 call assert_equal(a:buf_col, col('.'))
705 endfunc
706
707 " Check that clicking without scroll works first.
708 call s:check_mouse_click(3, 5, 1, 45)
709 call s:check_mouse_click(4, 1, 2, 1)
710 call s:check_mouse_click(4, 6, 2, 6)
711 call s:check_mouse_click(5, 1, 3, 1)
712 call s:check_mouse_click(5, 6, 3, 6)
713
714 " Smooth scroll, and checks that this didn't mess up mouse clicking
715 exe "normal \<C-E>"
716 call s:check_mouse_click(2, 5, 1, 45)
717 call s:check_mouse_click(3, 1, 2, 1)
718 call s:check_mouse_click(3, 6, 2, 6)
719 call s:check_mouse_click(4, 1, 3, 1)
720 call s:check_mouse_click(4, 6, 3, 6)
721
722 exe "normal \<C-E>"
723 call s:check_mouse_click(1, 5, 1, 45)
724 call s:check_mouse_click(2, 1, 2, 1)
725 call s:check_mouse_click(2, 6, 2, 6)
726 call s:check_mouse_click(3, 1, 3, 1)
727 call s:check_mouse_click(3, 6, 3, 6)
728
729 " Make a new first line 11 physical lines tall so it's taller than window
730 " height, to test overflow calculations with really long lines wrapping.
731 normal gg
732 call setline(1, "12345678901234567890"->repeat(11))
733 exe "normal 6\<C-E>"
734 call s:check_mouse_click(5, 1, 1, 201)
735 call s:check_mouse_click(6, 1, 2, 1)
736 call s:check_mouse_click(7, 1, 3, 1)
737
738 let &mouse = save_mouse
739 let &term = save_term
740 let &ttymouse = save_ttymouse
zeertzjqad493ef2024-03-29 10:23:19 +0100741 bwipe!
Yee Cheng Chine6392b12022-11-19 14:31:08 +0000742endfunc
743
Bram Moolenaar870219c2023-01-26 14:14:43 +0000744" this was dividing by zero
Luuk van Baalc8502f92023-05-06 12:40:15 +0100745func Test_smoothscroll_zero_width()
Bram Moolenaar870219c2023-01-26 14:14:43 +0000746 CheckScreendump
747
748 let lines =<< trim END
749 winsize 0 0
750 vsplit
751 vsplit
752 vsplit
753 vsplit
754 vsplit
755 sil norm H
756 set wrap
757 set smoothscroll
758 set number
759 END
760 call writefile(lines, 'XSmoothScrollZero', 'D')
761 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 +0000762 call VerifyScreenDump(buf, 'Test_smoothscroll_zero_1', {})
763
764 call term_sendkeys(buf, ":sil norm \<C-V>\<C-W>\<C-V>\<C-N>\<CR>")
765 call VerifyScreenDump(buf, 'Test_smoothscroll_zero_2', {})
766
767 call StopVimInTerminal(buf)
768endfunc
769
Luuk van Baalc8502f92023-05-06 12:40:15 +0100770" this was unnecessarily inserting lines
771func Test_smoothscroll_ins_lines()
772 CheckScreendump
773
774 let lines =<< trim END
775 set wrap
776 set smoothscroll
777 set scrolloff=0
778 set conceallevel=2
779 call setline(1, [
780 \'line one' .. 'with lots of text in one line '->repeat(2),
781 \'line two',
782 \'line three',
783 \'line four',
784 \'line five'
785 \])
786 END
787 call writefile(lines, 'XSmoothScrollInsLines', 'D')
788 let buf = RunVimInTerminal('-S XSmoothScrollInsLines', #{rows: 6, cols: 40})
789
790 call term_sendkeys(buf, "\<C-E>gjgk")
791 call VerifyScreenDump(buf, 'Test_smooth_ins_lines', {})
792
793 call StopVimInTerminal(buf)
794endfunc
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100795
Luuk van Baal3ce8c382023-05-08 15:51:14 +0100796" this placed the cursor in the command line
797func Test_smoothscroll_cursormoved_line()
798 CheckScreendump
799
800 let lines =<< trim END
801 set smoothscroll
802 call setline(1, [
803 \'',
804 \'_'->repeat(&lines * &columns),
805 \(('_')->repeat(&columns - 2) .. 'xxx')->repeat(2)
806 \])
807 autocmd CursorMoved * eval [line('w0'), line('w$')]
808 call search('xxx')
809 END
810 call writefile(lines, 'XSmoothCursorMovedLine', 'D')
811 let buf = RunVimInTerminal('-S XSmoothCursorMovedLine', #{rows: 6})
812
813 call VerifyScreenDump(buf, 'Test_smooth_cursormoved_line', {})
814
815 call StopVimInTerminal(buf)
816endfunc
817
818func Test_smoothscroll_eob()
819 CheckScreendump
820
821 let lines =<< trim END
822 set smoothscroll
823 call setline(1, ['']->repeat(100))
824 norm G
825 END
826 call writefile(lines, 'XSmoothEob', 'D')
827 let buf = RunVimInTerminal('-S XSmoothEob', #{rows: 10})
828
829 " does not scroll halfway when scrolling to end of buffer
830 call VerifyScreenDump(buf, 'Test_smooth_eob_1', {})
831
832 " cursor is not placed below window
Luuk van Baalb9f5b952024-03-26 18:46:45 +0100833 call term_sendkeys(buf, ":call setline(92, 'a'->repeat(100))\<CR>\<C-L>\<C-B>G")
Luuk van Baal3ce8c382023-05-08 15:51:14 +0100834 call VerifyScreenDump(buf, 'Test_smooth_eob_2', {})
835
836 call StopVimInTerminal(buf)
837endfunc
838
Luuk van Baald49f6462023-05-19 14:04:47 +0100839" skipcol should not reset when doing incremental search on the same word
840func Test_smoothscroll_incsearch()
841 CheckScreendump
842
843 let lines =<< trim END
844 set smoothscroll number scrolloff=0 incsearch
845 call setline(1, repeat([''], 20))
846 call setline(11, repeat('a', 100))
847 call setline(14, 'bbbb')
848 END
849 call writefile(lines, 'XSmoothIncsearch', 'D')
zeertzjq3c802272023-06-03 22:08:33 +0100850 let buf = RunVimInTerminal('-S XSmoothIncsearch', #{rows: 8, cols: 40})
Luuk van Baald49f6462023-05-19 14:04:47 +0100851
852 call term_sendkeys(buf, "/b")
853 call VerifyScreenDump(buf, 'Test_smooth_incsearch_1', {})
854 call term_sendkeys(buf, "b")
855 call VerifyScreenDump(buf, 'Test_smooth_incsearch_2', {})
856 call term_sendkeys(buf, "b")
857 call VerifyScreenDump(buf, 'Test_smooth_incsearch_3', {})
858 call term_sendkeys(buf, "b")
859 call VerifyScreenDump(buf, 'Test_smooth_incsearch_4', {})
860 call term_sendkeys(buf, "\<CR>")
861
862 call StopVimInTerminal(buf)
863endfunc
864
zeertzjq3c802272023-06-03 22:08:33 +0100865" Test scrolling multiple lines and stopping at non-zero skipcol.
866func Test_smoothscroll_multi_skipcol()
867 CheckScreendump
868
869 let lines =<< trim END
870 setlocal cursorline scrolloff=0 smoothscroll
zeertzjqd9a92dc2023-06-05 18:41:35 +0100871 call setline(1, repeat([''], 8))
zeertzjq3c802272023-06-03 22:08:33 +0100872 call setline(3, repeat('a', 50))
zeertzjqd9a92dc2023-06-05 18:41:35 +0100873 call setline(4, repeat('a', 50))
874 call setline(7, 'bbb')
875 call setline(8, 'ccc')
zeertzjq3c802272023-06-03 22:08:33 +0100876 redraw
877 END
878 call writefile(lines, 'XSmoothMultiSkipcol', 'D')
879 let buf = RunVimInTerminal('-S XSmoothMultiSkipcol', #{rows: 10, cols: 40})
880 call VerifyScreenDump(buf, 'Test_smooth_multi_skipcol_1', {})
881
882 call term_sendkeys(buf, "3\<C-E>")
883 call VerifyScreenDump(buf, 'Test_smooth_multi_skipcol_2', {})
884
zeertzjqd9a92dc2023-06-05 18:41:35 +0100885 call term_sendkeys(buf, "2\<C-E>")
886 call VerifyScreenDump(buf, 'Test_smooth_multi_skipcol_3', {})
887
zeertzjq3c802272023-06-03 22:08:33 +0100888 call StopVimInTerminal(buf)
889endfunc
890
fullwaywang8154e642023-06-24 21:58:09 +0100891" this was dividing by zero bug in scroll_cursor_bot
892func Test_smoothscroll_zero_width_scroll_cursor_bot()
893 CheckScreendump
894
895 let lines =<< trim END
896 silent normal yy
897 silent normal 19p
zeertzjqe4298932023-06-26 19:02:43 +0100898 set cpoptions+=n
fullwaywang8154e642023-06-24 21:58:09 +0100899 vsplit
900 vertical resize 0
901 set foldcolumn=1
902 set number
903 set smoothscroll
904 silent normal 20G
905 END
906 call writefile(lines, 'XSmoothScrollZeroBot', 'D')
zeertzjqe4298932023-06-26 19:02:43 +0100907 let buf = RunVimInTerminal('-u NONE -S XSmoothScrollZeroBot', #{rows: 19})
fullwaywang8154e642023-06-24 21:58:09 +0100908 call VerifyScreenDump(buf, 'Test_smoothscroll_zero_bot', {})
909
910 call StopVimInTerminal(buf)
911endfunc
912
Luuk van Baalbb800a72023-11-14 17:05:18 +0100913" scroll_cursor_top() should reset skipcol when it changes topline
914func Test_smoothscroll_cursor_top()
915 CheckScreendump
916
917 let lines =<< trim END
918 set smoothscroll scrolloff=2
919 new | 11resize | wincmd j
920 call setline(1, ['line1', 'line2', 'line3'->repeat(20), 'line4'])
921 exe "norm G3\<C-E>k"
922 END
923 call writefile(lines, 'XSmoothScrollCursorTop', 'D')
zeertzjq5b4d1fc2023-12-03 17:54:10 +0100924 let buf = RunVimInTerminal('-u NONE -S XSmoothScrollCursorTop', #{rows: 12, cols: 40})
Luuk van Baalbb800a72023-11-14 17:05:18 +0100925 call VerifyScreenDump(buf, 'Test_smoothscroll_cursor_top', {})
926
927 call StopVimInTerminal(buf)
928endfunc
929
Christian Brabandtcb0b99f2023-11-14 20:05:59 +0100930" Division by zero, shouldn't crash
931func Test_smoothscroll_crash()
932 CheckScreendump
933
934 let lines =<< trim END
935 20 new
936 vsp
937 put =repeat('aaaa', 20)
938 set nu fdc=1 smoothscroll cpo+=n
939 vert resize 0
940 exe "norm! 0\<c-e>"
941 END
942 call writefile(lines, 'XSmoothScrollCrash', 'D')
zeertzjq5b4d1fc2023-12-03 17:54:10 +0100943 let buf = RunVimInTerminal('-u NONE -S XSmoothScrollCrash', #{rows: 12, cols: 40})
Christian Brabandtcb0b99f2023-11-14 20:05:59 +0100944 call term_sendkeys(buf, "2\<C-E>\<C-L>")
945
946 call StopVimInTerminal(buf)
947endfunc
948
zeertzjq5b4d1fc2023-12-03 17:54:10 +0100949func Test_smoothscroll_insert_bottom()
950 CheckScreendump
951
952 let lines =<< trim END
953 call setline(1, repeat([repeat('A very long line ...', 10)], 5))
954 set wrap smoothscroll scrolloff=0
955 END
956 call writefile(lines, 'XSmoothScrollInsertBottom', 'D')
957 let buf = RunVimInTerminal('-u NONE -S XSmoothScrollInsertBottom', #{rows: 9, cols: 40})
958 call term_sendkeys(buf, "Go123456789\<CR>")
959 call VerifyScreenDump(buf, 'Test_smoothscroll_insert_bottom', {})
960
961 call StopVimInTerminal(buf)
962endfunc
963
zeertzjqc7a8eb52024-05-08 20:22:40 +0200964func Test_smoothscroll_in_qf_window()
965 CheckFeature quickfix
966 CheckScreendump
967
968 let lines =<< trim END
969 set nocompatible display=lastline
970 copen 5
971 setlocal number smoothscroll
972 let g:l = [{'text': 'foo'}] + repeat([{'text': join(range(30))}], 10)
973 call setqflist(g:l, 'r')
974 normal! G
975 wincmd t
976 let g:l1 = [{'text': join(range(1000))}]
977 END
978 call writefile(lines, 'XSmoothScrollInQfWindow', 'D')
979 let buf = RunVimInTerminal('-u NONE -S XSmoothScrollInQfWindow', #{rows: 20, cols: 60})
980 call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_1', {})
981
982 call term_sendkeys(buf, ":call setqflist([], 'r')\<CR>")
983 call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_2', {})
984
985 call term_sendkeys(buf, ":call setqflist(g:l, 'r')\<CR>")
986 call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_3', {})
987
988 call term_sendkeys(buf, ":call setqflist(g:l1, 'r')\<CR>")
989 call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_4', {})
990
991 call term_sendkeys(buf, "\<C-W>b$\<C-W>t")
992 call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_5', {})
993
994 call term_sendkeys(buf, ":call setqflist([], 'r')\<CR>")
995 call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_2', {})
996
997 call term_sendkeys(buf, ":call setqflist(g:l1, 'r')\<CR>")
998 call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_4', {})
999
1000 call term_sendkeys(buf, "\<C-W>b$\<C-W>t")
1001 call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_5', {})
1002
1003 call term_sendkeys(buf, ":call setqflist(g:l, 'r')\<CR>")
1004 call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_3', {})
1005
1006 call StopVimInTerminal(buf)
1007endfunc
1008
Sean Dewar02fcae02024-02-21 19:40:44 +01001009func Test_smoothscroll_in_zero_width_window()
1010 set cpo+=n number smoothscroll
1011 set winwidth=99999 winminwidth=0
1012
1013 vsplit
1014 call assert_equal(0, winwidth(winnr('#')))
1015 call win_execute(win_getid(winnr('#')), "norm! \<C-Y>")
1016
1017 only!
1018 set winwidth& winminwidth&
1019 set cpo-=n nonumber nosmoothscroll
1020endfunc
1021
1022func Test_smoothscroll_textoff_small_winwidth()
1023 set smoothscroll number
1024 call setline(1, 'llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch')
1025 vsplit
1026
1027 let textoff = getwininfo(win_getid())[0].textoff
1028 execute 'vertical resize' textoff + 1
1029 redraw
1030 call assert_equal(0, winsaveview().skipcol)
1031 execute "normal! 0\<C-E>"
1032 redraw
1033 call assert_equal(1, winsaveview().skipcol)
1034 execute 'vertical resize' textoff - 1
1035 " This caused a signed integer overflow.
1036 redraw
1037 call assert_equal(1, winsaveview().skipcol)
1038 execute 'vertical resize' textoff
1039 " This caused an infinite loop.
1040 redraw
1041 call assert_equal(1, winsaveview().skipcol)
1042
1043 %bw!
1044 set smoothscroll& number&
1045endfunc
1046
Luuk van Baalb9f5b952024-03-26 18:46:45 +01001047func Test_smoothscroll_page()
zeertzjqad493ef2024-03-29 10:23:19 +01001048 call NewWindow(10, 40)
1049 setlocal smoothscroll
Luuk van Baalb9f5b952024-03-26 18:46:45 +01001050 call setline(1, 'abcde '->repeat(150))
1051
1052 exe "norm! \<C-F>"
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001053 call assert_equal(400, winsaveview().skipcol)
Luuk van Baalb9f5b952024-03-26 18:46:45 +01001054 exe "norm! \<C-F>"
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001055 call assert_equal(800, winsaveview().skipcol)
Luuk van Baalb9f5b952024-03-26 18:46:45 +01001056 exe "norm! \<C-F>"
1057 call assert_equal(880, winsaveview().skipcol)
1058 exe "norm! \<C-B>"
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001059 call assert_equal(480, winsaveview().skipcol)
Luuk van Baalb9f5b952024-03-26 18:46:45 +01001060 exe "norm! \<C-B>"
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001061 call assert_equal(80, winsaveview().skipcol)
Luuk van Baalb9f5b952024-03-26 18:46:45 +01001062 exe "norm! \<C-B>"
1063 call assert_equal(0, winsaveview().skipcol)
1064
Luuk van Baalcb204e62024-04-02 20:49:45 +02001065 " Half-page scrolling does not go beyond end of buffer and moves the cursor.
Luuk van Baalbd28cae2024-04-03 22:50:40 +02001066 " Even with 'nostartofline', the correct amount of lines is scrolled.
1067 setl nostartofline
Luuk van Baal9148ba82024-04-08 22:27:41 +02001068 exe "norm! 15|\<C-D>"
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001069 call assert_equal(200, winsaveview().skipcol)
Luuk van Baal9148ba82024-04-08 22:27:41 +02001070 call assert_equal(215, col('.'))
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001071 exe "norm! \<C-D>"
1072 call assert_equal(400, winsaveview().skipcol)
Luuk van Baal9148ba82024-04-08 22:27:41 +02001073 call assert_equal(415, col('.'))
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001074 exe "norm! \<C-D>"
Luuk van Baalcb204e62024-04-02 20:49:45 +02001075 call assert_equal(520, winsaveview().skipcol)
Luuk van Baal78c51502024-04-09 21:30:19 +02001076 call assert_equal(615, col('.'))
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001077 exe "norm! \<C-D>"
Luuk van Baalcb204e62024-04-02 20:49:45 +02001078 call assert_equal(520, winsaveview().skipcol)
Luuk van Baal78c51502024-04-09 21:30:19 +02001079 call assert_equal(815, col('.'))
Luuk van Baal9148ba82024-04-08 22:27:41 +02001080 exe "norm! \<C-D>"
Luuk van Baalcb204e62024-04-02 20:49:45 +02001081 call assert_equal(520, winsaveview().skipcol)
Luuk van Baal9148ba82024-04-08 22:27:41 +02001082 call assert_equal(895, col('.'))
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001083 exe "norm! \<C-U>"
Luuk van Baal9148ba82024-04-08 22:27:41 +02001084 call assert_equal(320, winsaveview().skipcol)
1085 call assert_equal(695, col('.'))
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001086 exe "norm! \<C-U>"
Luuk van Baal9148ba82024-04-08 22:27:41 +02001087 call assert_equal(120, winsaveview().skipcol)
1088 call assert_equal(495, col('.'))
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001089 exe "norm! \<C-U>"
1090 call assert_equal(0, winsaveview().skipcol)
Luuk van Baal78c51502024-04-09 21:30:19 +02001091 call assert_equal(295, col('.'))
Luuk van Baal9148ba82024-04-08 22:27:41 +02001092 exe "norm! \<C-U>"
1093 call assert_equal(0, winsaveview().skipcol)
Luuk van Baal78c51502024-04-09 21:30:19 +02001094 call assert_equal(95, col('.'))
Luuk van Baal9148ba82024-04-08 22:27:41 +02001095 exe "norm! \<C-U>"
1096 call assert_equal(0, winsaveview().skipcol)
1097 call assert_equal(15, col('.'))
Luuk van Baalcb204e62024-04-02 20:49:45 +02001098
1099 bwipe!
1100endfunc
1101
1102func Test_smoothscroll_next_topline()
1103 call NewWindow(10, 40)
1104 setlocal smoothscroll
1105 call setline(1, ['abcde '->repeat(150)]->repeat(2))
1106
1107 " Scrolling a screenline that causes the cursor to move to the next buffer
1108 " line should not skip part of that line to bring the cursor into view.
1109 exe "norm! 22\<C-E>"
1110 call assert_equal(880, winsaveview().skipcol)
1111 exe "norm! \<C-E>"
1112 redraw
1113 call assert_equal(0, winsaveview().skipcol)
1114
Luuk van Baalbd28cae2024-04-03 22:50:40 +02001115 " Also when scrolling back.
1116 exe "norm! G\<C-Y>"
1117 redraw
1118 call assert_equal(880, winsaveview().skipcol)
1119
Luuk van Baalcb204e62024-04-02 20:49:45 +02001120 " Cursor in correct place when not in the first screenline of a buffer line.
1121 exe "norm! gg4gj20\<C-D>\<C-D>"
1122 redraw
1123 call assert_equal(2, line('w0'))
1124
Luuk van Baal9148ba82024-04-08 22:27:41 +02001125 " Cursor does not end up above topline, adjusting topline later.
1126 setlocal nu cpo+=n
1127 exe "norm! G$g013\<C-Y>"
1128 redraw
1129 call assert_equal(2, line('.'))
1130 call assert_equal(0, winsaveview().skipcol)
1131
1132 set cpo-=n
Luuk van Baalcb204e62024-04-02 20:49:45 +02001133 bwipe!
1134endfunc
1135
1136func Test_smoothscroll_long_line_zb()
1137 call NewWindow(10, 40)
1138 call setline(1, 'abcde '->repeat(150))
1139
1140 " Also works without 'smoothscroll' when last line of buffer doesn't fit.
1141 " Used to set topline to buffer line count plus one, causing an empty screen.
1142 norm zb
1143 redraw
1144 call assert_equal(1, winsaveview().topline)
1145
1146 " Moving cursor to bottom works on line that doesn't fit with 'smoothscroll'.
1147 " Skipcol was adjusted later for cursor being on not visible part of line.
1148 setlocal smoothscroll
1149 norm zb
1150 redraw
1151 call assert_equal(520, winsaveview().skipcol)
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001152
zeertzjqad493ef2024-03-29 10:23:19 +01001153 bwipe!
Luuk van Baalb9f5b952024-03-26 18:46:45 +01001154endfunc
1155
Luuk van Baalb32055e2024-05-16 20:44:09 +02001156func Test_smooth_long_scrolloff()
1157 CheckScreendump
1158
1159 let lines =<< trim END
1160 set smoothscroll scrolloff=3
1161 call setline(1, ['one', 'two long'->repeat(100), 'three', 'four', 'five', 'six'])
1162 END
1163 call writefile(lines, 'XSmoothLongScrolloff', 'D')
1164 let buf = RunVimInTerminal('-u NONE -S XSmoothLongScrolloff', #{rows: 8, cols: 40})
1165 "FIXME: empty screen due to reset_skipcol()/curs_columns() shenanigans
1166 call term_sendkeys(buf, ":norm j601|\<CR>")
1167 call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_1', {})
1168
1169 call term_sendkeys(buf, "gj")
1170 call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_2', {})
1171
1172 call term_sendkeys(buf, "gj")
1173 call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_3', {})
1174
1175 call term_sendkeys(buf, "gj")
1176 call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_4', {})
1177
1178 call term_sendkeys(buf, "gj")
1179 call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_5', {})
1180
1181 call term_sendkeys(buf, "gj")
1182 call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_6', {})
1183
1184 call term_sendkeys(buf, "gk")
1185 "FIXME: empty screen due to reset_skipcol()/curs_columns() shenanigans
1186 call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_7', {})
1187
1188 call StopVimInTerminal(buf)
1189endfunc
1190
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001191" vim: shiftwidth=2 sts=2 expandtab