blob: c146c018a68f2c71d52397c79b1b749e204bee3d [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 Moolenaar8df97482022-10-03 12:11:13 +010041func Test_CtrlE_CtrlY_stop_at_end()
42 enew
43 call setline(1, ['one', 'two'])
44 set number
45 exe "normal \<C-Y>"
46 call assert_equal([" 1 one "], ScreenLines(1, 10))
47 exe "normal \<C-E>\<C-E>\<C-E>"
48 call assert_equal([" 2 two "], ScreenLines(1, 10))
49
50 bwipe!
51 set nonumber
52endfunc
53
Bram Moolenaarf6196f42022-10-02 21:29:55 +010054func Test_smoothscroll_CtrlE_CtrlY()
55 CheckScreendump
56
57 let lines =<< trim END
58 vim9script
59 setline(1, [
60 'line one',
61 'word '->repeat(20),
62 'line three',
63 'long word '->repeat(7),
64 'line',
65 'line',
66 'line',
67 ])
68 set smoothscroll
69 :5
70 END
71 call writefile(lines, 'XSmoothScroll', 'D')
72 let buf = RunVimInTerminal('-S XSmoothScroll', #{rows: 12, cols: 40})
73
74 call term_sendkeys(buf, "\<C-E>")
75 call VerifyScreenDump(buf, 'Test_smoothscroll_1', {})
76 call term_sendkeys(buf, "\<C-E>")
77 call VerifyScreenDump(buf, 'Test_smoothscroll_2', {})
78 call term_sendkeys(buf, "\<C-E>")
79 call VerifyScreenDump(buf, 'Test_smoothscroll_3', {})
80 call term_sendkeys(buf, "\<C-E>")
81 call VerifyScreenDump(buf, 'Test_smoothscroll_4', {})
82
83 call term_sendkeys(buf, "\<C-Y>")
84 call VerifyScreenDump(buf, 'Test_smoothscroll_5', {})
85 call term_sendkeys(buf, "\<C-Y>")
86 call VerifyScreenDump(buf, 'Test_smoothscroll_6', {})
87 call term_sendkeys(buf, "\<C-Y>")
88 call VerifyScreenDump(buf, 'Test_smoothscroll_7', {})
89 call term_sendkeys(buf, "\<C-Y>")
90 call VerifyScreenDump(buf, 'Test_smoothscroll_8', {})
91
Bram Moolenaar6b2d4ff2022-10-03 14:06:02 +010092 if has('folding')
93 call term_sendkeys(buf, ":set foldmethod=indent\<CR>")
94 " move the cursor so we can reuse the same dumps
95 call term_sendkeys(buf, "5G")
96 call term_sendkeys(buf, "\<C-E>")
97 call VerifyScreenDump(buf, 'Test_smoothscroll_1', {})
98 call term_sendkeys(buf, "\<C-E>")
99 call VerifyScreenDump(buf, 'Test_smoothscroll_2', {})
100 call term_sendkeys(buf, "7G")
101 call term_sendkeys(buf, "\<C-Y>")
102 call VerifyScreenDump(buf, 'Test_smoothscroll_7', {})
103 call term_sendkeys(buf, "\<C-Y>")
104 call VerifyScreenDump(buf, 'Test_smoothscroll_8', {})
105 endif
106
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100107 call StopVimInTerminal(buf)
108endfunc
109
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +0100110func Test_smoothscroll_number()
111 CheckScreendump
112
113 let lines =<< trim END
114 vim9script
115 setline(1, [
116 'one ' .. 'word '->repeat(20),
117 'two ' .. 'long word '->repeat(7),
118 'line',
119 'line',
120 'line',
121 ])
122 set smoothscroll
123 set number cpo+=n
124 :3
Bram Moolenaareb4de622022-10-15 13:42:17 +0100125
126 def g:DoRel()
127 set number relativenumber scrolloff=0
128 :%del
129 setline(1, [
130 'one',
131 'very long text '->repeat(12),
132 'three',
133 ])
134 exe "normal 2Gzt\<C-E>"
135 enddef
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +0100136 END
137 call writefile(lines, 'XSmoothNumber', 'D')
138 let buf = RunVimInTerminal('-S XSmoothNumber', #{rows: 12, cols: 40})
139
140 call VerifyScreenDump(buf, 'Test_smooth_number_1', {})
141 call term_sendkeys(buf, "\<C-E>")
142 call VerifyScreenDump(buf, 'Test_smooth_number_2', {})
143 call term_sendkeys(buf, "\<C-E>")
144 call VerifyScreenDump(buf, 'Test_smooth_number_3', {})
145
146 call term_sendkeys(buf, ":set cpo-=n\<CR>")
147 call VerifyScreenDump(buf, 'Test_smooth_number_4', {})
148 call term_sendkeys(buf, "\<C-Y>")
149 call VerifyScreenDump(buf, 'Test_smooth_number_5', {})
150 call term_sendkeys(buf, "\<C-Y>")
151 call VerifyScreenDump(buf, 'Test_smooth_number_6', {})
152
Bram Moolenaareb4de622022-10-15 13:42:17 +0100153 call term_sendkeys(buf, ":call DoRel()\<CR>")
154 call VerifyScreenDump(buf, 'Test_smooth_number_7', {})
155
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +0100156 call StopVimInTerminal(buf)
157endfunc
158
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100159func Test_smoothscroll_list()
160 CheckScreendump
161
162 let lines =<< trim END
163 vim9script
164 set smoothscroll scrolloff=0
165 set list
166 setline(1, [
167 'one',
168 'very long text '->repeat(12),
169 'three',
170 ])
171 exe "normal 2Gzt\<C-E>"
172 END
173 call writefile(lines, 'XSmoothList', 'D')
174 let buf = RunVimInTerminal('-S XSmoothList', #{rows: 8, cols: 40})
175
176 call VerifyScreenDump(buf, 'Test_smooth_list_1', {})
177
178 call term_sendkeys(buf, ":set listchars+=precedes:#\<CR>")
179 call VerifyScreenDump(buf, 'Test_smooth_list_2', {})
180
181 call StopVimInTerminal(buf)
182endfunc
183
Bram Moolenaar1a58e1d2022-10-06 13:09:17 +0100184func Test_smoothscroll_diff_mode()
185 CheckScreendump
186
187 let lines =<< trim END
188 vim9script
189 var text = 'just some text here'
190 setline(1, text)
191 set smoothscroll
192 diffthis
193 new
194 setline(1, text)
195 set smoothscroll
196 diffthis
197 END
198 call writefile(lines, 'XSmoothDiff', 'D')
199 let buf = RunVimInTerminal('-S XSmoothDiff', #{rows: 8})
200
201 call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
202 call term_sendkeys(buf, "\<C-Y>")
203 call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
204 call term_sendkeys(buf, "\<C-E>")
205 call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
206
207 call StopVimInTerminal(buf)
208endfunc
209
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100210func Test_smoothscroll_wrap_scrolloff_zero()
211 CheckScreendump
212
213 let lines =<< trim END
214 vim9script
215 setline(1, ['Line' .. (' with some text'->repeat(7))]->repeat(7))
216 set smoothscroll scrolloff=0
217 :3
218 END
219 call writefile(lines, 'XSmoothWrap', 'D')
220 let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 8, cols: 40})
221
222 call VerifyScreenDump(buf, 'Test_smooth_wrap_1', {})
223
Bram Moolenaar46b54742022-10-06 15:46:49 +0100224 " moving cursor down - whole bottom line shows
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100225 call term_sendkeys(buf, "j")
226 call VerifyScreenDump(buf, 'Test_smooth_wrap_2', {})
227
228 call term_sendkeys(buf, "\<C-E>j")
229 call VerifyScreenDump(buf, 'Test_smooth_wrap_3', {})
230
231 call term_sendkeys(buf, "G")
232 call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {})
233
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000234 " moving cursor up right after the >>> marker - no need to show whole line
235 call term_sendkeys(buf, "2gj3l2k")
Bram Moolenaar46b54742022-10-06 15:46:49 +0100236 call VerifyScreenDump(buf, 'Test_smooth_wrap_5', {})
237
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000238 " moving cursor up where the >>> marker is - whole top line shows
239 call term_sendkeys(buf, "2j02k")
240 call VerifyScreenDump(buf, 'Test_smooth_wrap_6', {})
241
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100242 call StopVimInTerminal(buf)
243endfunc
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100244
Bram Moolenaar8cf34592022-10-08 21:13:40 +0100245func Test_smoothscroll_wrap_long_line()
246 CheckScreendump
247
248 let lines =<< trim END
249 vim9script
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000250 setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(30)) .. ' end', 'four'])
Bram Moolenaar8cf34592022-10-08 21:13:40 +0100251 set smoothscroll scrolloff=0
252 normal 3G10|zt
253 END
254 call writefile(lines, 'XSmoothWrap', 'D')
255 let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 6, cols: 40})
256 call VerifyScreenDump(buf, 'Test_smooth_long_1', {})
257
258 " scrolling up, cursor moves screen line down
259 call term_sendkeys(buf, "\<C-E>")
260 call VerifyScreenDump(buf, 'Test_smooth_long_2', {})
261 call term_sendkeys(buf, "5\<C-E>")
262 call VerifyScreenDump(buf, 'Test_smooth_long_3', {})
263
264 " scrolling down, cursor moves screen line up
265 call term_sendkeys(buf, "5\<C-Y>")
266 call VerifyScreenDump(buf, 'Test_smooth_long_4', {})
267 call term_sendkeys(buf, "\<C-Y>")
268 call VerifyScreenDump(buf, 'Test_smooth_long_5', {})
269
Bram Moolenaar118c2352022-10-09 17:19:27 +0100270 " 'scrolloff' set to 1, scrolling up, cursor moves screen line down
271 call term_sendkeys(buf, ":set scrolloff=1\<CR>")
272 call term_sendkeys(buf, "10|\<C-E>")
273 call VerifyScreenDump(buf, 'Test_smooth_long_6', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000274
Bram Moolenaar118c2352022-10-09 17:19:27 +0100275 " 'scrolloff' set to 1, scrolling down, cursor moves screen line up
276 call term_sendkeys(buf, "\<C-E>")
277 call term_sendkeys(buf, "gjgj")
278 call term_sendkeys(buf, "\<C-Y>")
279 call VerifyScreenDump(buf, 'Test_smooth_long_7', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000280
Bram Moolenaar118c2352022-10-09 17:19:27 +0100281 " 'scrolloff' set to 2, scrolling up, cursor moves screen line down
282 call term_sendkeys(buf, ":set scrolloff=2\<CR>")
283 call term_sendkeys(buf, "10|\<C-E>")
284 call VerifyScreenDump(buf, 'Test_smooth_long_8', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000285
Bram Moolenaar118c2352022-10-09 17:19:27 +0100286 " 'scrolloff' set to 2, scrolling down, cursor moves screen line up
287 call term_sendkeys(buf, "\<C-E>")
288 call term_sendkeys(buf, "gj")
289 call term_sendkeys(buf, "\<C-Y>")
290 call VerifyScreenDump(buf, 'Test_smooth_long_9', {})
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000291
292 " 'scrolloff' set to 0, move cursor down one line.
293 " Cursor should move properly, and since this is a really long line, it will
294 " be put on top of the screen.
295 call term_sendkeys(buf, ":set scrolloff=0\<CR>")
296 call term_sendkeys(buf, "0j")
297 call VerifyScreenDump(buf, 'Test_smooth_long_10', {})
298
Bram Moolenaardb4d88c2022-12-31 15:13:22 +0000299 " Test zt/zz/zb that they work properly when a long line is above it
300 call term_sendkeys(buf, "zb")
301 call VerifyScreenDump(buf, 'Test_smooth_long_11', {})
302 call term_sendkeys(buf, "zz")
303 call VerifyScreenDump(buf, 'Test_smooth_long_12', {})
304 call term_sendkeys(buf, "zt")
305 call VerifyScreenDump(buf, 'Test_smooth_long_13', {})
306
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000307 " Repeat the step and move the cursor down again.
308 " This time, use a shorter long line that is barely long enough to span more
309 " than one window. Note that the cursor is at the bottom this time because
310 " Vim prefers to do so if we are scrolling a few lines only.
311 call term_sendkeys(buf, ":call setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(10)) .. ' end', 'four'])\<CR>")
312 call term_sendkeys(buf, "3Gzt")
313 call term_sendkeys(buf, "j")
Bram Moolenaardb4d88c2022-12-31 15:13:22 +0000314 call VerifyScreenDump(buf, 'Test_smooth_long_14', {})
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000315
316 " Repeat the step but this time start it when the line is smooth-scrolled by
317 " one line. This tests that the offset calculation is still correct and
318 " still end up scrolling down to the next line with cursor at bottom of
319 " screen.
320 call term_sendkeys(buf, "3Gzt")
321 call term_sendkeys(buf, "\<C-E>j")
Bram Moolenaardb4d88c2022-12-31 15:13:22 +0000322 call VerifyScreenDump(buf, 'Test_smooth_long_15', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000323
Bram Moolenaar8cf34592022-10-08 21:13:40 +0100324 call StopVimInTerminal(buf)
325endfunc
326
Bram Moolenaar2fbabd22022-10-12 19:53:38 +0100327func Test_smoothscroll_one_long_line()
328 CheckScreendump
329
330 let lines =<< trim END
331 vim9script
332 setline(1, 'with lots of text '->repeat(7))
333 set smoothscroll scrolloff=0
334 END
335 call writefile(lines, 'XSmoothOneLong', 'D')
336 let buf = RunVimInTerminal('-S XSmoothOneLong', #{rows: 6, cols: 40})
337 call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000338
Bram Moolenaar2fbabd22022-10-12 19:53:38 +0100339 call term_sendkeys(buf, "\<C-E>")
340 call VerifyScreenDump(buf, 'Test_smooth_one_long_2', {})
341
342 call term_sendkeys(buf, "0")
343 call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {})
344
345 call StopVimInTerminal(buf)
346endfunc
347
Bram Moolenaar75ac25b2022-11-17 19:00:14 +0000348func Test_smoothscroll_long_line_showbreak()
349 CheckScreendump
350
351 let lines =<< trim END
352 vim9script
353 # a line that spans four screen lines
354 setline(1, 'with lots of text in one line '->repeat(6))
355 set smoothscroll scrolloff=0 showbreak=+++\
356 END
357 call writefile(lines, 'XSmoothLongShowbreak', 'D')
358 let buf = RunVimInTerminal('-S XSmoothLongShowbreak', #{rows: 6, cols: 40})
359 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_1', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000360
Bram Moolenaar75ac25b2022-11-17 19:00:14 +0000361 call term_sendkeys(buf, "\<C-E>")
362 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_2', {})
363
364 call term_sendkeys(buf, "0")
365 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_1', {})
366
367 call StopVimInTerminal(buf)
368endfunc
369
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000370func s:check_col_calc(win_col, win_line, buf_col)
371 call assert_equal(a:win_col, wincol())
372 call assert_equal(a:win_line, winline())
373 call assert_equal(a:buf_col, col('.'))
374endfunc
375
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000376" Test that if the current cursor is on a smooth scrolled line, we correctly
377" reposition it. Also check that we don't miscalculate the values by checking
378" the consistency between wincol() and col('.') as they are calculated
379" separately in code.
380func Test_smoothscroll_cursor_position()
381 call NewWindow(10, 20)
382 setl smoothscroll wrap
383 call setline(1, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
384
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000385 call s:check_col_calc(1, 1, 1)
386 exe "normal \<C-E>"
387
388 " Move down another line to avoid blocking the <<< display
389 call s:check_col_calc(1, 2, 41)
390 exe "normal \<C-Y>"
391 call s:check_col_calc(1, 3, 41)
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000392
393 normal gg3l
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000394 exe "normal \<C-E>"
395
396 " Move down only 1 line when we are out of the range of the <<< display
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000397 call s:check_col_calc(4, 1, 24)
398 exe "normal \<C-Y>"
399 call s:check_col_calc(4, 2, 24)
400 normal ggg$
401 exe "normal \<C-E>"
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000402 call s:check_col_calc(20, 1, 40)
403 exe "normal \<C-Y>"
404 call s:check_col_calc(20, 2, 40)
405 normal gg
406
407 " Test number, where we have indented lines
408 setl number
409 call s:check_col_calc(5, 1, 1)
410 exe "normal \<C-E>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000411
412 " Move down only 1 line when the <<< display is on the number column
413 call s:check_col_calc(5, 1, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000414 exe "normal \<C-Y>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000415 call s:check_col_calc(5, 2, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000416 normal ggg$
417 exe "normal \<C-E>"
418 call s:check_col_calc(20, 1, 32)
419 exe "normal \<C-Y>"
420 call s:check_col_calc(20, 2, 32)
421 normal gg
422
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000423 setl numberwidth=1
424
425 " Move down another line when numberwidth is too short to cover the whole
426 " <<< display
427 call s:check_col_calc(3, 1, 1)
428 exe "normal \<C-E>"
429 call s:check_col_calc(3, 2, 37)
430 exe "normal \<C-Y>"
431 call s:check_col_calc(3, 3, 37)
432 normal ggl
433
434 " Only move 1 line down when we are just past the <<< display
435 call s:check_col_calc(4, 1, 2)
436 exe "normal \<C-E>"
437 call s:check_col_calc(4, 1, 20)
438 exe "normal \<C-Y>"
439 call s:check_col_calc(4, 2, 20)
440 normal gg
441 setl numberwidth&
442
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000443 " Test number + showbreak, so test that the additional indentation works
444 setl number showbreak=+++
445 call s:check_col_calc(5, 1, 1)
446 exe "normal \<C-E>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000447 call s:check_col_calc(8, 1, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000448 exe "normal \<C-Y>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000449 call s:check_col_calc(8, 2, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000450 normal gg
451
452 " Test number + cpo+=n mode, where wrapped lines aren't indented
453 setl number cpo+=n showbreak=
454 call s:check_col_calc(5, 1, 1)
455 exe "normal \<C-E>"
456 call s:check_col_calc(1, 2, 37)
457 exe "normal \<C-Y>"
458 call s:check_col_calc(1, 3, 37)
459 normal gg
460
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000461 bwipe!
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000462endfunc
463
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000464func Test_smoothscroll_cursor_scrolloff()
465 call NewWindow(10, 20)
466 setl smoothscroll wrap
467 setl scrolloff=3
Bram Moolenaar94722c52023-01-28 19:19:03 +0000468
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000469 " 120 chars are 6 screen lines
470 call setline(1, "abcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRST")
471 call setline(2, "below")
472
473 call s:check_col_calc(1, 1, 1)
474
475 " CTRL-E shows "<<<DEFG...", cursor move four lines down
476 exe "normal \<C-E>"
477 call s:check_col_calc(1, 4, 81)
478
479 " cursor on start of second line, "gk" moves into first line, skipcol doesn't
480 " change
481 exe "normal G0gk"
482 call s:check_col_calc(1, 5, 101)
483
484 " move cursor left one window width worth, scrolls one screen line
485 exe "normal 20h"
486 call s:check_col_calc(1, 5, 81)
487
488 " move cursor left one window width worth, scrolls one screen line
489 exe "normal 20h"
490 call s:check_col_calc(1, 4, 61)
491
Bram Moolenaarb21b8e92022-12-03 18:35:07 +0000492 " cursor on last line, "gk" should not cause a scroll
493 set scrolloff=0
494 normal G0
495 call s:check_col_calc(1, 7, 1)
496 normal gk
497 call s:check_col_calc(1, 6, 101)
498
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000499 bwipe!
500endfunc
501
502
Yee Cheng Chine6392b12022-11-19 14:31:08 +0000503" Test that mouse picking is still accurate when we have smooth scrolled lines
504func Test_smoothscroll_mouse_pos()
505 CheckNotGui
506 CheckUnix
507
508 let save_mouse = &mouse
509 let save_term = &term
510 let save_ttymouse = &ttymouse
511 set mouse=a term=xterm ttymouse=xterm2
512
513 call NewWindow(10, 20)
514 setl smoothscroll wrap
515 " First line will wrap to 3 physical lines. 2nd/3rd lines are short lines.
516 call setline(1, ["abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", "line 2", "line 3"])
517
518 func s:check_mouse_click(row, col, buf_row, buf_col)
519 call MouseLeftClick(a:row, a:col)
520
521 call assert_equal(a:col, wincol())
522 call assert_equal(a:row, winline())
523 call assert_equal(a:buf_row, line('.'))
524 call assert_equal(a:buf_col, col('.'))
525 endfunc
526
527 " Check that clicking without scroll works first.
528 call s:check_mouse_click(3, 5, 1, 45)
529 call s:check_mouse_click(4, 1, 2, 1)
530 call s:check_mouse_click(4, 6, 2, 6)
531 call s:check_mouse_click(5, 1, 3, 1)
532 call s:check_mouse_click(5, 6, 3, 6)
533
534 " Smooth scroll, and checks that this didn't mess up mouse clicking
535 exe "normal \<C-E>"
536 call s:check_mouse_click(2, 5, 1, 45)
537 call s:check_mouse_click(3, 1, 2, 1)
538 call s:check_mouse_click(3, 6, 2, 6)
539 call s:check_mouse_click(4, 1, 3, 1)
540 call s:check_mouse_click(4, 6, 3, 6)
541
542 exe "normal \<C-E>"
543 call s:check_mouse_click(1, 5, 1, 45)
544 call s:check_mouse_click(2, 1, 2, 1)
545 call s:check_mouse_click(2, 6, 2, 6)
546 call s:check_mouse_click(3, 1, 3, 1)
547 call s:check_mouse_click(3, 6, 3, 6)
548
549 " Make a new first line 11 physical lines tall so it's taller than window
550 " height, to test overflow calculations with really long lines wrapping.
551 normal gg
552 call setline(1, "12345678901234567890"->repeat(11))
553 exe "normal 6\<C-E>"
554 call s:check_mouse_click(5, 1, 1, 201)
555 call s:check_mouse_click(6, 1, 2, 1)
556 call s:check_mouse_click(7, 1, 3, 1)
557
558 let &mouse = save_mouse
559 let &term = save_term
560 let &ttymouse = save_ttymouse
561endfunc
562
Bram Moolenaar870219c2023-01-26 14:14:43 +0000563" this was dividing by zero
564func Test_smoothscrol_zero_width()
565 CheckScreendump
566
567 let lines =<< trim END
568 winsize 0 0
569 vsplit
570 vsplit
571 vsplit
572 vsplit
573 vsplit
574 sil norm H
575 set wrap
576 set smoothscroll
577 set number
578 END
579 call writefile(lines, 'XSmoothScrollZero', 'D')
580 let buf = RunVimInTerminal('-u NONE -i NONE -n -m -X -Z -e -s -S XSmoothScrollZero', #{rows: 6, cols: 60, wait_for_ruler: 0})
581 call TermWait(buf, 3000)
582 call VerifyScreenDump(buf, 'Test_smoothscroll_zero_1', {})
583
584 call term_sendkeys(buf, ":sil norm \<C-V>\<C-W>\<C-V>\<C-N>\<CR>")
585 call VerifyScreenDump(buf, 'Test_smoothscroll_zero_2', {})
586
587 call StopVimInTerminal(buf)
588endfunc
589
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100590
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200591" vim: shiftwidth=2 sts=2 expandtab