blob: 636e7b76c50bf24c5de98aaa3c5e7744907d106a [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
Luuk van Baal6f37e532023-05-09 21:23:54 +0100326 call term_sendkeys(buf, "zt")
Bram Moolenaardb4d88c2022-12-31 15:13:22 +0000327 call VerifyScreenDump(buf, 'Test_smooth_long_11', {})
328 call term_sendkeys(buf, "zz")
329 call VerifyScreenDump(buf, 'Test_smooth_long_12', {})
Luuk van Baal6f37e532023-05-09 21:23:54 +0100330 call term_sendkeys(buf, "zb")
Bram Moolenaardb4d88c2022-12-31 15:13:22 +0000331 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>")
Luuk van Baal5d01f862023-05-11 19:24:20 +0100338 " Currently visible lines were replaced, test that the lines and cursor
339 " are correctly displayed.
340 call VerifyScreenDump(buf, 'Test_smooth_long_14', {})
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000341 call term_sendkeys(buf, "3Gzt")
342 call term_sendkeys(buf, "j")
Luuk van Baal5d01f862023-05-11 19:24:20 +0100343 call VerifyScreenDump(buf, 'Test_smooth_long_15', {})
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000344
345 " Repeat the step but this time start it when the line is smooth-scrolled by
346 " one line. This tests that the offset calculation is still correct and
347 " still end up scrolling down to the next line with cursor at bottom of
348 " screen.
349 call term_sendkeys(buf, "3Gzt")
350 call term_sendkeys(buf, "\<C-E>j")
Luuk van Baal5d01f862023-05-11 19:24:20 +0100351 call VerifyScreenDump(buf, 'Test_smooth_long_16', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000352
Bram Moolenaar8cf34592022-10-08 21:13:40 +0100353 call StopVimInTerminal(buf)
354endfunc
355
Bram Moolenaar2fbabd22022-10-12 19:53:38 +0100356func Test_smoothscroll_one_long_line()
357 CheckScreendump
358
359 let lines =<< trim END
360 vim9script
361 setline(1, 'with lots of text '->repeat(7))
362 set smoothscroll scrolloff=0
363 END
364 call writefile(lines, 'XSmoothOneLong', 'D')
365 let buf = RunVimInTerminal('-S XSmoothOneLong', #{rows: 6, cols: 40})
366 call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000367
Bram Moolenaar2fbabd22022-10-12 19:53:38 +0100368 call term_sendkeys(buf, "\<C-E>")
369 call VerifyScreenDump(buf, 'Test_smooth_one_long_2', {})
370
371 call term_sendkeys(buf, "0")
372 call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {})
373
374 call StopVimInTerminal(buf)
375endfunc
376
Bram Moolenaar75ac25b2022-11-17 19:00:14 +0000377func Test_smoothscroll_long_line_showbreak()
378 CheckScreendump
379
380 let lines =<< trim END
381 vim9script
382 # a line that spans four screen lines
383 setline(1, 'with lots of text in one line '->repeat(6))
384 set smoothscroll scrolloff=0 showbreak=+++\
385 END
386 call writefile(lines, 'XSmoothLongShowbreak', 'D')
387 let buf = RunVimInTerminal('-S XSmoothLongShowbreak', #{rows: 6, cols: 40})
388 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_1', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000389
Bram Moolenaar75ac25b2022-11-17 19:00:14 +0000390 call term_sendkeys(buf, "\<C-E>")
391 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_2', {})
392
393 call term_sendkeys(buf, "0")
394 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_1', {})
395
396 call StopVimInTerminal(buf)
397endfunc
398
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000399func s:check_col_calc(win_col, win_line, buf_col)
400 call assert_equal(a:win_col, wincol())
401 call assert_equal(a:win_line, winline())
402 call assert_equal(a:buf_col, col('.'))
403endfunc
404
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000405" Test that if the current cursor is on a smooth scrolled line, we correctly
406" reposition it. Also check that we don't miscalculate the values by checking
407" the consistency between wincol() and col('.') as they are calculated
408" separately in code.
409func Test_smoothscroll_cursor_position()
410 call NewWindow(10, 20)
411 setl smoothscroll wrap
412 call setline(1, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
413
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000414 call s:check_col_calc(1, 1, 1)
415 exe "normal \<C-E>"
416
417 " Move down another line to avoid blocking the <<< display
418 call s:check_col_calc(1, 2, 41)
419 exe "normal \<C-Y>"
420 call s:check_col_calc(1, 3, 41)
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000421
Luuk van Baal8667a562023-05-12 15:47:25 +0100422 " Test "g0/g<Home>"
423 exe "normal gg\<C-E>"
424 norm $gkg0
425 call s:check_col_calc(1, 2, 21)
426
427 " Test moving the cursor behind the <<< display with 'virtualedit'
428 set virtualedit=all
Luuk van Baal24b62ec2023-05-13 14:12:15 +0100429 exe "normal \<C-E>3lgkh"
Luuk van Baal8667a562023-05-12 15:47:25 +0100430 call s:check_col_calc(3, 2, 23)
431 set virtualedit&
432
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000433 normal gg3l
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000434 exe "normal \<C-E>"
435
436 " Move down only 1 line when we are out of the range of the <<< display
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000437 call s:check_col_calc(4, 1, 24)
438 exe "normal \<C-Y>"
439 call s:check_col_calc(4, 2, 24)
440 normal ggg$
441 exe "normal \<C-E>"
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000442 call s:check_col_calc(20, 1, 40)
443 exe "normal \<C-Y>"
444 call s:check_col_calc(20, 2, 40)
445 normal gg
446
447 " Test number, where we have indented lines
448 setl number
449 call s:check_col_calc(5, 1, 1)
450 exe "normal \<C-E>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000451
452 " Move down only 1 line when the <<< display is on the number column
453 call s:check_col_calc(5, 1, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000454 exe "normal \<C-Y>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000455 call s:check_col_calc(5, 2, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000456 normal ggg$
457 exe "normal \<C-E>"
458 call s:check_col_calc(20, 1, 32)
459 exe "normal \<C-Y>"
460 call s:check_col_calc(20, 2, 32)
461 normal gg
462
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000463 setl numberwidth=1
464
465 " Move down another line when numberwidth is too short to cover the whole
466 " <<< display
467 call s:check_col_calc(3, 1, 1)
468 exe "normal \<C-E>"
469 call s:check_col_calc(3, 2, 37)
470 exe "normal \<C-Y>"
471 call s:check_col_calc(3, 3, 37)
472 normal ggl
473
474 " Only move 1 line down when we are just past the <<< display
475 call s:check_col_calc(4, 1, 2)
476 exe "normal \<C-E>"
477 call s:check_col_calc(4, 1, 20)
478 exe "normal \<C-Y>"
479 call s:check_col_calc(4, 2, 20)
480 normal gg
481 setl numberwidth&
482
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000483 " Test number + showbreak, so test that the additional indentation works
484 setl number showbreak=+++
485 call s:check_col_calc(5, 1, 1)
486 exe "normal \<C-E>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000487 call s:check_col_calc(8, 1, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000488 exe "normal \<C-Y>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000489 call s:check_col_calc(8, 2, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000490 normal gg
491
492 " Test number + cpo+=n mode, where wrapped lines aren't indented
493 setl number cpo+=n showbreak=
494 call s:check_col_calc(5, 1, 1)
495 exe "normal \<C-E>"
496 call s:check_col_calc(1, 2, 37)
497 exe "normal \<C-Y>"
498 call s:check_col_calc(1, 3, 37)
499 normal gg
500
Luuk van Baal24b62ec2023-05-13 14:12:15 +0100501 " Test list + listchars "precedes", where there is always 1 overlap
502 " regardless of number and cpo-=n.
503 setl number list listchars=precedes:< cpo-=n
504 call s:check_col_calc(5, 1, 1)
505 exe "normal 2|\<C-E>"
506 call s:check_col_calc(6, 1, 18)
507 norm h
508 call s:check_col_calc(5, 2, 17)
509 normal gg
510
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000511 bwipe!
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000512endfunc
513
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000514func Test_smoothscroll_cursor_scrolloff()
515 call NewWindow(10, 20)
516 setl smoothscroll wrap
517 setl scrolloff=3
Bram Moolenaar94722c52023-01-28 19:19:03 +0000518
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000519 " 120 chars are 6 screen lines
520 call setline(1, "abcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRST")
521 call setline(2, "below")
522
523 call s:check_col_calc(1, 1, 1)
524
525 " CTRL-E shows "<<<DEFG...", cursor move four lines down
526 exe "normal \<C-E>"
527 call s:check_col_calc(1, 4, 81)
528
529 " cursor on start of second line, "gk" moves into first line, skipcol doesn't
530 " change
531 exe "normal G0gk"
532 call s:check_col_calc(1, 5, 101)
533
534 " move cursor left one window width worth, scrolls one screen line
535 exe "normal 20h"
536 call s:check_col_calc(1, 5, 81)
537
538 " move cursor left one window width worth, scrolls one screen line
539 exe "normal 20h"
540 call s:check_col_calc(1, 4, 61)
541
Bram Moolenaarb21b8e92022-12-03 18:35:07 +0000542 " cursor on last line, "gk" should not cause a scroll
543 set scrolloff=0
544 normal G0
545 call s:check_col_calc(1, 7, 1)
546 normal gk
547 call s:check_col_calc(1, 6, 101)
548
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000549 bwipe!
550endfunc
551
552
Yee Cheng Chine6392b12022-11-19 14:31:08 +0000553" Test that mouse picking is still accurate when we have smooth scrolled lines
554func Test_smoothscroll_mouse_pos()
555 CheckNotGui
556 CheckUnix
557
558 let save_mouse = &mouse
559 let save_term = &term
560 let save_ttymouse = &ttymouse
561 set mouse=a term=xterm ttymouse=xterm2
562
563 call NewWindow(10, 20)
564 setl smoothscroll wrap
565 " First line will wrap to 3 physical lines. 2nd/3rd lines are short lines.
566 call setline(1, ["abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", "line 2", "line 3"])
567
568 func s:check_mouse_click(row, col, buf_row, buf_col)
569 call MouseLeftClick(a:row, a:col)
570
571 call assert_equal(a:col, wincol())
572 call assert_equal(a:row, winline())
573 call assert_equal(a:buf_row, line('.'))
574 call assert_equal(a:buf_col, col('.'))
575 endfunc
576
577 " Check that clicking without scroll works first.
578 call s:check_mouse_click(3, 5, 1, 45)
579 call s:check_mouse_click(4, 1, 2, 1)
580 call s:check_mouse_click(4, 6, 2, 6)
581 call s:check_mouse_click(5, 1, 3, 1)
582 call s:check_mouse_click(5, 6, 3, 6)
583
584 " Smooth scroll, and checks that this didn't mess up mouse clicking
585 exe "normal \<C-E>"
586 call s:check_mouse_click(2, 5, 1, 45)
587 call s:check_mouse_click(3, 1, 2, 1)
588 call s:check_mouse_click(3, 6, 2, 6)
589 call s:check_mouse_click(4, 1, 3, 1)
590 call s:check_mouse_click(4, 6, 3, 6)
591
592 exe "normal \<C-E>"
593 call s:check_mouse_click(1, 5, 1, 45)
594 call s:check_mouse_click(2, 1, 2, 1)
595 call s:check_mouse_click(2, 6, 2, 6)
596 call s:check_mouse_click(3, 1, 3, 1)
597 call s:check_mouse_click(3, 6, 3, 6)
598
599 " Make a new first line 11 physical lines tall so it's taller than window
600 " height, to test overflow calculations with really long lines wrapping.
601 normal gg
602 call setline(1, "12345678901234567890"->repeat(11))
603 exe "normal 6\<C-E>"
604 call s:check_mouse_click(5, 1, 1, 201)
605 call s:check_mouse_click(6, 1, 2, 1)
606 call s:check_mouse_click(7, 1, 3, 1)
607
608 let &mouse = save_mouse
609 let &term = save_term
610 let &ttymouse = save_ttymouse
611endfunc
612
Bram Moolenaar870219c2023-01-26 14:14:43 +0000613" this was dividing by zero
Luuk van Baalc8502f92023-05-06 12:40:15 +0100614func Test_smoothscroll_zero_width()
Bram Moolenaar870219c2023-01-26 14:14:43 +0000615 CheckScreendump
616
617 let lines =<< trim END
618 winsize 0 0
619 vsplit
620 vsplit
621 vsplit
622 vsplit
623 vsplit
624 sil norm H
625 set wrap
626 set smoothscroll
627 set number
628 END
629 call writefile(lines, 'XSmoothScrollZero', 'D')
630 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 +0000631 call VerifyScreenDump(buf, 'Test_smoothscroll_zero_1', {})
632
633 call term_sendkeys(buf, ":sil norm \<C-V>\<C-W>\<C-V>\<C-N>\<CR>")
634 call VerifyScreenDump(buf, 'Test_smoothscroll_zero_2', {})
635
636 call StopVimInTerminal(buf)
637endfunc
638
Luuk van Baalc8502f92023-05-06 12:40:15 +0100639" this was unnecessarily inserting lines
640func Test_smoothscroll_ins_lines()
641 CheckScreendump
642
643 let lines =<< trim END
644 set wrap
645 set smoothscroll
646 set scrolloff=0
647 set conceallevel=2
648 call setline(1, [
649 \'line one' .. 'with lots of text in one line '->repeat(2),
650 \'line two',
651 \'line three',
652 \'line four',
653 \'line five'
654 \])
655 END
656 call writefile(lines, 'XSmoothScrollInsLines', 'D')
657 let buf = RunVimInTerminal('-S XSmoothScrollInsLines', #{rows: 6, cols: 40})
658
659 call term_sendkeys(buf, "\<C-E>gjgk")
660 call VerifyScreenDump(buf, 'Test_smooth_ins_lines', {})
661
662 call StopVimInTerminal(buf)
663endfunc
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100664
Luuk van Baal3ce8c382023-05-08 15:51:14 +0100665" this placed the cursor in the command line
666func Test_smoothscroll_cursormoved_line()
667 CheckScreendump
668
669 let lines =<< trim END
670 set smoothscroll
671 call setline(1, [
672 \'',
673 \'_'->repeat(&lines * &columns),
674 \(('_')->repeat(&columns - 2) .. 'xxx')->repeat(2)
675 \])
676 autocmd CursorMoved * eval [line('w0'), line('w$')]
677 call search('xxx')
678 END
679 call writefile(lines, 'XSmoothCursorMovedLine', 'D')
680 let buf = RunVimInTerminal('-S XSmoothCursorMovedLine', #{rows: 6})
681
682 call VerifyScreenDump(buf, 'Test_smooth_cursormoved_line', {})
683
684 call StopVimInTerminal(buf)
685endfunc
686
687func Test_smoothscroll_eob()
688 CheckScreendump
689
690 let lines =<< trim END
691 set smoothscroll
692 call setline(1, ['']->repeat(100))
693 norm G
694 END
695 call writefile(lines, 'XSmoothEob', 'D')
696 let buf = RunVimInTerminal('-S XSmoothEob', #{rows: 10})
697
698 " does not scroll halfway when scrolling to end of buffer
699 call VerifyScreenDump(buf, 'Test_smooth_eob_1', {})
700
701 " cursor is not placed below window
702 call term_sendkeys(buf, ":call setline(92, 'a'->repeat(100))\<CR>\<C-B>G")
703 call VerifyScreenDump(buf, 'Test_smooth_eob_2', {})
704
705 call StopVimInTerminal(buf)
706endfunc
707
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200708" vim: shiftwidth=2 sts=2 expandtab