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