blob: 0bdf6840b944e451c0d1741857b32072529b15f2 [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
429 exe "normal \<C-E>"
430 norm 3lgkh
431 call s:check_col_calc(3, 2, 23)
432 set virtualedit&
433
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000434 normal gg3l
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000435 exe "normal \<C-E>"
436
437 " Move down only 1 line when we are out of the range of the <<< display
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000438 call s:check_col_calc(4, 1, 24)
439 exe "normal \<C-Y>"
440 call s:check_col_calc(4, 2, 24)
441 normal ggg$
442 exe "normal \<C-E>"
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000443 call s:check_col_calc(20, 1, 40)
444 exe "normal \<C-Y>"
445 call s:check_col_calc(20, 2, 40)
446 normal gg
447
448 " Test number, where we have indented lines
449 setl number
450 call s:check_col_calc(5, 1, 1)
451 exe "normal \<C-E>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000452
453 " Move down only 1 line when the <<< display is on the number column
454 call s:check_col_calc(5, 1, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000455 exe "normal \<C-Y>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000456 call s:check_col_calc(5, 2, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000457 normal ggg$
458 exe "normal \<C-E>"
459 call s:check_col_calc(20, 1, 32)
460 exe "normal \<C-Y>"
461 call s:check_col_calc(20, 2, 32)
462 normal gg
463
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000464 setl numberwidth=1
465
466 " Move down another line when numberwidth is too short to cover the whole
467 " <<< display
468 call s:check_col_calc(3, 1, 1)
469 exe "normal \<C-E>"
470 call s:check_col_calc(3, 2, 37)
471 exe "normal \<C-Y>"
472 call s:check_col_calc(3, 3, 37)
473 normal ggl
474
475 " Only move 1 line down when we are just past the <<< display
476 call s:check_col_calc(4, 1, 2)
477 exe "normal \<C-E>"
478 call s:check_col_calc(4, 1, 20)
479 exe "normal \<C-Y>"
480 call s:check_col_calc(4, 2, 20)
481 normal gg
482 setl numberwidth&
483
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000484 " Test number + showbreak, so test that the additional indentation works
485 setl number showbreak=+++
486 call s:check_col_calc(5, 1, 1)
487 exe "normal \<C-E>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000488 call s:check_col_calc(8, 1, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000489 exe "normal \<C-Y>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000490 call s:check_col_calc(8, 2, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000491 normal gg
492
493 " Test number + cpo+=n mode, where wrapped lines aren't indented
494 setl number cpo+=n showbreak=
495 call s:check_col_calc(5, 1, 1)
496 exe "normal \<C-E>"
497 call s:check_col_calc(1, 2, 37)
498 exe "normal \<C-Y>"
499 call s:check_col_calc(1, 3, 37)
500 normal gg
501
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000502 bwipe!
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000503endfunc
504
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000505func Test_smoothscroll_cursor_scrolloff()
506 call NewWindow(10, 20)
507 setl smoothscroll wrap
508 setl scrolloff=3
Bram Moolenaar94722c52023-01-28 19:19:03 +0000509
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000510 " 120 chars are 6 screen lines
511 call setline(1, "abcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRST")
512 call setline(2, "below")
513
514 call s:check_col_calc(1, 1, 1)
515
516 " CTRL-E shows "<<<DEFG...", cursor move four lines down
517 exe "normal \<C-E>"
518 call s:check_col_calc(1, 4, 81)
519
520 " cursor on start of second line, "gk" moves into first line, skipcol doesn't
521 " change
522 exe "normal G0gk"
523 call s:check_col_calc(1, 5, 101)
524
525 " move cursor left one window width worth, scrolls one screen line
526 exe "normal 20h"
527 call s:check_col_calc(1, 5, 81)
528
529 " move cursor left one window width worth, scrolls one screen line
530 exe "normal 20h"
531 call s:check_col_calc(1, 4, 61)
532
Bram Moolenaarb21b8e92022-12-03 18:35:07 +0000533 " cursor on last line, "gk" should not cause a scroll
534 set scrolloff=0
535 normal G0
536 call s:check_col_calc(1, 7, 1)
537 normal gk
538 call s:check_col_calc(1, 6, 101)
539
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000540 bwipe!
541endfunc
542
543
Yee Cheng Chine6392b12022-11-19 14:31:08 +0000544" Test that mouse picking is still accurate when we have smooth scrolled lines
545func Test_smoothscroll_mouse_pos()
546 CheckNotGui
547 CheckUnix
548
549 let save_mouse = &mouse
550 let save_term = &term
551 let save_ttymouse = &ttymouse
552 set mouse=a term=xterm ttymouse=xterm2
553
554 call NewWindow(10, 20)
555 setl smoothscroll wrap
556 " First line will wrap to 3 physical lines. 2nd/3rd lines are short lines.
557 call setline(1, ["abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", "line 2", "line 3"])
558
559 func s:check_mouse_click(row, col, buf_row, buf_col)
560 call MouseLeftClick(a:row, a:col)
561
562 call assert_equal(a:col, wincol())
563 call assert_equal(a:row, winline())
564 call assert_equal(a:buf_row, line('.'))
565 call assert_equal(a:buf_col, col('.'))
566 endfunc
567
568 " Check that clicking without scroll works first.
569 call s:check_mouse_click(3, 5, 1, 45)
570 call s:check_mouse_click(4, 1, 2, 1)
571 call s:check_mouse_click(4, 6, 2, 6)
572 call s:check_mouse_click(5, 1, 3, 1)
573 call s:check_mouse_click(5, 6, 3, 6)
574
575 " Smooth scroll, and checks that this didn't mess up mouse clicking
576 exe "normal \<C-E>"
577 call s:check_mouse_click(2, 5, 1, 45)
578 call s:check_mouse_click(3, 1, 2, 1)
579 call s:check_mouse_click(3, 6, 2, 6)
580 call s:check_mouse_click(4, 1, 3, 1)
581 call s:check_mouse_click(4, 6, 3, 6)
582
583 exe "normal \<C-E>"
584 call s:check_mouse_click(1, 5, 1, 45)
585 call s:check_mouse_click(2, 1, 2, 1)
586 call s:check_mouse_click(2, 6, 2, 6)
587 call s:check_mouse_click(3, 1, 3, 1)
588 call s:check_mouse_click(3, 6, 3, 6)
589
590 " Make a new first line 11 physical lines tall so it's taller than window
591 " height, to test overflow calculations with really long lines wrapping.
592 normal gg
593 call setline(1, "12345678901234567890"->repeat(11))
594 exe "normal 6\<C-E>"
595 call s:check_mouse_click(5, 1, 1, 201)
596 call s:check_mouse_click(6, 1, 2, 1)
597 call s:check_mouse_click(7, 1, 3, 1)
598
599 let &mouse = save_mouse
600 let &term = save_term
601 let &ttymouse = save_ttymouse
602endfunc
603
Bram Moolenaar870219c2023-01-26 14:14:43 +0000604" this was dividing by zero
Luuk van Baalc8502f92023-05-06 12:40:15 +0100605func Test_smoothscroll_zero_width()
Bram Moolenaar870219c2023-01-26 14:14:43 +0000606 CheckScreendump
607
608 let lines =<< trim END
609 winsize 0 0
610 vsplit
611 vsplit
612 vsplit
613 vsplit
614 vsplit
615 sil norm H
616 set wrap
617 set smoothscroll
618 set number
619 END
620 call writefile(lines, 'XSmoothScrollZero', 'D')
621 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 +0000622 call VerifyScreenDump(buf, 'Test_smoothscroll_zero_1', {})
623
624 call term_sendkeys(buf, ":sil norm \<C-V>\<C-W>\<C-V>\<C-N>\<CR>")
625 call VerifyScreenDump(buf, 'Test_smoothscroll_zero_2', {})
626
627 call StopVimInTerminal(buf)
628endfunc
629
Luuk van Baalc8502f92023-05-06 12:40:15 +0100630" this was unnecessarily inserting lines
631func Test_smoothscroll_ins_lines()
632 CheckScreendump
633
634 let lines =<< trim END
635 set wrap
636 set smoothscroll
637 set scrolloff=0
638 set conceallevel=2
639 call setline(1, [
640 \'line one' .. 'with lots of text in one line '->repeat(2),
641 \'line two',
642 \'line three',
643 \'line four',
644 \'line five'
645 \])
646 END
647 call writefile(lines, 'XSmoothScrollInsLines', 'D')
648 let buf = RunVimInTerminal('-S XSmoothScrollInsLines', #{rows: 6, cols: 40})
649
650 call term_sendkeys(buf, "\<C-E>gjgk")
651 call VerifyScreenDump(buf, 'Test_smooth_ins_lines', {})
652
653 call StopVimInTerminal(buf)
654endfunc
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100655
Luuk van Baal3ce8c382023-05-08 15:51:14 +0100656" this placed the cursor in the command line
657func Test_smoothscroll_cursormoved_line()
658 CheckScreendump
659
660 let lines =<< trim END
661 set smoothscroll
662 call setline(1, [
663 \'',
664 \'_'->repeat(&lines * &columns),
665 \(('_')->repeat(&columns - 2) .. 'xxx')->repeat(2)
666 \])
667 autocmd CursorMoved * eval [line('w0'), line('w$')]
668 call search('xxx')
669 END
670 call writefile(lines, 'XSmoothCursorMovedLine', 'D')
671 let buf = RunVimInTerminal('-S XSmoothCursorMovedLine', #{rows: 6})
672
673 call VerifyScreenDump(buf, 'Test_smooth_cursormoved_line', {})
674
675 call StopVimInTerminal(buf)
676endfunc
677
678func Test_smoothscroll_eob()
679 CheckScreendump
680
681 let lines =<< trim END
682 set smoothscroll
683 call setline(1, ['']->repeat(100))
684 norm G
685 END
686 call writefile(lines, 'XSmoothEob', 'D')
687 let buf = RunVimInTerminal('-S XSmoothEob', #{rows: 10})
688
689 " does not scroll halfway when scrolling to end of buffer
690 call VerifyScreenDump(buf, 'Test_smooth_eob_1', {})
691
692 " cursor is not placed below window
693 call term_sendkeys(buf, ":call setline(92, 'a'->repeat(100))\<CR>\<C-B>G")
694 call VerifyScreenDump(buf, 'Test_smooth_eob_2', {})
695
696 call StopVimInTerminal(buf)
697endfunc
698
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200699" vim: shiftwidth=2 sts=2 expandtab