blob: 3806486bf654275845219c2a5825d1631a759eca [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
Luuk van Baald49f6462023-05-19 14:04:47 +0100260 call term_sendkeys(buf, "4\<C-Y>G")
261 call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {})
262
263 " moving cursor up right after the <<< marker - no need to show whole line
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000264 call term_sendkeys(buf, "2gj3l2k")
Bram Moolenaar46b54742022-10-06 15:46:49 +0100265 call VerifyScreenDump(buf, 'Test_smooth_wrap_5', {})
266
Luuk van Baald49f6462023-05-19 14:04:47 +0100267 " moving cursor up where the <<< marker is - whole top line shows
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000268 call term_sendkeys(buf, "2j02k")
269 call VerifyScreenDump(buf, 'Test_smooth_wrap_6', {})
270
Bram Moolenaar9bab7a02022-10-06 14:57:53 +0100271 call StopVimInTerminal(buf)
272endfunc
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100273
Bram Moolenaar8cf34592022-10-08 21:13:40 +0100274func Test_smoothscroll_wrap_long_line()
275 CheckScreendump
276
277 let lines =<< trim END
278 vim9script
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000279 setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(30)) .. ' end', 'four'])
Bram Moolenaar8cf34592022-10-08 21:13:40 +0100280 set smoothscroll scrolloff=0
281 normal 3G10|zt
282 END
283 call writefile(lines, 'XSmoothWrap', 'D')
284 let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 6, cols: 40})
285 call VerifyScreenDump(buf, 'Test_smooth_long_1', {})
286
287 " scrolling up, cursor moves screen line down
288 call term_sendkeys(buf, "\<C-E>")
289 call VerifyScreenDump(buf, 'Test_smooth_long_2', {})
290 call term_sendkeys(buf, "5\<C-E>")
291 call VerifyScreenDump(buf, 'Test_smooth_long_3', {})
292
293 " scrolling down, cursor moves screen line up
294 call term_sendkeys(buf, "5\<C-Y>")
295 call VerifyScreenDump(buf, 'Test_smooth_long_4', {})
296 call term_sendkeys(buf, "\<C-Y>")
297 call VerifyScreenDump(buf, 'Test_smooth_long_5', {})
298
Bram Moolenaar118c2352022-10-09 17:19:27 +0100299 " 'scrolloff' set to 1, scrolling up, cursor moves screen line down
300 call term_sendkeys(buf, ":set scrolloff=1\<CR>")
301 call term_sendkeys(buf, "10|\<C-E>")
302 call VerifyScreenDump(buf, 'Test_smooth_long_6', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000303
Bram Moolenaar118c2352022-10-09 17:19:27 +0100304 " 'scrolloff' set to 1, scrolling down, cursor moves screen line up
305 call term_sendkeys(buf, "\<C-E>")
306 call term_sendkeys(buf, "gjgj")
307 call term_sendkeys(buf, "\<C-Y>")
308 call VerifyScreenDump(buf, 'Test_smooth_long_7', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000309
Bram Moolenaar118c2352022-10-09 17:19:27 +0100310 " 'scrolloff' set to 2, scrolling up, cursor moves screen line down
311 call term_sendkeys(buf, ":set scrolloff=2\<CR>")
312 call term_sendkeys(buf, "10|\<C-E>")
313 call VerifyScreenDump(buf, 'Test_smooth_long_8', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000314
Bram Moolenaar118c2352022-10-09 17:19:27 +0100315 " 'scrolloff' set to 2, scrolling down, cursor moves screen line up
316 call term_sendkeys(buf, "\<C-E>")
317 call term_sendkeys(buf, "gj")
318 call term_sendkeys(buf, "\<C-Y>")
319 call VerifyScreenDump(buf, 'Test_smooth_long_9', {})
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000320
321 " 'scrolloff' set to 0, move cursor down one line.
322 " Cursor should move properly, and since this is a really long line, it will
323 " be put on top of the screen.
324 call term_sendkeys(buf, ":set scrolloff=0\<CR>")
325 call term_sendkeys(buf, "0j")
326 call VerifyScreenDump(buf, 'Test_smooth_long_10', {})
327
Bram Moolenaardb4d88c2022-12-31 15:13:22 +0000328 " Test zt/zz/zb that they work properly when a long line is above it
Luuk van Baal6f37e532023-05-09 21:23:54 +0100329 call term_sendkeys(buf, "zt")
Bram Moolenaardb4d88c2022-12-31 15:13:22 +0000330 call VerifyScreenDump(buf, 'Test_smooth_long_11', {})
331 call term_sendkeys(buf, "zz")
332 call VerifyScreenDump(buf, 'Test_smooth_long_12', {})
Luuk van Baal6f37e532023-05-09 21:23:54 +0100333 call term_sendkeys(buf, "zb")
Bram Moolenaardb4d88c2022-12-31 15:13:22 +0000334 call VerifyScreenDump(buf, 'Test_smooth_long_13', {})
335
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000336 " Repeat the step and move the cursor down again.
337 " This time, use a shorter long line that is barely long enough to span more
338 " than one window. Note that the cursor is at the bottom this time because
339 " Vim prefers to do so if we are scrolling a few lines only.
340 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 +0100341 " Currently visible lines were replaced, test that the lines and cursor
342 " are correctly displayed.
343 call VerifyScreenDump(buf, 'Test_smooth_long_14', {})
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000344 call term_sendkeys(buf, "3Gzt")
345 call term_sendkeys(buf, "j")
Luuk van Baal5d01f862023-05-11 19:24:20 +0100346 call VerifyScreenDump(buf, 'Test_smooth_long_15', {})
Yee Cheng Chin361895d2022-11-19 12:25:16 +0000347
348 " Repeat the step but this time start it when the line is smooth-scrolled by
349 " one line. This tests that the offset calculation is still correct and
350 " still end up scrolling down to the next line with cursor at bottom of
351 " screen.
352 call term_sendkeys(buf, "3Gzt")
353 call term_sendkeys(buf, "\<C-E>j")
Luuk van Baal5d01f862023-05-11 19:24:20 +0100354 call VerifyScreenDump(buf, 'Test_smooth_long_16', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000355
Bram Moolenaar8cf34592022-10-08 21:13:40 +0100356 call StopVimInTerminal(buf)
357endfunc
358
Bram Moolenaar2fbabd22022-10-12 19:53:38 +0100359func Test_smoothscroll_one_long_line()
360 CheckScreendump
361
362 let lines =<< trim END
363 vim9script
364 setline(1, 'with lots of text '->repeat(7))
365 set smoothscroll scrolloff=0
366 END
367 call writefile(lines, 'XSmoothOneLong', 'D')
368 let buf = RunVimInTerminal('-S XSmoothOneLong', #{rows: 6, cols: 40})
369 call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000370
Bram Moolenaar2fbabd22022-10-12 19:53:38 +0100371 call term_sendkeys(buf, "\<C-E>")
372 call VerifyScreenDump(buf, 'Test_smooth_one_long_2', {})
373
374 call term_sendkeys(buf, "0")
375 call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {})
376
377 call StopVimInTerminal(buf)
378endfunc
379
Bram Moolenaar75ac25b2022-11-17 19:00:14 +0000380func Test_smoothscroll_long_line_showbreak()
381 CheckScreendump
382
383 let lines =<< trim END
384 vim9script
385 # a line that spans four screen lines
386 setline(1, 'with lots of text in one line '->repeat(6))
387 set smoothscroll scrolloff=0 showbreak=+++\
388 END
389 call writefile(lines, 'XSmoothLongShowbreak', 'D')
390 let buf = RunVimInTerminal('-S XSmoothLongShowbreak', #{rows: 6, cols: 40})
391 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_1', {})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000392
Bram Moolenaar75ac25b2022-11-17 19:00:14 +0000393 call term_sendkeys(buf, "\<C-E>")
394 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_2', {})
395
396 call term_sendkeys(buf, "0")
397 call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_1', {})
398
399 call StopVimInTerminal(buf)
400endfunc
401
zeertzjqecb87dd2023-06-03 19:45:06 +0100402" Check that 'smoothscroll' marker is drawn over double-width char correctly.
403" Run with multiple encodings.
404func Test_smoothscroll_marker_over_double_width()
405 " Run this in a separate Vim instance to avoid messing up.
406 let after =<< trim [CODE]
407 scriptencoding utf-8
408 call setline(1, 'a'->repeat(&columns) .. '口'->repeat(10))
409 setlocal smoothscroll
410 redraw
411 exe "norm \<C-E>"
412 redraw
413 " Check the chars one by one. Don't check the whole line concatenated.
414 call assert_equal('<', screenstring(1, 1))
415 call assert_equal('<', screenstring(1, 2))
416 call assert_equal('<', screenstring(1, 3))
417 call assert_equal(' ', screenstring(1, 4))
418 call assert_equal('', screenstring(1, 5))
419 call assert_equal('', screenstring(1, 7))
420 call assert_equal('', screenstring(1, 9))
421 call assert_equal('', screenstring(1, 11))
422 call assert_equal('', screenstring(1, 13))
423 call assert_equal('', screenstring(1, 15))
424 call writefile(v:errors, 'Xresult')
425 qall!
426 [CODE]
427
428 let encodings = ['utf-8', 'cp932', 'cp936', 'cp949', 'cp950']
429 if !has('win32')
430 let encodings += ['euc-jp']
431 endif
432 for enc in encodings
433 let msg = 'enc=' .. enc
434 if RunVim([], after, $'--clean --cmd "set encoding={enc}"')
435 call assert_equal([], readfile('Xresult'), msg)
436 endif
437 call delete('Xresult')
438 endfor
439endfunc
440
441" Same as the test above, but check the text actually shown on screen.
442" Only run with UTF-8 encoding.
443func Test_smoothscroll_marker_over_double_width_dump()
444 CheckScreendump
445
446 let lines =<< trim END
447 call setline(1, 'a'->repeat(&columns) .. ''->repeat(10))
448 setlocal smoothscroll
449 END
450 call writefile(lines, 'XSmoothMarkerOverDoubleWidth', 'D')
451 let buf = RunVimInTerminal('-S XSmoothMarkerOverDoubleWidth', #{rows: 6, cols: 40})
452 call VerifyScreenDump(buf, 'Test_smooth_marker_over_double_width_1', {})
453
454 call term_sendkeys(buf, "\<C-E>")
455 call VerifyScreenDump(buf, 'Test_smooth_marker_over_double_width_2', {})
456
457 call StopVimInTerminal(buf)
458endfunc
459
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000460func s:check_col_calc(win_col, win_line, buf_col)
461 call assert_equal(a:win_col, wincol())
462 call assert_equal(a:win_line, winline())
463 call assert_equal(a:buf_col, col('.'))
464endfunc
465
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000466" Test that if the current cursor is on a smooth scrolled line, we correctly
467" reposition it. Also check that we don't miscalculate the values by checking
468" the consistency between wincol() and col('.') as they are calculated
469" separately in code.
470func Test_smoothscroll_cursor_position()
471 call NewWindow(10, 20)
472 setl smoothscroll wrap
473 call setline(1, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
474
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000475 call s:check_col_calc(1, 1, 1)
476 exe "normal \<C-E>"
477
478 " Move down another line to avoid blocking the <<< display
479 call s:check_col_calc(1, 2, 41)
480 exe "normal \<C-Y>"
481 call s:check_col_calc(1, 3, 41)
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000482
Luuk van Baal8667a562023-05-12 15:47:25 +0100483 " Test "g0/g<Home>"
484 exe "normal gg\<C-E>"
485 norm $gkg0
486 call s:check_col_calc(1, 2, 21)
487
488 " Test moving the cursor behind the <<< display with 'virtualedit'
489 set virtualedit=all
Luuk van Baal24b62ec2023-05-13 14:12:15 +0100490 exe "normal \<C-E>3lgkh"
Luuk van Baal8667a562023-05-12 15:47:25 +0100491 call s:check_col_calc(3, 2, 23)
492 set virtualedit&
493
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000494 normal gg3l
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000495 exe "normal \<C-E>"
496
497 " Move down only 1 line when we are out of the range of the <<< display
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000498 call s:check_col_calc(4, 1, 24)
499 exe "normal \<C-Y>"
500 call s:check_col_calc(4, 2, 24)
501 normal ggg$
502 exe "normal \<C-E>"
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000503 call s:check_col_calc(20, 1, 40)
504 exe "normal \<C-Y>"
505 call s:check_col_calc(20, 2, 40)
506 normal gg
507
508 " Test number, where we have indented lines
509 setl number
510 call s:check_col_calc(5, 1, 1)
511 exe "normal \<C-E>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000512
513 " Move down only 1 line when the <<< display is on the number column
514 call s:check_col_calc(5, 1, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000515 exe "normal \<C-Y>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000516 call s:check_col_calc(5, 2, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000517 normal ggg$
518 exe "normal \<C-E>"
519 call s:check_col_calc(20, 1, 32)
520 exe "normal \<C-Y>"
521 call s:check_col_calc(20, 2, 32)
522 normal gg
523
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000524 setl numberwidth=1
525
526 " Move down another line when numberwidth is too short to cover the whole
527 " <<< display
528 call s:check_col_calc(3, 1, 1)
529 exe "normal \<C-E>"
530 call s:check_col_calc(3, 2, 37)
531 exe "normal \<C-Y>"
532 call s:check_col_calc(3, 3, 37)
533 normal ggl
534
535 " Only move 1 line down when we are just past the <<< display
536 call s:check_col_calc(4, 1, 2)
537 exe "normal \<C-E>"
538 call s:check_col_calc(4, 1, 20)
539 exe "normal \<C-Y>"
540 call s:check_col_calc(4, 2, 20)
541 normal gg
542 setl numberwidth&
543
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000544 " Test number + showbreak, so test that the additional indentation works
545 setl number showbreak=+++
546 call s:check_col_calc(5, 1, 1)
547 exe "normal \<C-E>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000548 call s:check_col_calc(8, 1, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000549 exe "normal \<C-Y>"
Yee Cheng Chin81ba26e2022-11-18 12:52:50 +0000550 call s:check_col_calc(8, 2, 17)
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000551 normal gg
552
553 " Test number + cpo+=n mode, where wrapped lines aren't indented
554 setl number cpo+=n showbreak=
555 call s:check_col_calc(5, 1, 1)
556 exe "normal \<C-E>"
557 call s:check_col_calc(1, 2, 37)
558 exe "normal \<C-Y>"
559 call s:check_col_calc(1, 3, 37)
560 normal gg
561
Luuk van Baal24b62ec2023-05-13 14:12:15 +0100562 " Test list + listchars "precedes", where there is always 1 overlap
563 " regardless of number and cpo-=n.
564 setl number list listchars=precedes:< cpo-=n
565 call s:check_col_calc(5, 1, 1)
Luuk van Baal798fa762023-05-15 18:17:43 +0100566 exe "normal 3|\<C-E>h"
Luuk van Baal24b62ec2023-05-13 14:12:15 +0100567 call s:check_col_calc(6, 1, 18)
568 norm h
569 call s:check_col_calc(5, 2, 17)
570 normal gg
571
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000572 bwipe!
Yee Cheng Chin01ee52b2022-11-17 12:41:42 +0000573endfunc
574
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000575func Test_smoothscroll_cursor_scrolloff()
576 call NewWindow(10, 20)
577 setl smoothscroll wrap
578 setl scrolloff=3
Bram Moolenaar94722c52023-01-28 19:19:03 +0000579
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000580 " 120 chars are 6 screen lines
581 call setline(1, "abcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRST")
582 call setline(2, "below")
583
584 call s:check_col_calc(1, 1, 1)
585
586 " CTRL-E shows "<<<DEFG...", cursor move four lines down
587 exe "normal \<C-E>"
588 call s:check_col_calc(1, 4, 81)
589
590 " cursor on start of second line, "gk" moves into first line, skipcol doesn't
591 " change
592 exe "normal G0gk"
593 call s:check_col_calc(1, 5, 101)
594
595 " move cursor left one window width worth, scrolls one screen line
596 exe "normal 20h"
597 call s:check_col_calc(1, 5, 81)
598
599 " move cursor left one window width worth, scrolls one screen line
600 exe "normal 20h"
601 call s:check_col_calc(1, 4, 61)
602
Bram Moolenaarb21b8e92022-12-03 18:35:07 +0000603 " cursor on last line, "gk" should not cause a scroll
604 set scrolloff=0
605 normal G0
606 call s:check_col_calc(1, 7, 1)
607 normal gk
608 call s:check_col_calc(1, 6, 101)
609
Bram Moolenaar1b73edd2022-12-03 11:51:54 +0000610 bwipe!
611endfunc
612
613
Yee Cheng Chine6392b12022-11-19 14:31:08 +0000614" Test that mouse picking is still accurate when we have smooth scrolled lines
615func Test_smoothscroll_mouse_pos()
616 CheckNotGui
617 CheckUnix
618
619 let save_mouse = &mouse
620 let save_term = &term
621 let save_ttymouse = &ttymouse
622 set mouse=a term=xterm ttymouse=xterm2
623
624 call NewWindow(10, 20)
625 setl smoothscroll wrap
626 " First line will wrap to 3 physical lines. 2nd/3rd lines are short lines.
627 call setline(1, ["abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", "line 2", "line 3"])
628
629 func s:check_mouse_click(row, col, buf_row, buf_col)
630 call MouseLeftClick(a:row, a:col)
631
632 call assert_equal(a:col, wincol())
633 call assert_equal(a:row, winline())
634 call assert_equal(a:buf_row, line('.'))
635 call assert_equal(a:buf_col, col('.'))
636 endfunc
637
638 " Check that clicking without scroll works first.
639 call s:check_mouse_click(3, 5, 1, 45)
640 call s:check_mouse_click(4, 1, 2, 1)
641 call s:check_mouse_click(4, 6, 2, 6)
642 call s:check_mouse_click(5, 1, 3, 1)
643 call s:check_mouse_click(5, 6, 3, 6)
644
645 " Smooth scroll, and checks that this didn't mess up mouse clicking
646 exe "normal \<C-E>"
647 call s:check_mouse_click(2, 5, 1, 45)
648 call s:check_mouse_click(3, 1, 2, 1)
649 call s:check_mouse_click(3, 6, 2, 6)
650 call s:check_mouse_click(4, 1, 3, 1)
651 call s:check_mouse_click(4, 6, 3, 6)
652
653 exe "normal \<C-E>"
654 call s:check_mouse_click(1, 5, 1, 45)
655 call s:check_mouse_click(2, 1, 2, 1)
656 call s:check_mouse_click(2, 6, 2, 6)
657 call s:check_mouse_click(3, 1, 3, 1)
658 call s:check_mouse_click(3, 6, 3, 6)
659
660 " Make a new first line 11 physical lines tall so it's taller than window
661 " height, to test overflow calculations with really long lines wrapping.
662 normal gg
663 call setline(1, "12345678901234567890"->repeat(11))
664 exe "normal 6\<C-E>"
665 call s:check_mouse_click(5, 1, 1, 201)
666 call s:check_mouse_click(6, 1, 2, 1)
667 call s:check_mouse_click(7, 1, 3, 1)
668
669 let &mouse = save_mouse
670 let &term = save_term
671 let &ttymouse = save_ttymouse
672endfunc
673
Bram Moolenaar870219c2023-01-26 14:14:43 +0000674" this was dividing by zero
Luuk van Baalc8502f92023-05-06 12:40:15 +0100675func Test_smoothscroll_zero_width()
Bram Moolenaar870219c2023-01-26 14:14:43 +0000676 CheckScreendump
677
678 let lines =<< trim END
679 winsize 0 0
680 vsplit
681 vsplit
682 vsplit
683 vsplit
684 vsplit
685 sil norm H
686 set wrap
687 set smoothscroll
688 set number
689 END
690 call writefile(lines, 'XSmoothScrollZero', 'D')
691 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 +0000692 call VerifyScreenDump(buf, 'Test_smoothscroll_zero_1', {})
693
694 call term_sendkeys(buf, ":sil norm \<C-V>\<C-W>\<C-V>\<C-N>\<CR>")
695 call VerifyScreenDump(buf, 'Test_smoothscroll_zero_2', {})
696
697 call StopVimInTerminal(buf)
698endfunc
699
Luuk van Baalc8502f92023-05-06 12:40:15 +0100700" this was unnecessarily inserting lines
701func Test_smoothscroll_ins_lines()
702 CheckScreendump
703
704 let lines =<< trim END
705 set wrap
706 set smoothscroll
707 set scrolloff=0
708 set conceallevel=2
709 call setline(1, [
710 \'line one' .. 'with lots of text in one line '->repeat(2),
711 \'line two',
712 \'line three',
713 \'line four',
714 \'line five'
715 \])
716 END
717 call writefile(lines, 'XSmoothScrollInsLines', 'D')
718 let buf = RunVimInTerminal('-S XSmoothScrollInsLines', #{rows: 6, cols: 40})
719
720 call term_sendkeys(buf, "\<C-E>gjgk")
721 call VerifyScreenDump(buf, 'Test_smooth_ins_lines', {})
722
723 call StopVimInTerminal(buf)
724endfunc
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100725
Luuk van Baal3ce8c382023-05-08 15:51:14 +0100726" this placed the cursor in the command line
727func Test_smoothscroll_cursormoved_line()
728 CheckScreendump
729
730 let lines =<< trim END
731 set smoothscroll
732 call setline(1, [
733 \'',
734 \'_'->repeat(&lines * &columns),
735 \(('_')->repeat(&columns - 2) .. 'xxx')->repeat(2)
736 \])
737 autocmd CursorMoved * eval [line('w0'), line('w$')]
738 call search('xxx')
739 END
740 call writefile(lines, 'XSmoothCursorMovedLine', 'D')
741 let buf = RunVimInTerminal('-S XSmoothCursorMovedLine', #{rows: 6})
742
743 call VerifyScreenDump(buf, 'Test_smooth_cursormoved_line', {})
744
745 call StopVimInTerminal(buf)
746endfunc
747
748func Test_smoothscroll_eob()
749 CheckScreendump
750
751 let lines =<< trim END
752 set smoothscroll
753 call setline(1, ['']->repeat(100))
754 norm G
755 END
756 call writefile(lines, 'XSmoothEob', 'D')
757 let buf = RunVimInTerminal('-S XSmoothEob', #{rows: 10})
758
759 " does not scroll halfway when scrolling to end of buffer
760 call VerifyScreenDump(buf, 'Test_smooth_eob_1', {})
761
762 " cursor is not placed below window
763 call term_sendkeys(buf, ":call setline(92, 'a'->repeat(100))\<CR>\<C-B>G")
764 call VerifyScreenDump(buf, 'Test_smooth_eob_2', {})
765
766 call StopVimInTerminal(buf)
767endfunc
768
Luuk van Baald49f6462023-05-19 14:04:47 +0100769" skipcol should not reset when doing incremental search on the same word
770func Test_smoothscroll_incsearch()
771 CheckScreendump
772
773 let lines =<< trim END
774 set smoothscroll number scrolloff=0 incsearch
775 call setline(1, repeat([''], 20))
776 call setline(11, repeat('a', 100))
777 call setline(14, 'bbbb')
778 END
779 call writefile(lines, 'XSmoothIncsearch', 'D')
zeertzjq3c802272023-06-03 22:08:33 +0100780 let buf = RunVimInTerminal('-S XSmoothIncsearch', #{rows: 8, cols: 40})
Luuk van Baald49f6462023-05-19 14:04:47 +0100781
782 call term_sendkeys(buf, "/b")
783 call VerifyScreenDump(buf, 'Test_smooth_incsearch_1', {})
784 call term_sendkeys(buf, "b")
785 call VerifyScreenDump(buf, 'Test_smooth_incsearch_2', {})
786 call term_sendkeys(buf, "b")
787 call VerifyScreenDump(buf, 'Test_smooth_incsearch_3', {})
788 call term_sendkeys(buf, "b")
789 call VerifyScreenDump(buf, 'Test_smooth_incsearch_4', {})
790 call term_sendkeys(buf, "\<CR>")
791
792 call StopVimInTerminal(buf)
793endfunc
794
zeertzjq3c802272023-06-03 22:08:33 +0100795" Test scrolling multiple lines and stopping at non-zero skipcol.
796func Test_smoothscroll_multi_skipcol()
797 CheckScreendump
798
799 let lines =<< trim END
800 setlocal cursorline scrolloff=0 smoothscroll
801 call setline(1, repeat([''], 9))
802 call setline(3, repeat('a', 50))
803 call setline(8, 'bbb')
804 call setline(9, 'ccc')
805 redraw
806 END
807 call writefile(lines, 'XSmoothMultiSkipcol', 'D')
808 let buf = RunVimInTerminal('-S XSmoothMultiSkipcol', #{rows: 10, cols: 40})
809 call VerifyScreenDump(buf, 'Test_smooth_multi_skipcol_1', {})
810
811 call term_sendkeys(buf, "3\<C-E>")
812 call VerifyScreenDump(buf, 'Test_smooth_multi_skipcol_2', {})
813
814 call StopVimInTerminal(buf)
815endfunc
816
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200817" vim: shiftwidth=2 sts=2 expandtab