blob: 01b1dafe36419016e80ee69d3d840e838fd88ea3 [file] [log] [blame]
Bram Moolenaarf6196f42022-10-02 21:29:55 +01001" Test for reset 'scroll' and 'smoothscroll'
2
3source check.vim
4source screendump.vim
Yee Cheng Chine6392b12022-11-19 14:31:08 +00005source mouse.vim
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01006
7func Test_reset_scroll()
8 let scr = &l:scroll
9
10 setlocal scroll=1
11 setlocal scroll&
12 call assert_equal(scr, &l:scroll)
13
14 setlocal scroll=1
15 setlocal scroll=0
16 call assert_equal(scr, &l:scroll)
17
18 try
19 execute 'setlocal scroll=' . (winheight(0) + 1)
20 " not reached
21 call assert_false(1)
22 catch
23 call assert_exception('E49:')
24 endtry
25
26 split
27
28 let scr = &l:scroll
29
30 setlocal scroll=1
31 setlocal scroll&
32 call assert_equal(scr, &l:scroll)
33
34 setlocal scroll=1
35 setlocal scroll=0
36 call assert_equal(scr, &l:scroll)
37
38 quit!
39endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020040
Bram Moolenaar1d6539c2023-02-14 17:41:20 +000041func Test_scolloff_even_line_count()
42 new
43 resize 6
44 setlocal scrolloff=3
45 call setline(1, range(20))
46 normal 2j
47 call assert_equal(1, getwininfo(win_getid())[0].topline)
48 normal j
49 call assert_equal(1, getwininfo(win_getid())[0].topline)
50 normal j
51 call assert_equal(2, getwininfo(win_getid())[0].topline)
52 normal j
53 call assert_equal(3, getwininfo(win_getid())[0].topline)
54
55 bwipe!
56endfunc
57
Bram Moolenaar8df97482022-10-03 12:11:13 +010058func Test_CtrlE_CtrlY_stop_at_end()
59 enew
60 call setline(1, ['one', 'two'])
61 set number
62 exe "normal \<C-Y>"
63 call assert_equal([" 1 one "], ScreenLines(1, 10))
64 exe "normal \<C-E>\<C-E>\<C-E>"
65 call assert_equal([" 2 two "], ScreenLines(1, 10))
66
67 bwipe!
68 set nonumber
69endfunc
70
Bram Moolenaarf6196f42022-10-02 21:29:55 +010071func Test_smoothscroll_CtrlE_CtrlY()
72 CheckScreendump
73
74 let lines =<< trim END
75 vim9script
76 setline(1, [
77 'line one',
78 'word '->repeat(20),
79 'line three',
80 'long word '->repeat(7),
81 'line',
82 'line',
83 'line',
84 ])
85 set smoothscroll
86 :5
87 END
88 call writefile(lines, 'XSmoothScroll', 'D')
89 let buf = RunVimInTerminal('-S XSmoothScroll', #{rows: 12, cols: 40})
90
91 call term_sendkeys(buf, "\<C-E>")
92 call VerifyScreenDump(buf, 'Test_smoothscroll_1', {})
93 call term_sendkeys(buf, "\<C-E>")
94 call VerifyScreenDump(buf, 'Test_smoothscroll_2', {})
95 call term_sendkeys(buf, "\<C-E>")
96 call VerifyScreenDump(buf, 'Test_smoothscroll_3', {})
97 call term_sendkeys(buf, "\<C-E>")
98 call VerifyScreenDump(buf, 'Test_smoothscroll_4', {})
99
100 call term_sendkeys(buf, "\<C-Y>")
101 call VerifyScreenDump(buf, 'Test_smoothscroll_5', {})
102 call term_sendkeys(buf, "\<C-Y>")
103 call VerifyScreenDump(buf, 'Test_smoothscroll_6', {})
104 call term_sendkeys(buf, "\<C-Y>")
105 call VerifyScreenDump(buf, 'Test_smoothscroll_7', {})
106 call term_sendkeys(buf, "\<C-Y>")
107 call VerifyScreenDump(buf, 'Test_smoothscroll_8', {})
108
Bram Moolenaar6b2d4ff2022-10-03 14:06:02 +0100109 if has('folding')
110 call term_sendkeys(buf, ":set foldmethod=indent\<CR>")
111 " move the cursor so we can reuse the same dumps
112 call term_sendkeys(buf, "5G")
113 call term_sendkeys(buf, "\<C-E>")
114 call VerifyScreenDump(buf, 'Test_smoothscroll_1', {})
115 call term_sendkeys(buf, "\<C-E>")
116 call VerifyScreenDump(buf, 'Test_smoothscroll_2', {})
117 call term_sendkeys(buf, "7G")
118 call term_sendkeys(buf, "\<C-Y>")
119 call VerifyScreenDump(buf, 'Test_smoothscroll_7', {})
120 call term_sendkeys(buf, "\<C-Y>")
121 call VerifyScreenDump(buf, 'Test_smoothscroll_8', {})
122 endif
123
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100124 call StopVimInTerminal(buf)
125endfunc
126
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +0100127func Test_smoothscroll_number()
128 CheckScreendump
129
130 let lines =<< trim END
131 vim9script
132 setline(1, [
133 'one ' .. 'word '->repeat(20),
134 'two ' .. 'long word '->repeat(7),
135 'line',
136 'line',
137 'line',
138 ])
139 set smoothscroll
140 set number cpo+=n
141 :3
Bram Moolenaareb4de622022-10-15 13:42:17 +0100142
143 def g:DoRel()
144 set number relativenumber scrolloff=0
145 :%del
146 setline(1, [
147 'one',
148 'very long text '->repeat(12),
149 'three',
150 ])
151 exe "normal 2Gzt\<C-E>"
152 enddef
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +0100153 END
154 call writefile(lines, 'XSmoothNumber', 'D')
155 let buf = RunVimInTerminal('-S XSmoothNumber', #{rows: 12, cols: 40})
156
157 call VerifyScreenDump(buf, 'Test_smooth_number_1', {})
158 call term_sendkeys(buf, "\<C-E>")
159 call VerifyScreenDump(buf, 'Test_smooth_number_2', {})
160 call term_sendkeys(buf, "\<C-E>")
161 call VerifyScreenDump(buf, 'Test_smooth_number_3', {})
162
163 call term_sendkeys(buf, ":set cpo-=n\<CR>")
164 call VerifyScreenDump(buf, 'Test_smooth_number_4', {})
165 call term_sendkeys(buf, "\<C-Y>")
166 call VerifyScreenDump(buf, 'Test_smooth_number_5', {})
167 call term_sendkeys(buf, "\<C-Y>")
168 call VerifyScreenDump(buf, 'Test_smooth_number_6', {})
169
Bram Moolenaareb4de622022-10-15 13:42:17 +0100170 call term_sendkeys(buf, ":call DoRel()\<CR>")
171 call VerifyScreenDump(buf, 'Test_smooth_number_7', {})
172
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +0100173 call StopVimInTerminal(buf)
174endfunc
175
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100176func Test_smoothscroll_list()
177 CheckScreendump
178
179 let lines =<< trim END
180 vim9script
181 set smoothscroll scrolloff=0
182 set list
183 setline(1, [
184 'one',
185 'very long text '->repeat(12),
186 'three',
187 ])
188 exe "normal 2Gzt\<C-E>"
189 END
190 call writefile(lines, 'XSmoothList', 'D')
191 let buf = RunVimInTerminal('-S XSmoothList', #{rows: 8, cols: 40})
192
193 call VerifyScreenDump(buf, 'Test_smooth_list_1', {})
194
195 call term_sendkeys(buf, ":set listchars+=precedes:#\<CR>")
196 call VerifyScreenDump(buf, 'Test_smooth_list_2', {})
197
198 call StopVimInTerminal(buf)
199endfunc
200
Bram Moolenaar1a58e1d2022-10-06 13:09:17 +0100201func Test_smoothscroll_diff_mode()
202 CheckScreendump
203
204 let lines =<< trim END
205 vim9script
206 var text = 'just some text here'
207 setline(1, text)
208 set smoothscroll
209 diffthis
210 new
211 setline(1, text)
212 set smoothscroll
213 diffthis
214 END
215 call writefile(lines, 'XSmoothDiff', 'D')
216 let buf = RunVimInTerminal('-S XSmoothDiff', #{rows: 8})
217
218 call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
219 call term_sendkeys(buf, "\<C-Y>")
220 call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
221 call term_sendkeys(buf, "\<C-E>")
222 call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
223
224 call StopVimInTerminal(buf)
225endfunc
226
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100227func Test_smoothscroll_wrap_scrolloff_zero()
228 CheckScreendump
229
230 let lines =<< trim END
231 vim9script
232 setline(1, ['Line' .. (' with some text'->repeat(7))]->repeat(7))
233 set smoothscroll scrolloff=0
234 :3
235 END
236 call writefile(lines, 'XSmoothWrap', 'D')
237 let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 8, cols: 40})
238
239 call VerifyScreenDump(buf, 'Test_smooth_wrap_1', {})
240
Bram Moolenaar46b54742022-10-06 15:46:49 +0100241 " moving cursor down - whole bottom line shows
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100242 call term_sendkeys(buf, "j")
243 call VerifyScreenDump(buf, 'Test_smooth_wrap_2', {})
244
245 call term_sendkeys(buf, "\<C-E>j")
246 call VerifyScreenDump(buf, 'Test_smooth_wrap_3', {})
247
248 call term_sendkeys(buf, "G")
249 call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {})
250
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000251 " moving cursor up right after the >>> marker - no need to show whole line
252 call term_sendkeys(buf, "2gj3l2k")
Bram Moolenaar46b54742022-10-06 15:46:49 +0100253 call VerifyScreenDump(buf, 'Test_smooth_wrap_5', {})
254
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000255 " moving cursor up where the >>> marker is - whole top line shows
256 call term_sendkeys(buf, "2j02k")
257 call VerifyScreenDump(buf, 'Test_smooth_wrap_6', {})
258
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100259 call StopVimInTerminal(buf)
260endfunc
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100261
Bram Moolenaar8cf34592022-10-08 21:13:40 +0100262func Test_smoothscroll_wrap_long_line()
263 CheckScreendump
264
265 let lines =<< trim END
266 vim9script
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000267 setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(30)) .. ' end', 'four'])
Bram Moolenaar8cf34592022-10-08 21:13:40 +0100268 set smoothscroll scrolloff=0
269 normal 3G10|zt
270 END
271 call writefile(lines, 'XSmoothWrap', 'D')
272 let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 6, cols: 40})
273 call VerifyScreenDump(buf, 'Test_smooth_long_1', {})
274
275 " scrolling up, cursor moves screen line down
276 call term_sendkeys(buf, "\<C-E>")
277 call VerifyScreenDump(buf, 'Test_smooth_long_2', {})
278 call term_sendkeys(buf, "5\<C-E>")
279 call VerifyScreenDump(buf, 'Test_smooth_long_3', {})
280
281 " scrolling down, cursor moves screen line up
282 call term_sendkeys(buf, "5\<C-Y>")
283 call VerifyScreenDump(buf, 'Test_smooth_long_4', {})
284 call term_sendkeys(buf, "\<C-Y>")
285 call VerifyScreenDump(buf, 'Test_smooth_long_5', {})
286
Bram Moolenaar118c2352022-10-09 17:19:27 +0100287 " 'scrolloff' set to 1, scrolling up, cursor moves screen line down
288 call term_sendkeys(buf, ":set scrolloff=1\<CR>")
289 call term_sendkeys(buf, "10|\<C-E>")
290 call VerifyScreenDump(buf, 'Test_smooth_long_6', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000291
Bram Moolenaar118c2352022-10-09 17:19:27 +0100292 " 'scrolloff' set to 1, scrolling down, cursor moves screen line up
293 call term_sendkeys(buf, "\<C-E>")
294 call term_sendkeys(buf, "gjgj")
295 call term_sendkeys(buf, "\<C-Y>")
296 call VerifyScreenDump(buf, 'Test_smooth_long_7', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000297
Bram Moolenaar118c2352022-10-09 17:19:27 +0100298 " 'scrolloff' set to 2, scrolling up, cursor moves screen line down
299 call term_sendkeys(buf, ":set scrolloff=2\<CR>")
300 call term_sendkeys(buf, "10|\<C-E>")
301 call VerifyScreenDump(buf, 'Test_smooth_long_8', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000302
Bram Moolenaar118c2352022-10-09 17:19:27 +0100303 " 'scrolloff' set to 2, scrolling down, cursor moves screen line up
304 call term_sendkeys(buf, "\<C-E>")
305 call term_sendkeys(buf, "gj")
306 call term_sendkeys(buf, "\<C-Y>")
307 call VerifyScreenDump(buf, 'Test_smooth_long_9', {})
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000308
309 " 'scrolloff' set to 0, move cursor down one line.
310 " Cursor should move properly, and since this is a really long line, it will
311 " be put on top of the screen.
312 call term_sendkeys(buf, ":set scrolloff=0\<CR>")
313 call term_sendkeys(buf, "0j")
314 call VerifyScreenDump(buf, 'Test_smooth_long_10', {})
315
Bram Moolenaardb4d88c2022-12-31 15:13:22 +0000316 " Test zt/zz/zb that they work properly when a long line is above it
317 call term_sendkeys(buf, "zb")
318 call VerifyScreenDump(buf, 'Test_smooth_long_11', {})
319 call term_sendkeys(buf, "zz")
320 call VerifyScreenDump(buf, 'Test_smooth_long_12', {})
321 call term_sendkeys(buf, "zt")
322 call VerifyScreenDump(buf, 'Test_smooth_long_13', {})
323
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000324 " Repeat the step and move the cursor down again.
325 " This time, use a shorter long line that is barely long enough to span more
326 " than one window. Note that the cursor is at the bottom this time because
327 " Vim prefers to do so if we are scrolling a few lines only.
328 call term_sendkeys(buf, ":call setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(10)) .. ' end', 'four'])\<CR>")
329 call term_sendkeys(buf, "3Gzt")
330 call term_sendkeys(buf, "j")
Bram Moolenaardb4d88c2022-12-31 15:13:22 +0000331 call VerifyScreenDump(buf, 'Test_smooth_long_14', {})
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000332
333 " Repeat the step but this time start it when the line is smooth-scrolled by
334 " one line. This tests that the offset calculation is still correct and
335 " still end up scrolling down to the next line with cursor at bottom of
336 " screen.
337 call term_sendkeys(buf, "3Gzt")
338 call term_sendkeys(buf, "\<C-E>j")
Bram Moolenaardb4d88c2022-12-31 15:13:22 +0000339 call VerifyScreenDump(buf, 'Test_smooth_long_15', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000340
Bram Moolenaar8cf34592022-10-08 21:13:40 +0100341 call StopVimInTerminal(buf)
342endfunc
343
Bram Moolenaar2fbabd22022-10-12 19:53:38 +0100344func Test_smoothscroll_one_long_line()
345 CheckScreendump
346
347 let lines =<< trim END
348 vim9script
349 setline(1, 'with lots of text '->repeat(7))
350 set smoothscroll scrolloff=0
351 END
352 call writefile(lines, 'XSmoothOneLong', 'D')
353 let buf = RunVimInTerminal('-S XSmoothOneLong', #{rows: 6, cols: 40})
354 call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000355
Bram Moolenaar2fbabd22022-10-12 19:53:38 +0100356 call term_sendkeys(buf, "\<C-E>")
357 call VerifyScreenDump(buf, 'Test_smooth_one_long_2', {})
358
359 call term_sendkeys(buf, "0")
360 call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {})
361
362 call StopVimInTerminal(buf)
363endfunc
364
Bram Moolenaar75ac25b2022-11-17 19:00:14 +0000365func Test_smoothscroll_long_line_showbreak()
366 CheckScreendump
367
368 let lines =<< trim END
369 vim9script
370 # a line that spans four screen lines
371 setline(1, 'with lots of text in one line '->repeat(6))
372 set smoothscroll scrolloff=0 showbreak=+++\
373 END
374 call writefile(lines, 'XSmoothLongShowbreak', 'D')
375 let buf = RunVimInTerminal('-S XSmoothLongShowbreak', #{rows: 6, cols: 40})
376 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_1', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000377
Bram Moolenaar75ac25b2022-11-17 19:00:14 +0000378 call term_sendkeys(buf, "\<C-E>")
379 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_2', {})
380
381 call term_sendkeys(buf, "0")
382 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_1', {})
383
384 call StopVimInTerminal(buf)
385endfunc
386
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000387func s:check_col_calc(win_col, win_line, buf_col)
388 call assert_equal(a:win_col, wincol())
389 call assert_equal(a:win_line, winline())
390 call assert_equal(a:buf_col, col('.'))
391endfunc
392
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000393" Test that if the current cursor is on a smooth scrolled line, we correctly
394" reposition it. Also check that we don't miscalculate the values by checking
395" the consistency between wincol() and col('.') as they are calculated
396" separately in code.
397func Test_smoothscroll_cursor_position()
398 call NewWindow(10, 20)
399 setl smoothscroll wrap
400 call setline(1, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
401
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000402 call s:check_col_calc(1, 1, 1)
403 exe "normal \<C-E>"
404
405 " Move down another line to avoid blocking the <<< display
406 call s:check_col_calc(1, 2, 41)
407 exe "normal \<C-Y>"
408 call s:check_col_calc(1, 3, 41)
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000409
410 normal gg3l
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000411 exe "normal \<C-E>"
412
413 " Move down only 1 line when we are out of the range of the <<< display
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000414 call s:check_col_calc(4, 1, 24)
415 exe "normal \<C-Y>"
416 call s:check_col_calc(4, 2, 24)
417 normal ggg$
418 exe "normal \<C-E>"
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000419 call s:check_col_calc(20, 1, 40)
420 exe "normal \<C-Y>"
421 call s:check_col_calc(20, 2, 40)
422 normal gg
423
424 " Test number, where we have indented lines
425 setl number
426 call s:check_col_calc(5, 1, 1)
427 exe "normal \<C-E>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000428
429 " Move down only 1 line when the <<< display is on the number column
430 call s:check_col_calc(5, 1, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000431 exe "normal \<C-Y>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000432 call s:check_col_calc(5, 2, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000433 normal ggg$
434 exe "normal \<C-E>"
435 call s:check_col_calc(20, 1, 32)
436 exe "normal \<C-Y>"
437 call s:check_col_calc(20, 2, 32)
438 normal gg
439
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000440 setl numberwidth=1
441
442 " Move down another line when numberwidth is too short to cover the whole
443 " <<< display
444 call s:check_col_calc(3, 1, 1)
445 exe "normal \<C-E>"
446 call s:check_col_calc(3, 2, 37)
447 exe "normal \<C-Y>"
448 call s:check_col_calc(3, 3, 37)
449 normal ggl
450
451 " Only move 1 line down when we are just past the <<< display
452 call s:check_col_calc(4, 1, 2)
453 exe "normal \<C-E>"
454 call s:check_col_calc(4, 1, 20)
455 exe "normal \<C-Y>"
456 call s:check_col_calc(4, 2, 20)
457 normal gg
458 setl numberwidth&
459
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000460 " Test number + showbreak, so test that the additional indentation works
461 setl number showbreak=+++
462 call s:check_col_calc(5, 1, 1)
463 exe "normal \<C-E>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000464 call s:check_col_calc(8, 1, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000465 exe "normal \<C-Y>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000466 call s:check_col_calc(8, 2, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000467 normal gg
468
469 " Test number + cpo+=n mode, where wrapped lines aren't indented
470 setl number cpo+=n showbreak=
471 call s:check_col_calc(5, 1, 1)
472 exe "normal \<C-E>"
473 call s:check_col_calc(1, 2, 37)
474 exe "normal \<C-Y>"
475 call s:check_col_calc(1, 3, 37)
476 normal gg
477
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000478 bwipe!
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000479endfunc
480
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000481func Test_smoothscroll_cursor_scrolloff()
482 call NewWindow(10, 20)
483 setl smoothscroll wrap
484 setl scrolloff=3
Bram Moolenaar94722c52023-01-28 19:19:03 +0000485
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000486 " 120 chars are 6 screen lines
487 call setline(1, "abcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRST")
488 call setline(2, "below")
489
490 call s:check_col_calc(1, 1, 1)
491
492 " CTRL-E shows "<<<DEFG...", cursor move four lines down
493 exe "normal \<C-E>"
494 call s:check_col_calc(1, 4, 81)
495
496 " cursor on start of second line, "gk" moves into first line, skipcol doesn't
497 " change
498 exe "normal G0gk"
499 call s:check_col_calc(1, 5, 101)
500
501 " move cursor left one window width worth, scrolls one screen line
502 exe "normal 20h"
503 call s:check_col_calc(1, 5, 81)
504
505 " move cursor left one window width worth, scrolls one screen line
506 exe "normal 20h"
507 call s:check_col_calc(1, 4, 61)
508
Bram Moolenaarb21b8e92022-12-03 18:35:07 +0000509 " cursor on last line, "gk" should not cause a scroll
510 set scrolloff=0
511 normal G0
512 call s:check_col_calc(1, 7, 1)
513 normal gk
514 call s:check_col_calc(1, 6, 101)
515
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000516 bwipe!
517endfunc
518
519
Yee Cheng Chine6392b12022-11-19 14:31:08 +0000520" Test that mouse picking is still accurate when we have smooth scrolled lines
521func Test_smoothscroll_mouse_pos()
522 CheckNotGui
523 CheckUnix
524
525 let save_mouse = &mouse
526 let save_term = &term
527 let save_ttymouse = &ttymouse
528 set mouse=a term=xterm ttymouse=xterm2
529
530 call NewWindow(10, 20)
531 setl smoothscroll wrap
532 " First line will wrap to 3 physical lines. 2nd/3rd lines are short lines.
533 call setline(1, ["abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", "line 2", "line 3"])
534
535 func s:check_mouse_click(row, col, buf_row, buf_col)
536 call MouseLeftClick(a:row, a:col)
537
538 call assert_equal(a:col, wincol())
539 call assert_equal(a:row, winline())
540 call assert_equal(a:buf_row, line('.'))
541 call assert_equal(a:buf_col, col('.'))
542 endfunc
543
544 " Check that clicking without scroll works first.
545 call s:check_mouse_click(3, 5, 1, 45)
546 call s:check_mouse_click(4, 1, 2, 1)
547 call s:check_mouse_click(4, 6, 2, 6)
548 call s:check_mouse_click(5, 1, 3, 1)
549 call s:check_mouse_click(5, 6, 3, 6)
550
551 " Smooth scroll, and checks that this didn't mess up mouse clicking
552 exe "normal \<C-E>"
553 call s:check_mouse_click(2, 5, 1, 45)
554 call s:check_mouse_click(3, 1, 2, 1)
555 call s:check_mouse_click(3, 6, 2, 6)
556 call s:check_mouse_click(4, 1, 3, 1)
557 call s:check_mouse_click(4, 6, 3, 6)
558
559 exe "normal \<C-E>"
560 call s:check_mouse_click(1, 5, 1, 45)
561 call s:check_mouse_click(2, 1, 2, 1)
562 call s:check_mouse_click(2, 6, 2, 6)
563 call s:check_mouse_click(3, 1, 3, 1)
564 call s:check_mouse_click(3, 6, 3, 6)
565
566 " Make a new first line 11 physical lines tall so it's taller than window
567 " height, to test overflow calculations with really long lines wrapping.
568 normal gg
569 call setline(1, "12345678901234567890"->repeat(11))
570 exe "normal 6\<C-E>"
571 call s:check_mouse_click(5, 1, 1, 201)
572 call s:check_mouse_click(6, 1, 2, 1)
573 call s:check_mouse_click(7, 1, 3, 1)
574
575 let &mouse = save_mouse
576 let &term = save_term
577 let &ttymouse = save_ttymouse
578endfunc
579
Bram Moolenaar870219c2023-01-26 14:14:43 +0000580" this was dividing by zero
581func Test_smoothscrol_zero_width()
582 CheckScreendump
583
584 let lines =<< trim END
585 winsize 0 0
586 vsplit
587 vsplit
588 vsplit
589 vsplit
590 vsplit
591 sil norm H
592 set wrap
593 set smoothscroll
594 set number
595 END
596 call writefile(lines, 'XSmoothScrollZero', 'D')
597 let buf = RunVimInTerminal('-u NONE -i NONE -n -m -X -Z -e -s -S XSmoothScrollZero', #{rows: 6, cols: 60, wait_for_ruler: 0})
598 call TermWait(buf, 3000)
599 call VerifyScreenDump(buf, 'Test_smoothscroll_zero_1', {})
600
601 call term_sendkeys(buf, ":sil norm \<C-V>\<C-W>\<C-V>\<C-N>\<CR>")
602 call VerifyScreenDump(buf, 'Test_smoothscroll_zero_2', {})
603
604 call StopVimInTerminal(buf)
605endfunc
606
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100607
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200608" vim: shiftwidth=2 sts=2 expandtab