blob: bab1e08fe8463b9891fbc7ffc1e8e034ad2b988c [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
zeertzjq88bb3e02023-05-02 20:52:59 +0100140 set splitkeep=topline
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +0100141 set number cpo+=n
142 :3
Bram Moolenaareb4de622022-10-15 13:42:17 +0100143
144 def g:DoRel()
145 set number relativenumber scrolloff=0
146 :%del
147 setline(1, [
148 'one',
149 'very long text '->repeat(12),
150 'three',
151 ])
152 exe "normal 2Gzt\<C-E>"
153 enddef
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +0100154 END
155 call writefile(lines, 'XSmoothNumber', 'D')
156 let buf = RunVimInTerminal('-S XSmoothNumber', #{rows: 12, cols: 40})
157
158 call VerifyScreenDump(buf, 'Test_smooth_number_1', {})
159 call term_sendkeys(buf, "\<C-E>")
160 call VerifyScreenDump(buf, 'Test_smooth_number_2', {})
161 call term_sendkeys(buf, "\<C-E>")
162 call VerifyScreenDump(buf, 'Test_smooth_number_3', {})
163
164 call term_sendkeys(buf, ":set cpo-=n\<CR>")
165 call VerifyScreenDump(buf, 'Test_smooth_number_4', {})
166 call term_sendkeys(buf, "\<C-Y>")
167 call VerifyScreenDump(buf, 'Test_smooth_number_5', {})
168 call term_sendkeys(buf, "\<C-Y>")
169 call VerifyScreenDump(buf, 'Test_smooth_number_6', {})
170
zeertzjq88bb3e02023-05-02 20:52:59 +0100171 call term_sendkeys(buf, ":botright split\<CR>gg")
Bram Moolenaareb4de622022-10-15 13:42:17 +0100172 call VerifyScreenDump(buf, 'Test_smooth_number_7', {})
zeertzjq88bb3e02023-05-02 20:52:59 +0100173 call term_sendkeys(buf, "\<C-E>")
174 call VerifyScreenDump(buf, 'Test_smooth_number_8', {})
175 call term_sendkeys(buf, "\<C-E>")
176 call VerifyScreenDump(buf, 'Test_smooth_number_9', {})
177 call term_sendkeys(buf, ":close\<CR>")
178
179 call term_sendkeys(buf, ":call DoRel()\<CR>")
180 call VerifyScreenDump(buf, 'Test_smooth_number_10', {})
Bram Moolenaareb4de622022-10-15 13:42:17 +0100181
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +0100182 call StopVimInTerminal(buf)
183endfunc
184
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100185func Test_smoothscroll_list()
186 CheckScreendump
187
188 let lines =<< trim END
189 vim9script
190 set smoothscroll scrolloff=0
191 set list
192 setline(1, [
193 'one',
194 'very long text '->repeat(12),
195 'three',
196 ])
197 exe "normal 2Gzt\<C-E>"
198 END
199 call writefile(lines, 'XSmoothList', 'D')
200 let buf = RunVimInTerminal('-S XSmoothList', #{rows: 8, cols: 40})
201
202 call VerifyScreenDump(buf, 'Test_smooth_list_1', {})
203
204 call term_sendkeys(buf, ":set listchars+=precedes:#\<CR>")
205 call VerifyScreenDump(buf, 'Test_smooth_list_2', {})
206
207 call StopVimInTerminal(buf)
208endfunc
209
Bram Moolenaar1a58e1d2022-10-06 13:09:17 +0100210func Test_smoothscroll_diff_mode()
211 CheckScreendump
212
213 let lines =<< trim END
214 vim9script
215 var text = 'just some text here'
216 setline(1, text)
217 set smoothscroll
218 diffthis
219 new
220 setline(1, text)
221 set smoothscroll
222 diffthis
223 END
224 call writefile(lines, 'XSmoothDiff', 'D')
225 let buf = RunVimInTerminal('-S XSmoothDiff', #{rows: 8})
226
227 call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
228 call term_sendkeys(buf, "\<C-Y>")
229 call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
230 call term_sendkeys(buf, "\<C-E>")
231 call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
232
233 call StopVimInTerminal(buf)
234endfunc
235
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100236func Test_smoothscroll_wrap_scrolloff_zero()
237 CheckScreendump
238
239 let lines =<< trim END
240 vim9script
241 setline(1, ['Line' .. (' with some text'->repeat(7))]->repeat(7))
242 set smoothscroll scrolloff=0
243 :3
244 END
245 call writefile(lines, 'XSmoothWrap', 'D')
246 let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 8, cols: 40})
247
248 call VerifyScreenDump(buf, 'Test_smooth_wrap_1', {})
249
Bram Moolenaar46b54742022-10-06 15:46:49 +0100250 " moving cursor down - whole bottom line shows
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100251 call term_sendkeys(buf, "j")
252 call VerifyScreenDump(buf, 'Test_smooth_wrap_2', {})
253
254 call term_sendkeys(buf, "\<C-E>j")
255 call VerifyScreenDump(buf, 'Test_smooth_wrap_3', {})
256
257 call term_sendkeys(buf, "G")
258 call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {})
259
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000260 " moving cursor up right after the >>> marker - no need to show whole line
261 call term_sendkeys(buf, "2gj3l2k")
Bram Moolenaar46b54742022-10-06 15:46:49 +0100262 call VerifyScreenDump(buf, 'Test_smooth_wrap_5', {})
263
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000264 " moving cursor up where the >>> marker is - whole top line shows
265 call term_sendkeys(buf, "2j02k")
266 call VerifyScreenDump(buf, 'Test_smooth_wrap_6', {})
267
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100268 call StopVimInTerminal(buf)
269endfunc
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100270
Bram Moolenaar8cf34592022-10-08 21:13:40 +0100271func Test_smoothscroll_wrap_long_line()
272 CheckScreendump
273
274 let lines =<< trim END
275 vim9script
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000276 setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(30)) .. ' end', 'four'])
Bram Moolenaar8cf34592022-10-08 21:13:40 +0100277 set smoothscroll scrolloff=0
278 normal 3G10|zt
279 END
280 call writefile(lines, 'XSmoothWrap', 'D')
281 let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 6, cols: 40})
282 call VerifyScreenDump(buf, 'Test_smooth_long_1', {})
283
284 " scrolling up, cursor moves screen line down
285 call term_sendkeys(buf, "\<C-E>")
286 call VerifyScreenDump(buf, 'Test_smooth_long_2', {})
287 call term_sendkeys(buf, "5\<C-E>")
288 call VerifyScreenDump(buf, 'Test_smooth_long_3', {})
289
290 " scrolling down, cursor moves screen line up
291 call term_sendkeys(buf, "5\<C-Y>")
292 call VerifyScreenDump(buf, 'Test_smooth_long_4', {})
293 call term_sendkeys(buf, "\<C-Y>")
294 call VerifyScreenDump(buf, 'Test_smooth_long_5', {})
295
Bram Moolenaar118c2352022-10-09 17:19:27 +0100296 " 'scrolloff' set to 1, scrolling up, cursor moves screen line down
297 call term_sendkeys(buf, ":set scrolloff=1\<CR>")
298 call term_sendkeys(buf, "10|\<C-E>")
299 call VerifyScreenDump(buf, 'Test_smooth_long_6', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000300
Bram Moolenaar118c2352022-10-09 17:19:27 +0100301 " 'scrolloff' set to 1, scrolling down, cursor moves screen line up
302 call term_sendkeys(buf, "\<C-E>")
303 call term_sendkeys(buf, "gjgj")
304 call term_sendkeys(buf, "\<C-Y>")
305 call VerifyScreenDump(buf, 'Test_smooth_long_7', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000306
Bram Moolenaar118c2352022-10-09 17:19:27 +0100307 " 'scrolloff' set to 2, scrolling up, cursor moves screen line down
308 call term_sendkeys(buf, ":set scrolloff=2\<CR>")
309 call term_sendkeys(buf, "10|\<C-E>")
310 call VerifyScreenDump(buf, 'Test_smooth_long_8', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000311
Bram Moolenaar118c2352022-10-09 17:19:27 +0100312 " 'scrolloff' set to 2, scrolling down, cursor moves screen line up
313 call term_sendkeys(buf, "\<C-E>")
314 call term_sendkeys(buf, "gj")
315 call term_sendkeys(buf, "\<C-Y>")
316 call VerifyScreenDump(buf, 'Test_smooth_long_9', {})
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000317
318 " 'scrolloff' set to 0, move cursor down one line.
319 " Cursor should move properly, and since this is a really long line, it will
320 " be put on top of the screen.
321 call term_sendkeys(buf, ":set scrolloff=0\<CR>")
322 call term_sendkeys(buf, "0j")
323 call VerifyScreenDump(buf, 'Test_smooth_long_10', {})
324
Bram Moolenaardb4d88c2022-12-31 15:13:22 +0000325 " Test zt/zz/zb that they work properly when a long line is above it
326 call term_sendkeys(buf, "zb")
327 call VerifyScreenDump(buf, 'Test_smooth_long_11', {})
328 call term_sendkeys(buf, "zz")
329 call VerifyScreenDump(buf, 'Test_smooth_long_12', {})
330 call term_sendkeys(buf, "zt")
331 call VerifyScreenDump(buf, 'Test_smooth_long_13', {})
332
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000333 " Repeat the step and move the cursor down again.
334 " This time, use a shorter long line that is barely long enough to span more
335 " than one window. Note that the cursor is at the bottom this time because
336 " Vim prefers to do so if we are scrolling a few lines only.
337 call term_sendkeys(buf, ":call setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(10)) .. ' end', 'four'])\<CR>")
338 call term_sendkeys(buf, "3Gzt")
339 call term_sendkeys(buf, "j")
Bram Moolenaardb4d88c2022-12-31 15:13:22 +0000340 call VerifyScreenDump(buf, 'Test_smooth_long_14', {})
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000341
342 " Repeat the step but this time start it when the line is smooth-scrolled by
343 " one line. This tests that the offset calculation is still correct and
344 " still end up scrolling down to the next line with cursor at bottom of
345 " screen.
346 call term_sendkeys(buf, "3Gzt")
347 call term_sendkeys(buf, "\<C-E>j")
Bram Moolenaardb4d88c2022-12-31 15:13:22 +0000348 call VerifyScreenDump(buf, 'Test_smooth_long_15', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000349
Bram Moolenaar8cf34592022-10-08 21:13:40 +0100350 call StopVimInTerminal(buf)
351endfunc
352
Bram Moolenaar2fbabd22022-10-12 19:53:38 +0100353func Test_smoothscroll_one_long_line()
354 CheckScreendump
355
356 let lines =<< trim END
357 vim9script
358 setline(1, 'with lots of text '->repeat(7))
359 set smoothscroll scrolloff=0
360 END
361 call writefile(lines, 'XSmoothOneLong', 'D')
362 let buf = RunVimInTerminal('-S XSmoothOneLong', #{rows: 6, cols: 40})
363 call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000364
Bram Moolenaar2fbabd22022-10-12 19:53:38 +0100365 call term_sendkeys(buf, "\<C-E>")
366 call VerifyScreenDump(buf, 'Test_smooth_one_long_2', {})
367
368 call term_sendkeys(buf, "0")
369 call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {})
370
371 call StopVimInTerminal(buf)
372endfunc
373
Bram Moolenaar75ac25b2022-11-17 19:00:14 +0000374func Test_smoothscroll_long_line_showbreak()
375 CheckScreendump
376
377 let lines =<< trim END
378 vim9script
379 # a line that spans four screen lines
380 setline(1, 'with lots of text in one line '->repeat(6))
381 set smoothscroll scrolloff=0 showbreak=+++\
382 END
383 call writefile(lines, 'XSmoothLongShowbreak', 'D')
384 let buf = RunVimInTerminal('-S XSmoothLongShowbreak', #{rows: 6, cols: 40})
385 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_1', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000386
Bram Moolenaar75ac25b2022-11-17 19:00:14 +0000387 call term_sendkeys(buf, "\<C-E>")
388 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_2', {})
389
390 call term_sendkeys(buf, "0")
391 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_1', {})
392
393 call StopVimInTerminal(buf)
394endfunc
395
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000396func s:check_col_calc(win_col, win_line, buf_col)
397 call assert_equal(a:win_col, wincol())
398 call assert_equal(a:win_line, winline())
399 call assert_equal(a:buf_col, col('.'))
400endfunc
401
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000402" Test that if the current cursor is on a smooth scrolled line, we correctly
403" reposition it. Also check that we don't miscalculate the values by checking
404" the consistency between wincol() and col('.') as they are calculated
405" separately in code.
406func Test_smoothscroll_cursor_position()
407 call NewWindow(10, 20)
408 setl smoothscroll wrap
409 call setline(1, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
410
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000411 call s:check_col_calc(1, 1, 1)
412 exe "normal \<C-E>"
413
414 " Move down another line to avoid blocking the <<< display
415 call s:check_col_calc(1, 2, 41)
416 exe "normal \<C-Y>"
417 call s:check_col_calc(1, 3, 41)
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000418
419 normal gg3l
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000420 exe "normal \<C-E>"
421
422 " Move down only 1 line when we are out of the range of the <<< display
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000423 call s:check_col_calc(4, 1, 24)
424 exe "normal \<C-Y>"
425 call s:check_col_calc(4, 2, 24)
426 normal ggg$
427 exe "normal \<C-E>"
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000428 call s:check_col_calc(20, 1, 40)
429 exe "normal \<C-Y>"
430 call s:check_col_calc(20, 2, 40)
431 normal gg
432
433 " Test number, where we have indented lines
434 setl number
435 call s:check_col_calc(5, 1, 1)
436 exe "normal \<C-E>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000437
438 " Move down only 1 line when the <<< display is on the number column
439 call s:check_col_calc(5, 1, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000440 exe "normal \<C-Y>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000441 call s:check_col_calc(5, 2, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000442 normal ggg$
443 exe "normal \<C-E>"
444 call s:check_col_calc(20, 1, 32)
445 exe "normal \<C-Y>"
446 call s:check_col_calc(20, 2, 32)
447 normal gg
448
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000449 setl numberwidth=1
450
451 " Move down another line when numberwidth is too short to cover the whole
452 " <<< display
453 call s:check_col_calc(3, 1, 1)
454 exe "normal \<C-E>"
455 call s:check_col_calc(3, 2, 37)
456 exe "normal \<C-Y>"
457 call s:check_col_calc(3, 3, 37)
458 normal ggl
459
460 " Only move 1 line down when we are just past the <<< display
461 call s:check_col_calc(4, 1, 2)
462 exe "normal \<C-E>"
463 call s:check_col_calc(4, 1, 20)
464 exe "normal \<C-Y>"
465 call s:check_col_calc(4, 2, 20)
466 normal gg
467 setl numberwidth&
468
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000469 " Test number + showbreak, so test that the additional indentation works
470 setl number showbreak=+++
471 call s:check_col_calc(5, 1, 1)
472 exe "normal \<C-E>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000473 call s:check_col_calc(8, 1, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000474 exe "normal \<C-Y>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000475 call s:check_col_calc(8, 2, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000476 normal gg
477
478 " Test number + cpo+=n mode, where wrapped lines aren't indented
479 setl number cpo+=n showbreak=
480 call s:check_col_calc(5, 1, 1)
481 exe "normal \<C-E>"
482 call s:check_col_calc(1, 2, 37)
483 exe "normal \<C-Y>"
484 call s:check_col_calc(1, 3, 37)
485 normal gg
486
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000487 bwipe!
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000488endfunc
489
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000490func Test_smoothscroll_cursor_scrolloff()
491 call NewWindow(10, 20)
492 setl smoothscroll wrap
493 setl scrolloff=3
Bram Moolenaar94722c52023-01-28 19:19:03 +0000494
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000495 " 120 chars are 6 screen lines
496 call setline(1, "abcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRST")
497 call setline(2, "below")
498
499 call s:check_col_calc(1, 1, 1)
500
501 " CTRL-E shows "<<<DEFG...", cursor move four lines down
502 exe "normal \<C-E>"
503 call s:check_col_calc(1, 4, 81)
504
505 " cursor on start of second line, "gk" moves into first line, skipcol doesn't
506 " change
507 exe "normal G0gk"
508 call s:check_col_calc(1, 5, 101)
509
510 " move cursor left one window width worth, scrolls one screen line
511 exe "normal 20h"
512 call s:check_col_calc(1, 5, 81)
513
514 " move cursor left one window width worth, scrolls one screen line
515 exe "normal 20h"
516 call s:check_col_calc(1, 4, 61)
517
Bram Moolenaarb21b8e92022-12-03 18:35:07 +0000518 " cursor on last line, "gk" should not cause a scroll
519 set scrolloff=0
520 normal G0
521 call s:check_col_calc(1, 7, 1)
522 normal gk
523 call s:check_col_calc(1, 6, 101)
524
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000525 bwipe!
526endfunc
527
528
Yee Cheng Chine6392b12022-11-19 14:31:08 +0000529" Test that mouse picking is still accurate when we have smooth scrolled lines
530func Test_smoothscroll_mouse_pos()
531 CheckNotGui
532 CheckUnix
533
534 let save_mouse = &mouse
535 let save_term = &term
536 let save_ttymouse = &ttymouse
537 set mouse=a term=xterm ttymouse=xterm2
538
539 call NewWindow(10, 20)
540 setl smoothscroll wrap
541 " First line will wrap to 3 physical lines. 2nd/3rd lines are short lines.
542 call setline(1, ["abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", "line 2", "line 3"])
543
544 func s:check_mouse_click(row, col, buf_row, buf_col)
545 call MouseLeftClick(a:row, a:col)
546
547 call assert_equal(a:col, wincol())
548 call assert_equal(a:row, winline())
549 call assert_equal(a:buf_row, line('.'))
550 call assert_equal(a:buf_col, col('.'))
551 endfunc
552
553 " Check that clicking without scroll works first.
554 call s:check_mouse_click(3, 5, 1, 45)
555 call s:check_mouse_click(4, 1, 2, 1)
556 call s:check_mouse_click(4, 6, 2, 6)
557 call s:check_mouse_click(5, 1, 3, 1)
558 call s:check_mouse_click(5, 6, 3, 6)
559
560 " Smooth scroll, and checks that this didn't mess up mouse clicking
561 exe "normal \<C-E>"
562 call s:check_mouse_click(2, 5, 1, 45)
563 call s:check_mouse_click(3, 1, 2, 1)
564 call s:check_mouse_click(3, 6, 2, 6)
565 call s:check_mouse_click(4, 1, 3, 1)
566 call s:check_mouse_click(4, 6, 3, 6)
567
568 exe "normal \<C-E>"
569 call s:check_mouse_click(1, 5, 1, 45)
570 call s:check_mouse_click(2, 1, 2, 1)
571 call s:check_mouse_click(2, 6, 2, 6)
572 call s:check_mouse_click(3, 1, 3, 1)
573 call s:check_mouse_click(3, 6, 3, 6)
574
575 " Make a new first line 11 physical lines tall so it's taller than window
576 " height, to test overflow calculations with really long lines wrapping.
577 normal gg
578 call setline(1, "12345678901234567890"->repeat(11))
579 exe "normal 6\<C-E>"
580 call s:check_mouse_click(5, 1, 1, 201)
581 call s:check_mouse_click(6, 1, 2, 1)
582 call s:check_mouse_click(7, 1, 3, 1)
583
584 let &mouse = save_mouse
585 let &term = save_term
586 let &ttymouse = save_ttymouse
587endfunc
588
Bram Moolenaar870219c2023-01-26 14:14:43 +0000589" this was dividing by zero
590func Test_smoothscrol_zero_width()
591 CheckScreendump
592
593 let lines =<< trim END
594 winsize 0 0
595 vsplit
596 vsplit
597 vsplit
598 vsplit
599 vsplit
600 sil norm H
601 set wrap
602 set smoothscroll
603 set number
604 END
605 call writefile(lines, 'XSmoothScrollZero', 'D')
606 let buf = RunVimInTerminal('-u NONE -i NONE -n -m -X -Z -e -s -S XSmoothScrollZero', #{rows: 6, cols: 60, wait_for_ruler: 0})
607 call TermWait(buf, 3000)
608 call VerifyScreenDump(buf, 'Test_smoothscroll_zero_1', {})
609
610 call term_sendkeys(buf, ":sil norm \<C-V>\<C-W>\<C-V>\<C-N>\<CR>")
611 call VerifyScreenDump(buf, 'Test_smoothscroll_zero_2', {})
612
613 call StopVimInTerminal(buf)
614endfunc
615
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100616
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200617" vim: shiftwidth=2 sts=2 expandtab