blob: 4e29976176e5084bb4f7905bbb24f5d97b8ef4de [file] [log] [blame]
zeertzjq8e5f26e2023-10-04 21:45:33 +02001" Test for 'scroll', 'scrolloff', 'smoothscroll', etc.
Bram Moolenaarf6196f42022-10-02 21:29:55 +01002
Christian Brabandteb380b92025-07-07 20:53:55 +02003source util/screendump.vim
4source util/mouse.vim
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01005
6func Test_reset_scroll()
7 let scr = &l:scroll
8
9 setlocal scroll=1
10 setlocal scroll&
11 call assert_equal(scr, &l:scroll)
12
13 setlocal scroll=1
14 setlocal scroll=0
15 call assert_equal(scr, &l:scroll)
16
17 try
18 execute 'setlocal scroll=' . (winheight(0) + 1)
19 " not reached
20 call assert_false(1)
21 catch
22 call assert_exception('E49:')
23 endtry
24
25 split
26
27 let scr = &l:scroll
28
29 setlocal scroll=1
30 setlocal scroll&
31 call assert_equal(scr, &l:scroll)
32
33 setlocal scroll=1
34 setlocal scroll=0
35 call assert_equal(scr, &l:scroll)
36
37 quit!
38endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020039
Bram Moolenaar1d6539c2023-02-14 17:41:20 +000040func Test_scolloff_even_line_count()
zeertzjq8e5f26e2023-10-04 21:45:33 +020041 new
42 resize 6
43 setlocal scrolloff=3
44 call setline(1, range(20))
45 normal 2j
46 call assert_equal(1, getwininfo(win_getid())[0].topline)
47 normal j
48 call assert_equal(1, getwininfo(win_getid())[0].topline)
49 normal j
50 call assert_equal(2, getwininfo(win_getid())[0].topline)
51 normal j
52 call assert_equal(3, getwininfo(win_getid())[0].topline)
Bram Moolenaar1d6539c2023-02-14 17:41:20 +000053
zeertzjq8e5f26e2023-10-04 21:45:33 +020054 bwipe!
55endfunc
56
57func Test_mouse_scroll_inactive_with_cursorbind()
58 for scb in [0, 1]
59 for so in [0, 1, 2]
60 let msg = $'scb={scb} so={so}'
61
62 new | only
63 let w1 = win_getid()
64 setlocal cursorbind
65 let &l:scb = scb
66 let &l:so = so
67 call setline(1, range(101, 109))
68 rightbelow vnew
69 let w2 = win_getid()
70 setlocal cursorbind
71 let &l:scb = scb
72 let &l:so = so
73 call setline(1, range(101, 109))
74
75 normal! $
76 call assert_equal(3, col('.', w1), msg)
77 call assert_equal(3, col('.', w2), msg)
78 call test_setmouse(1, 1)
79 call feedkeys("\<ScrollWheelDown>", 'xt')
80 call assert_equal(4, line('w0', w1), msg)
81 call assert_equal(4 + so, line('.', w1), msg)
82 call assert_equal(1, line('w0', w2), msg)
83 call assert_equal(1, line('.', w2), msg)
84 call feedkeys("\<ScrollWheelDown>", 'xt')
85 call assert_equal(7, line('w0', w1), msg)
86 call assert_equal(7 + so, line('.', w1), msg)
87 call assert_equal(1, line('w0', w2), msg)
88 call assert_equal(1, line('.', w2), msg)
89 call feedkeys("\<ScrollWheelUp>", 'xt')
90 call assert_equal(4, line('w0', w1), msg)
91 call assert_equal(7 + so, line('.', w1), msg)
92 call assert_equal(1, line('w0', w2), msg)
93 call assert_equal(1, line('.', w2), msg)
94 call feedkeys("\<ScrollWheelUp>", 'xt')
95 call assert_equal(1, line('w0', w1), msg)
96 call assert_equal(7 + so, line('.', w1), msg)
97 call assert_equal(1, line('w0', w2), msg)
98 call assert_equal(1, line('.', w2), msg)
99 normal! 0
100 call assert_equal(1, line('.', w1), msg)
101 call assert_equal(1, col('.', w1), msg)
102 call assert_equal(1, line('.', w2), msg)
103 call assert_equal(1, col('.', w2), msg)
104
105 bwipe!
106 bwipe!
107 endfor
108 endfor
Bram Moolenaar1d6539c2023-02-14 17:41:20 +0000109endfunc
110
Bram Moolenaar8df97482022-10-03 12:11:13 +0100111func Test_CtrlE_CtrlY_stop_at_end()
112 enew
113 call setline(1, ['one', 'two'])
114 set number
115 exe "normal \<C-Y>"
116 call assert_equal([" 1 one "], ScreenLines(1, 10))
117 exe "normal \<C-E>\<C-E>\<C-E>"
118 call assert_equal([" 2 two "], ScreenLines(1, 10))
119
120 bwipe!
121 set nonumber
122endfunc
123
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100124func Test_smoothscroll_CtrlE_CtrlY()
125 CheckScreendump
126
127 let lines =<< trim END
128 vim9script
129 setline(1, [
130 'line one',
131 'word '->repeat(20),
132 'line three',
133 'long word '->repeat(7),
134 'line',
135 'line',
136 'line',
137 ])
138 set smoothscroll
139 :5
140 END
141 call writefile(lines, 'XSmoothScroll', 'D')
142 let buf = RunVimInTerminal('-S XSmoothScroll', #{rows: 12, cols: 40})
143
144 call term_sendkeys(buf, "\<C-E>")
145 call VerifyScreenDump(buf, 'Test_smoothscroll_1', {})
146 call term_sendkeys(buf, "\<C-E>")
147 call VerifyScreenDump(buf, 'Test_smoothscroll_2', {})
148 call term_sendkeys(buf, "\<C-E>")
149 call VerifyScreenDump(buf, 'Test_smoothscroll_3', {})
150 call term_sendkeys(buf, "\<C-E>")
151 call VerifyScreenDump(buf, 'Test_smoothscroll_4', {})
152
153 call term_sendkeys(buf, "\<C-Y>")
154 call VerifyScreenDump(buf, 'Test_smoothscroll_5', {})
155 call term_sendkeys(buf, "\<C-Y>")
156 call VerifyScreenDump(buf, 'Test_smoothscroll_6', {})
157 call term_sendkeys(buf, "\<C-Y>")
158 call VerifyScreenDump(buf, 'Test_smoothscroll_7', {})
159 call term_sendkeys(buf, "\<C-Y>")
160 call VerifyScreenDump(buf, 'Test_smoothscroll_8', {})
161
Bram Moolenaar6b2d4ff2022-10-03 14:06:02 +0100162 if has('folding')
163 call term_sendkeys(buf, ":set foldmethod=indent\<CR>")
164 " move the cursor so we can reuse the same dumps
165 call term_sendkeys(buf, "5G")
166 call term_sendkeys(buf, "\<C-E>")
167 call VerifyScreenDump(buf, 'Test_smoothscroll_1', {})
168 call term_sendkeys(buf, "\<C-E>")
169 call VerifyScreenDump(buf, 'Test_smoothscroll_2', {})
170 call term_sendkeys(buf, "7G")
171 call term_sendkeys(buf, "\<C-Y>")
172 call VerifyScreenDump(buf, 'Test_smoothscroll_7', {})
173 call term_sendkeys(buf, "\<C-Y>")
174 call VerifyScreenDump(buf, 'Test_smoothscroll_8', {})
175 endif
176
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100177 call StopVimInTerminal(buf)
178endfunc
179
Bram Moolenaar15d47472023-06-05 20:44:55 +0100180func Test_smoothscroll_multibyte()
181 CheckScreendump
182
183 let lines =<< trim END
184 set scrolloff=0 smoothscroll
185 call setline(1, [repeat('ϛ', 45), repeat('2', 36)])
186 exe "normal G35l\<C-E>k"
187 END
188 call writefile(lines, 'XSmoothMultibyte', 'D')
189 let buf = RunVimInTerminal('-S XSmoothMultibyte', #{rows: 6, cols: 40})
190 call VerifyScreenDump(buf, 'Test_smoothscroll_multi_1', {})
191
192 call StopVimInTerminal(buf)
193endfunc
194
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +0100195func Test_smoothscroll_number()
196 CheckScreendump
197
198 let lines =<< trim END
199 vim9script
200 setline(1, [
201 'one ' .. 'word '->repeat(20),
202 'two ' .. 'long word '->repeat(7),
203 'line',
204 'line',
205 'line',
206 ])
207 set smoothscroll
zeertzjq88bb3e02023-05-02 20:52:59 +0100208 set splitkeep=topline
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +0100209 set number cpo+=n
210 :3
Bram Moolenaareb4de622022-10-15 13:42:17 +0100211
212 def g:DoRel()
213 set number relativenumber scrolloff=0
214 :%del
215 setline(1, [
216 'one',
217 'very long text '->repeat(12),
218 'three',
219 ])
220 exe "normal 2Gzt\<C-E>"
221 enddef
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +0100222 END
223 call writefile(lines, 'XSmoothNumber', 'D')
224 let buf = RunVimInTerminal('-S XSmoothNumber', #{rows: 12, cols: 40})
225
226 call VerifyScreenDump(buf, 'Test_smooth_number_1', {})
227 call term_sendkeys(buf, "\<C-E>")
228 call VerifyScreenDump(buf, 'Test_smooth_number_2', {})
229 call term_sendkeys(buf, "\<C-E>")
230 call VerifyScreenDump(buf, 'Test_smooth_number_3', {})
231
232 call term_sendkeys(buf, ":set cpo-=n\<CR>")
233 call VerifyScreenDump(buf, 'Test_smooth_number_4', {})
234 call term_sendkeys(buf, "\<C-Y>")
235 call VerifyScreenDump(buf, 'Test_smooth_number_5', {})
236 call term_sendkeys(buf, "\<C-Y>")
237 call VerifyScreenDump(buf, 'Test_smooth_number_6', {})
238
zeertzjq88bb3e02023-05-02 20:52:59 +0100239 call term_sendkeys(buf, ":botright split\<CR>gg")
Bram Moolenaareb4de622022-10-15 13:42:17 +0100240 call VerifyScreenDump(buf, 'Test_smooth_number_7', {})
zeertzjq88bb3e02023-05-02 20:52:59 +0100241 call term_sendkeys(buf, "\<C-E>")
242 call VerifyScreenDump(buf, 'Test_smooth_number_8', {})
243 call term_sendkeys(buf, "\<C-E>")
244 call VerifyScreenDump(buf, 'Test_smooth_number_9', {})
245 call term_sendkeys(buf, ":close\<CR>")
246
247 call term_sendkeys(buf, ":call DoRel()\<CR>")
248 call VerifyScreenDump(buf, 'Test_smooth_number_10', {})
Bram Moolenaareb4de622022-10-15 13:42:17 +0100249
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +0100250 call StopVimInTerminal(buf)
251endfunc
252
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100253func Test_smoothscroll_list()
254 CheckScreendump
255
256 let lines =<< trim END
257 vim9script
258 set smoothscroll scrolloff=0
259 set list
260 setline(1, [
261 'one',
262 'very long text '->repeat(12),
263 'three',
264 ])
265 exe "normal 2Gzt\<C-E>"
266 END
267 call writefile(lines, 'XSmoothList', 'D')
268 let buf = RunVimInTerminal('-S XSmoothList', #{rows: 8, cols: 40})
269
270 call VerifyScreenDump(buf, 'Test_smooth_list_1', {})
271
272 call term_sendkeys(buf, ":set listchars+=precedes:#\<CR>")
273 call VerifyScreenDump(buf, 'Test_smooth_list_2', {})
274
275 call StopVimInTerminal(buf)
276endfunc
277
Bram Moolenaar1a58e1d2022-10-06 13:09:17 +0100278func Test_smoothscroll_diff_mode()
279 CheckScreendump
280
281 let lines =<< trim END
282 vim9script
283 var text = 'just some text here'
284 setline(1, text)
285 set smoothscroll
286 diffthis
287 new
288 setline(1, text)
289 set smoothscroll
290 diffthis
291 END
292 call writefile(lines, 'XSmoothDiff', 'D')
293 let buf = RunVimInTerminal('-S XSmoothDiff', #{rows: 8})
294
295 call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
296 call term_sendkeys(buf, "\<C-Y>")
297 call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
298 call term_sendkeys(buf, "\<C-E>")
299 call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
300
301 call StopVimInTerminal(buf)
302endfunc
303
zeertzjq47f85842024-10-01 19:35:47 +0200304func Test_smoothscroll_diff_change_line()
305 CheckScreendump
306
307 let lines =<< trim END
308 set diffopt+=followwrap smoothscroll
309 call setline(1, repeat(' abc', &columns))
310 call setline(2, 'bar')
311 call setline(3, repeat(' abc', &columns))
312 vnew
313 call setline(1, repeat(' abc', &columns))
314 call setline(2, 'foo')
315 call setline(3, 'bar')
316 call setline(4, repeat(' abc', &columns))
317 windo exe "normal! 2gg5\<C-E>"
318 windo diffthis
319 END
320 call writefile(lines, 'XSmoothDiffChangeLine', 'D')
321 let buf = RunVimInTerminal('-S XSmoothDiffChangeLine', #{rows: 20, columns: 55})
322
323 call VerifyScreenDump(buf, 'Test_smooth_diff_change_line_1', {})
324 call term_sendkeys(buf, "Abar")
325 call VerifyScreenDump(buf, 'Test_smooth_diff_change_line_2', {})
326 call term_sendkeys(buf, "\<Esc>")
327 call VerifyScreenDump(buf, 'Test_smooth_diff_change_line_3', {})
328 call term_sendkeys(buf, "yyp")
329 call VerifyScreenDump(buf, 'Test_smooth_diff_change_line_4', {})
330
331 call StopVimInTerminal(buf)
332endfunc
333
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100334func Test_smoothscroll_wrap_scrolloff_zero()
335 CheckScreendump
336
337 let lines =<< trim END
338 vim9script
339 setline(1, ['Line' .. (' with some text'->repeat(7))]->repeat(7))
340 set smoothscroll scrolloff=0
341 :3
342 END
343 call writefile(lines, 'XSmoothWrap', 'D')
344 let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 8, cols: 40})
345
346 call VerifyScreenDump(buf, 'Test_smooth_wrap_1', {})
347
Bram Moolenaar46b54742022-10-06 15:46:49 +0100348 " moving cursor down - whole bottom line shows
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100349 call term_sendkeys(buf, "j")
350 call VerifyScreenDump(buf, 'Test_smooth_wrap_2', {})
351
352 call term_sendkeys(buf, "\<C-E>j")
353 call VerifyScreenDump(buf, 'Test_smooth_wrap_3', {})
354
355 call term_sendkeys(buf, "G")
356 call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {})
357
Luuk van Baald49f6462023-05-19 14:04:47 +0100358 call term_sendkeys(buf, "4\<C-Y>G")
359 call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {})
360
361 " moving cursor up right after the <<< marker - no need to show whole line
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000362 call term_sendkeys(buf, "2gj3l2k")
Bram Moolenaar46b54742022-10-06 15:46:49 +0100363 call VerifyScreenDump(buf, 'Test_smooth_wrap_5', {})
364
Luuk van Baald49f6462023-05-19 14:04:47 +0100365 " moving cursor up where the <<< marker is - whole top line shows
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000366 call term_sendkeys(buf, "2j02k")
367 call VerifyScreenDump(buf, 'Test_smooth_wrap_6', {})
368
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100369 call StopVimInTerminal(buf)
370endfunc
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100371
Bram Moolenaar8cf34592022-10-08 21:13:40 +0100372func Test_smoothscroll_wrap_long_line()
373 CheckScreendump
374
375 let lines =<< trim END
376 vim9script
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000377 setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(30)) .. ' end', 'four'])
Bram Moolenaar8cf34592022-10-08 21:13:40 +0100378 set smoothscroll scrolloff=0
379 normal 3G10|zt
380 END
381 call writefile(lines, 'XSmoothWrap', 'D')
382 let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 6, cols: 40})
383 call VerifyScreenDump(buf, 'Test_smooth_long_1', {})
384
385 " scrolling up, cursor moves screen line down
386 call term_sendkeys(buf, "\<C-E>")
387 call VerifyScreenDump(buf, 'Test_smooth_long_2', {})
388 call term_sendkeys(buf, "5\<C-E>")
389 call VerifyScreenDump(buf, 'Test_smooth_long_3', {})
390
391 " scrolling down, cursor moves screen line up
392 call term_sendkeys(buf, "5\<C-Y>")
393 call VerifyScreenDump(buf, 'Test_smooth_long_4', {})
394 call term_sendkeys(buf, "\<C-Y>")
395 call VerifyScreenDump(buf, 'Test_smooth_long_5', {})
396
Bram Moolenaar118c2352022-10-09 17:19:27 +0100397 " 'scrolloff' set to 1, scrolling up, cursor moves screen line down
398 call term_sendkeys(buf, ":set scrolloff=1\<CR>")
399 call term_sendkeys(buf, "10|\<C-E>")
400 call VerifyScreenDump(buf, 'Test_smooth_long_6', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000401
Bram Moolenaar118c2352022-10-09 17:19:27 +0100402 " 'scrolloff' set to 1, scrolling down, cursor moves screen line up
403 call term_sendkeys(buf, "\<C-E>")
404 call term_sendkeys(buf, "gjgj")
405 call term_sendkeys(buf, "\<C-Y>")
406 call VerifyScreenDump(buf, 'Test_smooth_long_7', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000407
Bram Moolenaar118c2352022-10-09 17:19:27 +0100408 " 'scrolloff' set to 2, scrolling up, cursor moves screen line down
409 call term_sendkeys(buf, ":set scrolloff=2\<CR>")
410 call term_sendkeys(buf, "10|\<C-E>")
411 call VerifyScreenDump(buf, 'Test_smooth_long_8', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000412
Bram Moolenaar118c2352022-10-09 17:19:27 +0100413 " 'scrolloff' set to 2, scrolling down, cursor moves screen line up
414 call term_sendkeys(buf, "\<C-E>")
415 call term_sendkeys(buf, "gj")
416 call term_sendkeys(buf, "\<C-Y>")
417 call VerifyScreenDump(buf, 'Test_smooth_long_9', {})
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000418
419 " 'scrolloff' set to 0, move cursor down one line.
420 " Cursor should move properly, and since this is a really long line, it will
421 " be put on top of the screen.
422 call term_sendkeys(buf, ":set scrolloff=0\<CR>")
423 call term_sendkeys(buf, "0j")
424 call VerifyScreenDump(buf, 'Test_smooth_long_10', {})
425
Bram Moolenaardb4d88c2022-12-31 15:13:22 +0000426 " Test zt/zz/zb that they work properly when a long line is above it
Luuk van Baal6f37e532023-05-09 21:23:54 +0100427 call term_sendkeys(buf, "zt")
Bram Moolenaardb4d88c2022-12-31 15:13:22 +0000428 call VerifyScreenDump(buf, 'Test_smooth_long_11', {})
429 call term_sendkeys(buf, "zz")
430 call VerifyScreenDump(buf, 'Test_smooth_long_12', {})
Luuk van Baal6f37e532023-05-09 21:23:54 +0100431 call term_sendkeys(buf, "zb")
Bram Moolenaardb4d88c2022-12-31 15:13:22 +0000432 call VerifyScreenDump(buf, 'Test_smooth_long_13', {})
433
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000434 " Repeat the step and move the cursor down again.
435 " This time, use a shorter long line that is barely long enough to span more
436 " than one window. Note that the cursor is at the bottom this time because
437 " Vim prefers to do so if we are scrolling a few lines only.
438 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 +0100439 " Currently visible lines were replaced, test that the lines and cursor
440 " are correctly displayed.
441 call VerifyScreenDump(buf, 'Test_smooth_long_14', {})
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000442 call term_sendkeys(buf, "3Gzt")
443 call term_sendkeys(buf, "j")
Luuk van Baal5d01f862023-05-11 19:24:20 +0100444 call VerifyScreenDump(buf, 'Test_smooth_long_15', {})
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000445
446 " Repeat the step but this time start it when the line is smooth-scrolled by
447 " one line. This tests that the offset calculation is still correct and
448 " still end up scrolling down to the next line with cursor at bottom of
449 " screen.
450 call term_sendkeys(buf, "3Gzt")
451 call term_sendkeys(buf, "\<C-E>j")
Luuk van Baal5d01f862023-05-11 19:24:20 +0100452 call VerifyScreenDump(buf, 'Test_smooth_long_16', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000453
Bram Moolenaar8cf34592022-10-08 21:13:40 +0100454 call StopVimInTerminal(buf)
455endfunc
456
Bram Moolenaar2fbabd22022-10-12 19:53:38 +0100457func Test_smoothscroll_one_long_line()
458 CheckScreendump
459
460 let lines =<< trim END
461 vim9script
462 setline(1, 'with lots of text '->repeat(7))
463 set smoothscroll scrolloff=0
464 END
465 call writefile(lines, 'XSmoothOneLong', 'D')
466 let buf = RunVimInTerminal('-S XSmoothOneLong', #{rows: 6, cols: 40})
467 call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000468
Bram Moolenaar2fbabd22022-10-12 19:53:38 +0100469 call term_sendkeys(buf, "\<C-E>")
470 call VerifyScreenDump(buf, 'Test_smooth_one_long_2', {})
471
472 call term_sendkeys(buf, "0")
473 call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {})
474
475 call StopVimInTerminal(buf)
476endfunc
477
Bram Moolenaar75ac25b2022-11-17 19:00:14 +0000478func Test_smoothscroll_long_line_showbreak()
479 CheckScreendump
480
481 let lines =<< trim END
482 vim9script
483 # a line that spans four screen lines
484 setline(1, 'with lots of text in one line '->repeat(6))
485 set smoothscroll scrolloff=0 showbreak=+++\
486 END
487 call writefile(lines, 'XSmoothLongShowbreak', 'D')
488 let buf = RunVimInTerminal('-S XSmoothLongShowbreak', #{rows: 6, cols: 40})
489 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_1', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000490
Bram Moolenaar75ac25b2022-11-17 19:00:14 +0000491 call term_sendkeys(buf, "\<C-E>")
492 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_2', {})
493
494 call term_sendkeys(buf, "0")
495 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_1', {})
496
497 call StopVimInTerminal(buf)
498endfunc
499
zeertzjqecb87dd2023-06-03 19:45:06 +0100500" Check that 'smoothscroll' marker is drawn over double-width char correctly.
501" Run with multiple encodings.
502func Test_smoothscroll_marker_over_double_width()
503 " Run this in a separate Vim instance to avoid messing up.
504 let after =<< trim [CODE]
505 scriptencoding utf-8
506 call setline(1, 'a'->repeat(&columns) .. '口'->repeat(10))
507 setlocal smoothscroll
508 redraw
509 exe "norm \<C-E>"
510 redraw
511 " Check the chars one by one. Don't check the whole line concatenated.
512 call assert_equal('<', screenstring(1, 1))
513 call assert_equal('<', screenstring(1, 2))
514 call assert_equal('<', screenstring(1, 3))
515 call assert_equal(' ', screenstring(1, 4))
516 call assert_equal('', screenstring(1, 5))
517 call assert_equal('', screenstring(1, 7))
518 call assert_equal('', screenstring(1, 9))
519 call assert_equal('', screenstring(1, 11))
520 call assert_equal('', screenstring(1, 13))
521 call assert_equal('', screenstring(1, 15))
522 call writefile(v:errors, 'Xresult')
523 qall!
524 [CODE]
525
526 let encodings = ['utf-8', 'cp932', 'cp936', 'cp949', 'cp950']
527 if !has('win32')
528 let encodings += ['euc-jp']
529 endif
530 for enc in encodings
531 let msg = 'enc=' .. enc
532 if RunVim([], after, $'--clean --cmd "set encoding={enc}"')
533 call assert_equal([], readfile('Xresult'), msg)
534 endif
535 call delete('Xresult')
536 endfor
537endfunc
538
539" Same as the test above, but check the text actually shown on screen.
540" Only run with UTF-8 encoding.
541func Test_smoothscroll_marker_over_double_width_dump()
542 CheckScreendump
543
544 let lines =<< trim END
545 call setline(1, 'a'->repeat(&columns) .. ''->repeat(10))
546 setlocal smoothscroll
547 END
548 call writefile(lines, 'XSmoothMarkerOverDoubleWidth', 'D')
549 let buf = RunVimInTerminal('-S XSmoothMarkerOverDoubleWidth', #{rows: 6, cols: 40})
550 call VerifyScreenDump(buf, 'Test_smooth_marker_over_double_width_1', {})
551
552 call term_sendkeys(buf, "\<C-E>")
553 call VerifyScreenDump(buf, 'Test_smooth_marker_over_double_width_2', {})
554
555 call StopVimInTerminal(buf)
556endfunc
557
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000558func s:check_col_calc(win_col, win_line, buf_col)
559 call assert_equal(a:win_col, wincol())
560 call assert_equal(a:win_line, winline())
561 call assert_equal(a:buf_col, col('.'))
562endfunc
563
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000564" Test that if the current cursor is on a smooth scrolled line, we correctly
565" reposition it. Also check that we don't miscalculate the values by checking
566" the consistency between wincol() and col('.') as they are calculated
567" separately in code.
568func Test_smoothscroll_cursor_position()
569 call NewWindow(10, 20)
570 setl smoothscroll wrap
571 call setline(1, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
572
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000573 call s:check_col_calc(1, 1, 1)
574 exe "normal \<C-E>"
575
576 " Move down another line to avoid blocking the <<< display
577 call s:check_col_calc(1, 2, 41)
578 exe "normal \<C-Y>"
579 call s:check_col_calc(1, 3, 41)
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000580
Luuk van Baal8667a562023-05-12 15:47:25 +0100581 " Test "g0/g<Home>"
582 exe "normal gg\<C-E>"
583 norm $gkg0
Luuk van Baalcb204e62024-04-02 20:49:45 +0200584 call s:check_col_calc(4, 1, 24)
Luuk van Baal8667a562023-05-12 15:47:25 +0100585
586 " Test moving the cursor behind the <<< display with 'virtualedit'
587 set virtualedit=all
Luuk van Baalcb204e62024-04-02 20:49:45 +0200588 exe "normal \<C-E>gkh"
Luuk van Baal8667a562023-05-12 15:47:25 +0100589 call s:check_col_calc(3, 2, 23)
590 set virtualedit&
591
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000592 normal gg3l
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000593 exe "normal \<C-E>"
594
595 " Move down only 1 line when we are out of the range of the <<< display
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000596 call s:check_col_calc(4, 1, 24)
597 exe "normal \<C-Y>"
598 call s:check_col_calc(4, 2, 24)
599 normal ggg$
600 exe "normal \<C-E>"
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000601 call s:check_col_calc(20, 1, 40)
602 exe "normal \<C-Y>"
603 call s:check_col_calc(20, 2, 40)
604 normal gg
605
606 " Test number, where we have indented lines
607 setl number
608 call s:check_col_calc(5, 1, 1)
609 exe "normal \<C-E>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000610
611 " Move down only 1 line when the <<< display is on the number column
612 call s:check_col_calc(5, 1, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000613 exe "normal \<C-Y>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000614 call s:check_col_calc(5, 2, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000615 normal ggg$
616 exe "normal \<C-E>"
617 call s:check_col_calc(20, 1, 32)
618 exe "normal \<C-Y>"
619 call s:check_col_calc(20, 2, 32)
620 normal gg
621
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000622 setl numberwidth=1
623
624 " Move down another line when numberwidth is too short to cover the whole
625 " <<< display
626 call s:check_col_calc(3, 1, 1)
627 exe "normal \<C-E>"
628 call s:check_col_calc(3, 2, 37)
629 exe "normal \<C-Y>"
630 call s:check_col_calc(3, 3, 37)
631 normal ggl
632
633 " Only move 1 line down when we are just past the <<< display
634 call s:check_col_calc(4, 1, 2)
635 exe "normal \<C-E>"
636 call s:check_col_calc(4, 1, 20)
637 exe "normal \<C-Y>"
638 call s:check_col_calc(4, 2, 20)
639 normal gg
640 setl numberwidth&
641
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000642 " Test number + showbreak, so test that the additional indentation works
643 setl number showbreak=+++
644 call s:check_col_calc(5, 1, 1)
645 exe "normal \<C-E>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000646 call s:check_col_calc(8, 1, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000647 exe "normal \<C-Y>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000648 call s:check_col_calc(8, 2, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000649 normal gg
650
651 " Test number + cpo+=n mode, where wrapped lines aren't indented
652 setl number cpo+=n showbreak=
653 call s:check_col_calc(5, 1, 1)
654 exe "normal \<C-E>"
655 call s:check_col_calc(1, 2, 37)
656 exe "normal \<C-Y>"
657 call s:check_col_calc(1, 3, 37)
658 normal gg
659
Luuk van Baal24b62ec2023-05-13 14:12:15 +0100660 " Test list + listchars "precedes", where there is always 1 overlap
661 " regardless of number and cpo-=n.
662 setl number list listchars=precedes:< cpo-=n
663 call s:check_col_calc(5, 1, 1)
Luuk van Baal798fa762023-05-15 18:17:43 +0100664 exe "normal 3|\<C-E>h"
Luuk van Baal24b62ec2023-05-13 14:12:15 +0100665 call s:check_col_calc(6, 1, 18)
666 norm h
667 call s:check_col_calc(5, 2, 17)
668 normal gg
669
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000670 bwipe!
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000671endfunc
672
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000673func Test_smoothscroll_cursor_scrolloff()
674 call NewWindow(10, 20)
675 setl smoothscroll wrap
676 setl scrolloff=3
Bram Moolenaar94722c52023-01-28 19:19:03 +0000677
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000678 " 120 chars are 6 screen lines
679 call setline(1, "abcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRST")
680 call setline(2, "below")
681
682 call s:check_col_calc(1, 1, 1)
683
684 " CTRL-E shows "<<<DEFG...", cursor move four lines down
685 exe "normal \<C-E>"
686 call s:check_col_calc(1, 4, 81)
687
688 " cursor on start of second line, "gk" moves into first line, skipcol doesn't
689 " change
690 exe "normal G0gk"
691 call s:check_col_calc(1, 5, 101)
692
693 " move cursor left one window width worth, scrolls one screen line
694 exe "normal 20h"
695 call s:check_col_calc(1, 5, 81)
696
697 " move cursor left one window width worth, scrolls one screen line
698 exe "normal 20h"
699 call s:check_col_calc(1, 4, 61)
700
Bram Moolenaarb21b8e92022-12-03 18:35:07 +0000701 " cursor on last line, "gk" should not cause a scroll
702 set scrolloff=0
703 normal G0
704 call s:check_col_calc(1, 7, 1)
705 normal gk
706 call s:check_col_calc(1, 6, 101)
707
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000708 bwipe!
709endfunc
710
711
Yee Cheng Chine6392b12022-11-19 14:31:08 +0000712" Test that mouse picking is still accurate when we have smooth scrolled lines
713func Test_smoothscroll_mouse_pos()
714 CheckNotGui
715 CheckUnix
716
717 let save_mouse = &mouse
718 let save_term = &term
719 let save_ttymouse = &ttymouse
720 set mouse=a term=xterm ttymouse=xterm2
721
722 call NewWindow(10, 20)
723 setl smoothscroll wrap
724 " First line will wrap to 3 physical lines. 2nd/3rd lines are short lines.
725 call setline(1, ["abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", "line 2", "line 3"])
726
727 func s:check_mouse_click(row, col, buf_row, buf_col)
728 call MouseLeftClick(a:row, a:col)
729
730 call assert_equal(a:col, wincol())
731 call assert_equal(a:row, winline())
732 call assert_equal(a:buf_row, line('.'))
733 call assert_equal(a:buf_col, col('.'))
734 endfunc
735
736 " Check that clicking without scroll works first.
737 call s:check_mouse_click(3, 5, 1, 45)
738 call s:check_mouse_click(4, 1, 2, 1)
739 call s:check_mouse_click(4, 6, 2, 6)
740 call s:check_mouse_click(5, 1, 3, 1)
741 call s:check_mouse_click(5, 6, 3, 6)
742
743 " Smooth scroll, and checks that this didn't mess up mouse clicking
744 exe "normal \<C-E>"
745 call s:check_mouse_click(2, 5, 1, 45)
746 call s:check_mouse_click(3, 1, 2, 1)
747 call s:check_mouse_click(3, 6, 2, 6)
748 call s:check_mouse_click(4, 1, 3, 1)
749 call s:check_mouse_click(4, 6, 3, 6)
750
751 exe "normal \<C-E>"
752 call s:check_mouse_click(1, 5, 1, 45)
753 call s:check_mouse_click(2, 1, 2, 1)
754 call s:check_mouse_click(2, 6, 2, 6)
755 call s:check_mouse_click(3, 1, 3, 1)
756 call s:check_mouse_click(3, 6, 3, 6)
757
758 " Make a new first line 11 physical lines tall so it's taller than window
759 " height, to test overflow calculations with really long lines wrapping.
760 normal gg
761 call setline(1, "12345678901234567890"->repeat(11))
762 exe "normal 6\<C-E>"
763 call s:check_mouse_click(5, 1, 1, 201)
764 call s:check_mouse_click(6, 1, 2, 1)
765 call s:check_mouse_click(7, 1, 3, 1)
766
767 let &mouse = save_mouse
768 let &term = save_term
769 let &ttymouse = save_ttymouse
zeertzjqad493ef2024-03-29 10:23:19 +0100770 bwipe!
Yee Cheng Chine6392b12022-11-19 14:31:08 +0000771endfunc
772
Bram Moolenaar870219c2023-01-26 14:14:43 +0000773" this was dividing by zero
Luuk van Baalc8502f92023-05-06 12:40:15 +0100774func Test_smoothscroll_zero_width()
Bram Moolenaar870219c2023-01-26 14:14:43 +0000775 CheckScreendump
776
777 let lines =<< trim END
778 winsize 0 0
779 vsplit
780 vsplit
781 vsplit
782 vsplit
783 vsplit
784 sil norm H
785 set wrap
786 set smoothscroll
787 set number
788 END
789 call writefile(lines, 'XSmoothScrollZero', 'D')
790 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 +0000791 call VerifyScreenDump(buf, 'Test_smoothscroll_zero_1', {})
792
793 call term_sendkeys(buf, ":sil norm \<C-V>\<C-W>\<C-V>\<C-N>\<CR>")
794 call VerifyScreenDump(buf, 'Test_smoothscroll_zero_2', {})
795
796 call StopVimInTerminal(buf)
797endfunc
798
Luuk van Baalc8502f92023-05-06 12:40:15 +0100799" this was unnecessarily inserting lines
800func Test_smoothscroll_ins_lines()
801 CheckScreendump
802
803 let lines =<< trim END
804 set wrap
805 set smoothscroll
806 set scrolloff=0
807 set conceallevel=2
808 call setline(1, [
809 \'line one' .. 'with lots of text in one line '->repeat(2),
810 \'line two',
811 \'line three',
812 \'line four',
813 \'line five'
814 \])
815 END
816 call writefile(lines, 'XSmoothScrollInsLines', 'D')
817 let buf = RunVimInTerminal('-S XSmoothScrollInsLines', #{rows: 6, cols: 40})
818
819 call term_sendkeys(buf, "\<C-E>gjgk")
820 call VerifyScreenDump(buf, 'Test_smooth_ins_lines', {})
821
822 call StopVimInTerminal(buf)
823endfunc
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100824
Luuk van Baal3ce8c382023-05-08 15:51:14 +0100825" this placed the cursor in the command line
826func Test_smoothscroll_cursormoved_line()
827 CheckScreendump
828
829 let lines =<< trim END
830 set smoothscroll
831 call setline(1, [
832 \'',
833 \'_'->repeat(&lines * &columns),
834 \(('_')->repeat(&columns - 2) .. 'xxx')->repeat(2)
835 \])
836 autocmd CursorMoved * eval [line('w0'), line('w$')]
837 call search('xxx')
838 END
839 call writefile(lines, 'XSmoothCursorMovedLine', 'D')
840 let buf = RunVimInTerminal('-S XSmoothCursorMovedLine', #{rows: 6})
841
842 call VerifyScreenDump(buf, 'Test_smooth_cursormoved_line', {})
843
844 call StopVimInTerminal(buf)
845endfunc
846
847func Test_smoothscroll_eob()
848 CheckScreendump
849
850 let lines =<< trim END
851 set smoothscroll
852 call setline(1, ['']->repeat(100))
853 norm G
854 END
855 call writefile(lines, 'XSmoothEob', 'D')
856 let buf = RunVimInTerminal('-S XSmoothEob', #{rows: 10})
857
858 " does not scroll halfway when scrolling to end of buffer
859 call VerifyScreenDump(buf, 'Test_smooth_eob_1', {})
860
861 " cursor is not placed below window
Luuk van Baalb9f5b952024-03-26 18:46:45 +0100862 call term_sendkeys(buf, ":call setline(92, 'a'->repeat(100))\<CR>\<C-L>\<C-B>G")
Luuk van Baal3ce8c382023-05-08 15:51:14 +0100863 call VerifyScreenDump(buf, 'Test_smooth_eob_2', {})
864
865 call StopVimInTerminal(buf)
866endfunc
867
Luuk van Baald49f6462023-05-19 14:04:47 +0100868" skipcol should not reset when doing incremental search on the same word
869func Test_smoothscroll_incsearch()
870 CheckScreendump
871
872 let lines =<< trim END
873 set smoothscroll number scrolloff=0 incsearch
874 call setline(1, repeat([''], 20))
875 call setline(11, repeat('a', 100))
876 call setline(14, 'bbbb')
877 END
878 call writefile(lines, 'XSmoothIncsearch', 'D')
zeertzjq3c802272023-06-03 22:08:33 +0100879 let buf = RunVimInTerminal('-S XSmoothIncsearch', #{rows: 8, cols: 40})
Luuk van Baald49f6462023-05-19 14:04:47 +0100880
881 call term_sendkeys(buf, "/b")
882 call VerifyScreenDump(buf, 'Test_smooth_incsearch_1', {})
883 call term_sendkeys(buf, "b")
884 call VerifyScreenDump(buf, 'Test_smooth_incsearch_2', {})
885 call term_sendkeys(buf, "b")
886 call VerifyScreenDump(buf, 'Test_smooth_incsearch_3', {})
887 call term_sendkeys(buf, "b")
888 call VerifyScreenDump(buf, 'Test_smooth_incsearch_4', {})
889 call term_sendkeys(buf, "\<CR>")
890
891 call StopVimInTerminal(buf)
892endfunc
893
zeertzjq3c802272023-06-03 22:08:33 +0100894" Test scrolling multiple lines and stopping at non-zero skipcol.
895func Test_smoothscroll_multi_skipcol()
896 CheckScreendump
897
898 let lines =<< trim END
899 setlocal cursorline scrolloff=0 smoothscroll
zeertzjqd9a92dc2023-06-05 18:41:35 +0100900 call setline(1, repeat([''], 8))
zeertzjq3c802272023-06-03 22:08:33 +0100901 call setline(3, repeat('a', 50))
zeertzjqd9a92dc2023-06-05 18:41:35 +0100902 call setline(4, repeat('a', 50))
903 call setline(7, 'bbb')
904 call setline(8, 'ccc')
zeertzjq3c802272023-06-03 22:08:33 +0100905 redraw
906 END
907 call writefile(lines, 'XSmoothMultiSkipcol', 'D')
908 let buf = RunVimInTerminal('-S XSmoothMultiSkipcol', #{rows: 10, cols: 40})
909 call VerifyScreenDump(buf, 'Test_smooth_multi_skipcol_1', {})
910
911 call term_sendkeys(buf, "3\<C-E>")
912 call VerifyScreenDump(buf, 'Test_smooth_multi_skipcol_2', {})
913
zeertzjqd9a92dc2023-06-05 18:41:35 +0100914 call term_sendkeys(buf, "2\<C-E>")
915 call VerifyScreenDump(buf, 'Test_smooth_multi_skipcol_3', {})
916
zeertzjq3c802272023-06-03 22:08:33 +0100917 call StopVimInTerminal(buf)
918endfunc
919
fullwaywang8154e642023-06-24 21:58:09 +0100920" this was dividing by zero bug in scroll_cursor_bot
921func Test_smoothscroll_zero_width_scroll_cursor_bot()
922 CheckScreendump
923
924 let lines =<< trim END
925 silent normal yy
926 silent normal 19p
zeertzjqe4298932023-06-26 19:02:43 +0100927 set cpoptions+=n
fullwaywang8154e642023-06-24 21:58:09 +0100928 vsplit
929 vertical resize 0
930 set foldcolumn=1
931 set number
932 set smoothscroll
933 silent normal 20G
934 END
935 call writefile(lines, 'XSmoothScrollZeroBot', 'D')
zeertzjqe4298932023-06-26 19:02:43 +0100936 let buf = RunVimInTerminal('-u NONE -S XSmoothScrollZeroBot', #{rows: 19})
fullwaywang8154e642023-06-24 21:58:09 +0100937 call VerifyScreenDump(buf, 'Test_smoothscroll_zero_bot', {})
938
939 call StopVimInTerminal(buf)
940endfunc
941
Luuk van Baalbb800a72023-11-14 17:05:18 +0100942" scroll_cursor_top() should reset skipcol when it changes topline
943func Test_smoothscroll_cursor_top()
944 CheckScreendump
945
946 let lines =<< trim END
947 set smoothscroll scrolloff=2
948 new | 11resize | wincmd j
949 call setline(1, ['line1', 'line2', 'line3'->repeat(20), 'line4'])
950 exe "norm G3\<C-E>k"
951 END
952 call writefile(lines, 'XSmoothScrollCursorTop', 'D')
zeertzjq5b4d1fc2023-12-03 17:54:10 +0100953 let buf = RunVimInTerminal('-u NONE -S XSmoothScrollCursorTop', #{rows: 12, cols: 40})
Luuk van Baalbb800a72023-11-14 17:05:18 +0100954 call VerifyScreenDump(buf, 'Test_smoothscroll_cursor_top', {})
955
956 call StopVimInTerminal(buf)
957endfunc
958
Christian Brabandtcb0b99f2023-11-14 20:05:59 +0100959" Division by zero, shouldn't crash
960func Test_smoothscroll_crash()
961 CheckScreendump
962
963 let lines =<< trim END
964 20 new
965 vsp
966 put =repeat('aaaa', 20)
967 set nu fdc=1 smoothscroll cpo+=n
968 vert resize 0
969 exe "norm! 0\<c-e>"
970 END
971 call writefile(lines, 'XSmoothScrollCrash', 'D')
zeertzjq5b4d1fc2023-12-03 17:54:10 +0100972 let buf = RunVimInTerminal('-u NONE -S XSmoothScrollCrash', #{rows: 12, cols: 40})
Christian Brabandtcb0b99f2023-11-14 20:05:59 +0100973 call term_sendkeys(buf, "2\<C-E>\<C-L>")
974
975 call StopVimInTerminal(buf)
976endfunc
977
zeertzjq5b4d1fc2023-12-03 17:54:10 +0100978func Test_smoothscroll_insert_bottom()
979 CheckScreendump
980
981 let lines =<< trim END
982 call setline(1, repeat([repeat('A very long line ...', 10)], 5))
983 set wrap smoothscroll scrolloff=0
984 END
985 call writefile(lines, 'XSmoothScrollInsertBottom', 'D')
986 let buf = RunVimInTerminal('-u NONE -S XSmoothScrollInsertBottom', #{rows: 9, cols: 40})
987 call term_sendkeys(buf, "Go123456789\<CR>")
988 call VerifyScreenDump(buf, 'Test_smoothscroll_insert_bottom', {})
989
990 call StopVimInTerminal(buf)
991endfunc
992
zeertzjqc7a8eb52024-05-08 20:22:40 +0200993func Test_smoothscroll_in_qf_window()
994 CheckFeature quickfix
995 CheckScreendump
996
997 let lines =<< trim END
998 set nocompatible display=lastline
999 copen 5
1000 setlocal number smoothscroll
1001 let g:l = [{'text': 'foo'}] + repeat([{'text': join(range(30))}], 10)
1002 call setqflist(g:l, 'r')
1003 normal! G
1004 wincmd t
1005 let g:l1 = [{'text': join(range(1000))}]
1006 END
1007 call writefile(lines, 'XSmoothScrollInQfWindow', 'D')
1008 let buf = RunVimInTerminal('-u NONE -S XSmoothScrollInQfWindow', #{rows: 20, cols: 60})
1009 call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_1', {})
1010
1011 call term_sendkeys(buf, ":call setqflist([], 'r')\<CR>")
1012 call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_2', {})
1013
1014 call term_sendkeys(buf, ":call setqflist(g:l, 'r')\<CR>")
1015 call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_3', {})
1016
1017 call term_sendkeys(buf, ":call setqflist(g:l1, 'r')\<CR>")
1018 call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_4', {})
1019
1020 call term_sendkeys(buf, "\<C-W>b$\<C-W>t")
1021 call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_5', {})
1022
1023 call term_sendkeys(buf, ":call setqflist([], 'r')\<CR>")
1024 call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_2', {})
1025
1026 call term_sendkeys(buf, ":call setqflist(g:l1, 'r')\<CR>")
1027 call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_4', {})
1028
1029 call term_sendkeys(buf, "\<C-W>b$\<C-W>t")
1030 call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_5', {})
1031
1032 call term_sendkeys(buf, ":call setqflist(g:l, 'r')\<CR>")
1033 call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_3', {})
1034
1035 call StopVimInTerminal(buf)
1036endfunc
1037
Sean Dewar02fcae02024-02-21 19:40:44 +01001038func Test_smoothscroll_in_zero_width_window()
1039 set cpo+=n number smoothscroll
1040 set winwidth=99999 winminwidth=0
1041
1042 vsplit
1043 call assert_equal(0, winwidth(winnr('#')))
1044 call win_execute(win_getid(winnr('#')), "norm! \<C-Y>")
1045
1046 only!
1047 set winwidth& winminwidth&
1048 set cpo-=n nonumber nosmoothscroll
1049endfunc
1050
1051func Test_smoothscroll_textoff_small_winwidth()
1052 set smoothscroll number
1053 call setline(1, 'llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch')
1054 vsplit
1055
1056 let textoff = getwininfo(win_getid())[0].textoff
1057 execute 'vertical resize' textoff + 1
1058 redraw
1059 call assert_equal(0, winsaveview().skipcol)
1060 execute "normal! 0\<C-E>"
1061 redraw
1062 call assert_equal(1, winsaveview().skipcol)
1063 execute 'vertical resize' textoff - 1
1064 " This caused a signed integer overflow.
1065 redraw
1066 call assert_equal(1, winsaveview().skipcol)
1067 execute 'vertical resize' textoff
1068 " This caused an infinite loop.
1069 redraw
1070 call assert_equal(1, winsaveview().skipcol)
1071
1072 %bw!
1073 set smoothscroll& number&
1074endfunc
1075
Luuk van Baalb9f5b952024-03-26 18:46:45 +01001076func Test_smoothscroll_page()
zeertzjqad493ef2024-03-29 10:23:19 +01001077 call NewWindow(10, 40)
1078 setlocal smoothscroll
Luuk van Baalb9f5b952024-03-26 18:46:45 +01001079 call setline(1, 'abcde '->repeat(150))
1080
1081 exe "norm! \<C-F>"
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001082 call assert_equal(400, winsaveview().skipcol)
Luuk van Baalb9f5b952024-03-26 18:46:45 +01001083 exe "norm! \<C-F>"
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001084 call assert_equal(800, winsaveview().skipcol)
Luuk van Baalb9f5b952024-03-26 18:46:45 +01001085 exe "norm! \<C-F>"
1086 call assert_equal(880, winsaveview().skipcol)
1087 exe "norm! \<C-B>"
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001088 call assert_equal(480, winsaveview().skipcol)
Luuk van Baalb9f5b952024-03-26 18:46:45 +01001089 exe "norm! \<C-B>"
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001090 call assert_equal(80, winsaveview().skipcol)
Luuk van Baalb9f5b952024-03-26 18:46:45 +01001091 exe "norm! \<C-B>"
1092 call assert_equal(0, winsaveview().skipcol)
1093
Luuk van Baalcb204e62024-04-02 20:49:45 +02001094 " Half-page scrolling does not go beyond end of buffer and moves the cursor.
Luuk van Baalbd28cae2024-04-03 22:50:40 +02001095 " Even with 'nostartofline', the correct amount of lines is scrolled.
1096 setl nostartofline
Luuk van Baal9148ba82024-04-08 22:27:41 +02001097 exe "norm! 15|\<C-D>"
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001098 call assert_equal(200, winsaveview().skipcol)
Luuk van Baal9148ba82024-04-08 22:27:41 +02001099 call assert_equal(215, col('.'))
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001100 exe "norm! \<C-D>"
1101 call assert_equal(400, winsaveview().skipcol)
Luuk van Baal9148ba82024-04-08 22:27:41 +02001102 call assert_equal(415, col('.'))
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001103 exe "norm! \<C-D>"
Luuk van Baalcb204e62024-04-02 20:49:45 +02001104 call assert_equal(520, winsaveview().skipcol)
Luuk van Baal78c51502024-04-09 21:30:19 +02001105 call assert_equal(615, col('.'))
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001106 exe "norm! \<C-D>"
Luuk van Baalcb204e62024-04-02 20:49:45 +02001107 call assert_equal(520, winsaveview().skipcol)
Luuk van Baal78c51502024-04-09 21:30:19 +02001108 call assert_equal(815, col('.'))
Luuk van Baal9148ba82024-04-08 22:27:41 +02001109 exe "norm! \<C-D>"
Luuk van Baalcb204e62024-04-02 20:49:45 +02001110 call assert_equal(520, winsaveview().skipcol)
Luuk van Baal9148ba82024-04-08 22:27:41 +02001111 call assert_equal(895, col('.'))
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001112 exe "norm! \<C-U>"
Luuk van Baal9148ba82024-04-08 22:27:41 +02001113 call assert_equal(320, winsaveview().skipcol)
1114 call assert_equal(695, col('.'))
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001115 exe "norm! \<C-U>"
Luuk van Baal9148ba82024-04-08 22:27:41 +02001116 call assert_equal(120, winsaveview().skipcol)
1117 call assert_equal(495, col('.'))
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001118 exe "norm! \<C-U>"
1119 call assert_equal(0, winsaveview().skipcol)
Luuk van Baal78c51502024-04-09 21:30:19 +02001120 call assert_equal(295, col('.'))
Luuk van Baal9148ba82024-04-08 22:27:41 +02001121 exe "norm! \<C-U>"
1122 call assert_equal(0, winsaveview().skipcol)
Luuk van Baal78c51502024-04-09 21:30:19 +02001123 call assert_equal(95, col('.'))
Luuk van Baal9148ba82024-04-08 22:27:41 +02001124 exe "norm! \<C-U>"
1125 call assert_equal(0, winsaveview().skipcol)
1126 call assert_equal(15, col('.'))
Luuk van Baalcb204e62024-04-02 20:49:45 +02001127
1128 bwipe!
1129endfunc
1130
1131func Test_smoothscroll_next_topline()
1132 call NewWindow(10, 40)
1133 setlocal smoothscroll
1134 call setline(1, ['abcde '->repeat(150)]->repeat(2))
1135
1136 " Scrolling a screenline that causes the cursor to move to the next buffer
1137 " line should not skip part of that line to bring the cursor into view.
1138 exe "norm! 22\<C-E>"
1139 call assert_equal(880, winsaveview().skipcol)
1140 exe "norm! \<C-E>"
1141 redraw
1142 call assert_equal(0, winsaveview().skipcol)
1143
Luuk van Baalbd28cae2024-04-03 22:50:40 +02001144 " Also when scrolling back.
1145 exe "norm! G\<C-Y>"
1146 redraw
1147 call assert_equal(880, winsaveview().skipcol)
1148
Luuk van Baalcb204e62024-04-02 20:49:45 +02001149 " Cursor in correct place when not in the first screenline of a buffer line.
1150 exe "norm! gg4gj20\<C-D>\<C-D>"
1151 redraw
1152 call assert_equal(2, line('w0'))
1153
Luuk van Baal9148ba82024-04-08 22:27:41 +02001154 " Cursor does not end up above topline, adjusting topline later.
1155 setlocal nu cpo+=n
1156 exe "norm! G$g013\<C-Y>"
1157 redraw
1158 call assert_equal(2, line('.'))
1159 call assert_equal(0, winsaveview().skipcol)
1160
1161 set cpo-=n
Luuk van Baalcb204e62024-04-02 20:49:45 +02001162 bwipe!
1163endfunc
1164
1165func Test_smoothscroll_long_line_zb()
1166 call NewWindow(10, 40)
1167 call setline(1, 'abcde '->repeat(150))
1168
1169 " Also works without 'smoothscroll' when last line of buffer doesn't fit.
1170 " Used to set topline to buffer line count plus one, causing an empty screen.
1171 norm zb
1172 redraw
1173 call assert_equal(1, winsaveview().topline)
1174
1175 " Moving cursor to bottom works on line that doesn't fit with 'smoothscroll'.
1176 " Skipcol was adjusted later for cursor being on not visible part of line.
1177 setlocal smoothscroll
1178 norm zb
1179 redraw
1180 call assert_equal(520, winsaveview().skipcol)
Luuk van Baal5a2e3ec2024-03-28 10:07:29 +01001181
zeertzjqad493ef2024-03-29 10:23:19 +01001182 bwipe!
Luuk van Baalb9f5b952024-03-26 18:46:45 +01001183endfunc
1184
Luuk van Baalb32055e2024-05-16 20:44:09 +02001185func Test_smooth_long_scrolloff()
1186 CheckScreendump
1187
1188 let lines =<< trim END
1189 set smoothscroll scrolloff=3
Luuk van Baal2e642732024-05-17 18:25:13 +02001190 call setline(1, ['one', 'two long '->repeat(100), 'three', 'four', 'five', 'six'])
Luuk van Baalb32055e2024-05-16 20:44:09 +02001191 END
1192 call writefile(lines, 'XSmoothLongScrolloff', 'D')
1193 let buf = RunVimInTerminal('-u NONE -S XSmoothLongScrolloff', #{rows: 8, cols: 40})
Luuk van Baal2e642732024-05-17 18:25:13 +02001194 call term_sendkeys(buf, ":norm j721|\<CR>")
Luuk van Baalb32055e2024-05-16 20:44:09 +02001195 call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_1', {})
1196
1197 call term_sendkeys(buf, "gj")
1198 call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_2', {})
1199
1200 call term_sendkeys(buf, "gj")
1201 call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_3', {})
1202
1203 call term_sendkeys(buf, "gj")
1204 call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_4', {})
1205
1206 call term_sendkeys(buf, "gj")
1207 call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_5', {})
1208
1209 call term_sendkeys(buf, "gj")
1210 call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_6', {})
1211
1212 call term_sendkeys(buf, "gk")
Luuk van Baalb32055e2024-05-16 20:44:09 +02001213 call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_7', {})
1214
1215 call StopVimInTerminal(buf)
1216endfunc
1217
zeertzjq2c47ab82025-02-13 20:34:34 +01001218func Test_smoothscroll_listchars_eol()
1219 call NewWindow(10, 40)
1220 setlocal list listchars=eol:$ scrolloff=0 smoothscroll
1221 call setline(1, repeat('-', 40))
1222 call append(1, repeat(['foobar'], 10))
1223
1224 normal! G
1225 call assert_equal(2, line('w0'))
1226 call assert_equal(0, winsaveview().skipcol)
1227
1228 exe "normal! \<C-Y>"
1229 call assert_equal(1, line('w0'))
1230 call assert_equal(40, winsaveview().skipcol)
1231
1232 exe "normal! \<C-Y>"
1233 call assert_equal(1, line('w0'))
1234 call assert_equal(0, winsaveview().skipcol)
1235
1236 exe "normal! \<C-Y>"
1237 call assert_equal(1, line('w0'))
1238 call assert_equal(0, winsaveview().skipcol)
1239
1240 exe "normal! \<C-E>"
1241 call assert_equal(1, line('w0'))
1242 call assert_equal(40, winsaveview().skipcol)
1243
1244 exe "normal! \<C-E>"
1245 call assert_equal(2, line('w0'))
1246 call assert_equal(0, winsaveview().skipcol)
1247
1248 for ve in ['', 'all', 'onemore']
1249 let &virtualedit = ve
1250 normal! gg
1251 call assert_equal(1, line('w0'))
1252 call assert_equal(0, winsaveview().skipcol)
1253
1254 exe "normal! \<C-E>"
1255 redraw " redrawing should not cause another scroll
1256 call assert_equal(1, line('w0'))
1257 call assert_equal(40, winsaveview().skipcol)
1258
1259 exe "normal! \<C-E>"
1260 redraw
1261 call assert_equal(2, line('w0'))
1262 call assert_equal(0, winsaveview().skipcol)
1263
1264 if ve != 'all'
1265 call assert_equal([0, 2, 1, 0], getpos('.'))
1266 endif
1267 endfor
1268
1269 set virtualedit&
1270 bwipe!
1271endfunc
1272
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001273" vim: shiftwidth=2 sts=2 expandtab