blob: a497d0e39391c29c2dec9671a9498c3f6ee99321 [file] [log] [blame]
Bram Moolenaar410e98a2019-09-09 22:05:49 +02001" Test for cursorline and cursorlineopt
Bram Moolenaar017ba072019-09-14 21:01:23 +02002
Bram Moolenaar017ba072019-09-14 21:01:23 +02003source screendump.vim
Bram Moolenaar410e98a2019-09-09 22:05:49 +02004
Bram Moolenaar97f0eb12022-10-06 19:49:13 +01005func s:screen_attr(lnum) abort
Bram Moolenaar410e98a2019-09-09 22:05:49 +02006 return map(range(1, 8), 'screenattr(a:lnum, v:val)')
Bram Moolenaar97f0eb12022-10-06 19:49:13 +01007endfunc
Bram Moolenaar410e98a2019-09-09 22:05:49 +02008
Bram Moolenaar97f0eb12022-10-06 19:49:13 +01009func s:test_windows(h, w) abort
Bram Moolenaar410e98a2019-09-09 22:05:49 +020010 call NewWindow(a:h, a:w)
Bram Moolenaar97f0eb12022-10-06 19:49:13 +010011endfunc
Bram Moolenaar410e98a2019-09-09 22:05:49 +020012
Bram Moolenaar97f0eb12022-10-06 19:49:13 +010013func s:close_windows() abort
Bram Moolenaar410e98a2019-09-09 22:05:49 +020014 call CloseWindow()
Bram Moolenaar97f0eb12022-10-06 19:49:13 +010015endfunc
Bram Moolenaar410e98a2019-09-09 22:05:49 +020016
Bram Moolenaar97f0eb12022-10-06 19:49:13 +010017func s:new_hi() abort
Bram Moolenaar410e98a2019-09-09 22:05:49 +020018 redir => save_hi
19 silent! hi CursorLineNr
20 redir END
21 let save_hi = join(split(substitute(save_hi, '\s*xxx\s*', ' ', ''), "\n"), '')
22 exe 'hi' save_hi 'ctermbg=0 guibg=Black'
23 return save_hi
Bram Moolenaar97f0eb12022-10-06 19:49:13 +010024endfunc
Bram Moolenaar410e98a2019-09-09 22:05:49 +020025
26func Test_cursorline_highlight1()
27 let save_hi = s:new_hi()
28 try
29 call s:test_windows(10, 20)
30 call setline(1, repeat(['aaaa'], 10))
31 redraw
32 let attr01 = s:screen_attr(1)
33 call assert_equal(repeat([attr01[0]], 8), attr01)
34
35 setl number numberwidth=4
36 redraw
37 let attr11 = s:screen_attr(1)
38 call assert_equal(repeat([attr11[0]], 4), attr11[0:3])
39 call assert_equal(repeat([attr11[4]], 4), attr11[4:7])
40 call assert_notequal(attr11[0], attr11[4])
41
42 setl cursorline
43 redraw
44 let attr21 = s:screen_attr(1)
45 let attr22 = s:screen_attr(2)
46 call assert_equal(repeat([attr21[0]], 4), attr21[0:3])
47 call assert_equal(repeat([attr21[4]], 4), attr21[4:7])
48 call assert_equal(attr11, attr22)
49 call assert_notequal(attr22, attr21)
50
51 setl nocursorline relativenumber
52 redraw
53 let attr31 = s:screen_attr(1)
Bram Moolenaar49474ca2019-10-05 21:57:12 +020054 call assert_equal(attr22[0:3], attr31[0:3])
Bram Moolenaar410e98a2019-09-09 22:05:49 +020055 call assert_equal(attr11[4:7], attr31[4:7])
56
57 call s:close_windows()
58 finally
59 exe 'hi' save_hi
60 endtry
61endfunc
62
63func Test_cursorline_highlight2()
64 CheckOption cursorlineopt
65
66 let save_hi = s:new_hi()
67 try
68 call s:test_windows(10, 20)
69 call setline(1, repeat(['aaaa'], 10))
70 redraw
71 let attr0 = s:screen_attr(1)
72 call assert_equal(repeat([attr0[0]], 8), attr0)
73
74 setl number
75 redraw
76 let attr1 = s:screen_attr(1)
77 call assert_notequal(attr0[0:3], attr1[0:3])
78 call assert_equal(attr0[0:3], attr1[4:7])
79
80 setl cursorline cursorlineopt=both
81 redraw
82 let attr2 = s:screen_attr(1)
83 call assert_notequal(attr1[0:3], attr2[0:3])
84 call assert_notequal(attr1[4:7], attr2[4:7])
85
86 setl cursorlineopt=line
87 redraw
88 let attr3 = s:screen_attr(1)
89 call assert_equal(attr1[0:3], attr3[0:3])
90 call assert_equal(attr2[4:7], attr3[4:7])
91
92 setl cursorlineopt=number
93 redraw
94 let attr4 = s:screen_attr(1)
95 call assert_equal(attr2[0:3], attr4[0:3])
96 call assert_equal(attr1[4:7], attr4[4:7])
97
98 setl nonumber
99 redraw
100 let attr5 = s:screen_attr(1)
101 call assert_equal(attr0, attr5)
102
103 call s:close_windows()
104 finally
105 exe 'hi' save_hi
106 endtry
107endfunc
Bram Moolenaar017ba072019-09-14 21:01:23 +0200108
109func Test_cursorline_screenline()
110 CheckScreendump
111 CheckOption cursorlineopt
Bram Moolenaarc9e7e342021-07-22 21:33:03 +0200112
Bram Moolenaar017ba072019-09-14 21:01:23 +0200113 let filename='Xcursorline'
114 let lines = []
115
116 let file_content =<< trim END
117 1 foooooooo ar eins‍zwei drei vier fünf sechs sieben acht un zehn elf zwöfl dreizehn v ierzehn fünfzehn
118 2 foooooooo bar eins zwei drei vier fünf sechs sieben
119 3 foooooooo bar eins zwei drei vier fünf sechs sieben
120 4 foooooooo bar eins zwei drei vier fünf sechs sieben
121 END
122 let lines1 =<< trim END1
123 set nocp
124 set display=lastline
125 set cursorlineopt=screenline cursorline nu wrap sbr=>
126 hi CursorLineNr ctermfg=blue
127 25vsp
128 END1
129 let lines2 =<< trim END2
130 call cursor(1,1)
131 END2
132 call extend(lines, lines1)
133 call extend(lines, ["call append(0, ".. string(file_content).. ')'])
134 call extend(lines, lines2)
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100135 call writefile(lines, filename, 'D')
Bram Moolenaar017ba072019-09-14 21:01:23 +0200136 " basic test
137 let buf = RunVimInTerminal('-S '. filename, #{rows: 20})
Bram Moolenaar017ba072019-09-14 21:01:23 +0200138 call VerifyScreenDump(buf, 'Test_'. filename. '_1', {})
139 call term_sendkeys(buf, "fagj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200140 call VerifyScreenDump(buf, 'Test_'. filename. '_2', {})
141 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200142 call VerifyScreenDump(buf, 'Test_'. filename. '_3', {})
143 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200144 call VerifyScreenDump(buf, 'Test_'. filename. '_4', {})
145 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200146 call VerifyScreenDump(buf, 'Test_'. filename. '_5', {})
147 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200148 call VerifyScreenDump(buf, 'Test_'. filename. '_6', {})
149 " test with set list and cursorlineopt containing number
150 call term_sendkeys(buf, "gg0")
151 call term_sendkeys(buf, ":set list cursorlineopt+=number listchars=space:-\<cr>")
152 call VerifyScreenDump(buf, 'Test_'. filename. '_7', {})
153 call term_sendkeys(buf, "fagj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200154 call VerifyScreenDump(buf, 'Test_'. filename. '_8', {})
155 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200156 call VerifyScreenDump(buf, 'Test_'. filename. '_9', {})
157 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200158 call VerifyScreenDump(buf, 'Test_'. filename. '_10', {})
159 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200160 call VerifyScreenDump(buf, 'Test_'. filename. '_11', {})
161 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200162 call VerifyScreenDump(buf, 'Test_'. filename. '_12', {})
163 if exists("+foldcolumn") && exists("+signcolumn") && exists("+breakindent")
Dominique Pelle81b573d2022-03-22 21:14:55 +0000164 " test with set foldcolumn signcolumn and breakindent
Bram Moolenaar017ba072019-09-14 21:01:23 +0200165 call term_sendkeys(buf, "gg0")
166 call term_sendkeys(buf, ":set breakindent foldcolumn=2 signcolumn=yes\<cr>")
167 call VerifyScreenDump(buf, 'Test_'. filename. '_13', {})
168 call term_sendkeys(buf, "fagj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200169 call VerifyScreenDump(buf, 'Test_'. filename. '_14', {})
170 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200171 call VerifyScreenDump(buf, 'Test_'. filename. '_15', {})
172 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200173 call VerifyScreenDump(buf, 'Test_'. filename. '_16', {})
174 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200175 call VerifyScreenDump(buf, 'Test_'. filename. '_17', {})
176 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200177 call VerifyScreenDump(buf, 'Test_'. filename. '_18', {})
zeertzjq4f33bc22021-08-05 17:57:02 +0200178 call term_sendkeys(buf, ":set breakindent& foldcolumn& signcolumn&\<cr>")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200179 endif
zeertzjq4f33bc22021-08-05 17:57:02 +0200180 " showbreak should not be highlighted with CursorLine when 'number' is off
181 call term_sendkeys(buf, "gg0")
182 call term_sendkeys(buf, ":set list cursorlineopt=screenline listchars=space:-\<cr>")
183 call term_sendkeys(buf, ":set nonumber\<cr>")
184 call VerifyScreenDump(buf, 'Test_'. filename. '_19', {})
185 call term_sendkeys(buf, "fagj")
zeertzjq4f33bc22021-08-05 17:57:02 +0200186 call VerifyScreenDump(buf, 'Test_'. filename. '_20', {})
187 call term_sendkeys(buf, "gj")
zeertzjq4f33bc22021-08-05 17:57:02 +0200188 call VerifyScreenDump(buf, 'Test_'. filename. '_21', {})
189 call term_sendkeys(buf, "gj")
zeertzjq4f33bc22021-08-05 17:57:02 +0200190 call VerifyScreenDump(buf, 'Test_'. filename. '_22', {})
191 call term_sendkeys(buf, "gj")
zeertzjq4f33bc22021-08-05 17:57:02 +0200192 call VerifyScreenDump(buf, 'Test_'. filename. '_23', {})
193 call term_sendkeys(buf, "gj")
zeertzjq4f33bc22021-08-05 17:57:02 +0200194 call VerifyScreenDump(buf, 'Test_'. filename. '_24', {})
195 call term_sendkeys(buf, ":set list& cursorlineopt& listchars&\<cr>")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200196
197 call StopVimInTerminal(buf)
Bram Moolenaar017ba072019-09-14 21:01:23 +0200198endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200199
Bram Moolenaarc9e7e342021-07-22 21:33:03 +0200200func Test_cursorline_redraw()
201 CheckScreendump
202 CheckOption cursorlineopt
203
204 let textlines =<< END
205 When the option is a list of flags, {value} must be
206 exactly as they appear in the option. Remove flags
207 one by one to avoid problems.
208 Also see |:set-args| above.
209
210The {option} arguments to ":set" may be repeated. For example: >
211 :set ai nosi sw=3 ts=3
212If you make an error in one of the arguments, an error message will be given
213and the following arguments will be ignored.
214
215 *:set-verbose*
216When 'verbose' is non-zero, displaying an option value will also tell where it
217was last set. Example: >
218 :verbose set shiftwidth cindent?
219< shiftwidth=4 ~
220 Last set from modeline line 1 ~
221 cindent ~
222 Last set from /usr/local/share/vim/vim60/ftplugin/c.vim line 30 ~
223This is only done when specific option values are requested, not for ":verbose
224set all" or ":verbose set" without an argument.
225When the option was set by hand there is no "Last set" message.
226When the option was set while executing a function, user command or
227END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100228 call writefile(textlines, 'Xtextfile', 'D')
Bram Moolenaarc9e7e342021-07-22 21:33:03 +0200229
230 let script =<< trim END
231 set cursorline scrolloff=2
232 normal 12G
233 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100234 call writefile(script, 'Xscript', 'D')
Bram Moolenaarc9e7e342021-07-22 21:33:03 +0200235
236 let buf = RunVimInTerminal('-S Xscript Xtextfile', #{rows: 20, cols: 40})
237 call VerifyScreenDump(buf, 'Test_cursorline_redraw_1', {})
238 call term_sendkeys(buf, "zt")
239 call TermWait(buf)
240 call term_sendkeys(buf, "\<C-U>")
241 call VerifyScreenDump(buf, 'Test_cursorline_redraw_2', {})
242
243 call StopVimInTerminal(buf)
Bram Moolenaarc9e7e342021-07-22 21:33:03 +0200244endfunc
245
Bram Moolenaare7a74d52022-03-19 11:10:15 +0000246func Test_cursorline_callback()
247 CheckScreendump
248 CheckFeature timers
249
250 let lines =<< trim END
251 call setline(1, ['aaaaa', 'bbbbb', 'ccccc', 'ddddd'])
252 set cursorline
253 call cursor(4, 1)
254
255 func Func(timer)
256 call cursor(2, 1)
257 endfunc
258
259 call timer_start(300, 'Func')
260 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100261 call writefile(lines, 'Xcul_timer', 'D')
Bram Moolenaare7a74d52022-03-19 11:10:15 +0000262
263 let buf = RunVimInTerminal('-S Xcul_timer', #{rows: 8})
264 call TermWait(buf, 310)
265 call VerifyScreenDump(buf, 'Test_cursorline_callback_1', {})
266
267 call StopVimInTerminal(buf)
Bram Moolenaare7a74d52022-03-19 11:10:15 +0000268endfunc
269
zeertzjq86dc4f82024-09-14 10:37:17 +0200270func Test_cursorline_screenline_resize()
271 CheckScreendump
272
273 let lines =<< trim END
274 50vnew
275 call setline(1, repeat('xyz ', 30))
276 setlocal number cursorline cursorlineopt=screenline
277 normal! $
278 END
279 call writefile(lines, 'Xcul_screenline_resize', 'D')
280
281 let buf = RunVimInTerminal('-S Xcul_screenline_resize', #{rows: 8})
282 call VerifyScreenDump(buf, 'Test_cursorline_screenline_resize_1', {})
283 call term_sendkeys(buf, ":vertical resize -4\<CR>")
284 call VerifyScreenDump(buf, 'Test_cursorline_screenline_resize_2', {})
285 call term_sendkeys(buf, ":set cpoptions+=n\<CR>")
286 call VerifyScreenDump(buf, 'Test_cursorline_screenline_resize_3', {})
287
288 call StopVimInTerminal(buf)
289endfunc
290
Bram Moolenaarbf269ed2022-03-26 13:28:14 +0000291func Test_cursorline_screenline_update()
292 CheckScreendump
293
294 let lines =<< trim END
295 call setline(1, repeat('xyz ', 30))
296 set cursorline cursorlineopt=screenline
297 inoremap <F2> <Cmd>call cursor(1, 1)<CR>
298 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100299 call writefile(lines, 'Xcul_screenline', 'D')
Bram Moolenaarbf269ed2022-03-26 13:28:14 +0000300
301 let buf = RunVimInTerminal('-S Xcul_screenline', #{rows: 8})
302 call term_sendkeys(buf, "A")
303 call VerifyScreenDump(buf, 'Test_cursorline_screenline_1', {})
304 call term_sendkeys(buf, "\<F2>")
305 call VerifyScreenDump(buf, 'Test_cursorline_screenline_2', {})
306 call term_sendkeys(buf, "\<Esc>")
307
308 call StopVimInTerminal(buf)
Bram Moolenaarbf269ed2022-03-26 13:28:14 +0000309endfunc
310
zeertzjq59149f02024-09-14 10:40:29 +0200311func Test_cursorline_screenline_zero_width()
312 CheckOption foldcolumn
313
314 set cursorline culopt=screenline winminwidth=1 foldcolumn=1
315 " This used to crash Vim
316 1vnew | redraw
317
318 bwipe!
319 set cursorline& culopt& winminwidth& foldcolumn&
320endfunc
321
Christian Brabandt2c645e82022-04-20 14:52:01 +0100322func Test_cursorline_cursorbind_horizontal_scroll()
323 CheckScreendump
324
325 let lines =<< trim END
Christian Brabandt3fd74802022-04-20 22:07:41 +0100326 call setline(1, 'aa bb cc dd ee ff gg hh ii jj kk ll mm' ..
Bram Moolenaar6ed545e2022-05-09 20:09:23 +0100327 \ ' nn oo pp qq rr ss tt uu vv ww xx yy zz')
Christian Brabandt2c645e82022-04-20 14:52:01 +0100328 set nowrap
329 " The following makes the cursor apparent on the screen dump
330 set sidescroll=1 cursorcolumn
331 " add empty lines, required for cursorcolumn
332 call append(1, ['','','',''])
333 20vsp
334 windo :set cursorbind
335 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100336 call writefile(lines, 'Xhor_scroll', 'D')
Christian Brabandt2c645e82022-04-20 14:52:01 +0100337
338 let buf = RunVimInTerminal('-S Xhor_scroll', #{rows: 8})
339 call term_sendkeys(buf, "20l")
340 call VerifyScreenDump(buf, 'Test_hor_scroll_1', {})
341 call term_sendkeys(buf, "10l")
342 call VerifyScreenDump(buf, 'Test_hor_scroll_2', {})
343 call term_sendkeys(buf, ":windo :set cursorline\<cr>")
344 call term_sendkeys(buf, "0")
345 call term_sendkeys(buf, "20l")
346 call VerifyScreenDump(buf, 'Test_hor_scroll_3', {})
347 call term_sendkeys(buf, "10l")
348 call VerifyScreenDump(buf, 'Test_hor_scroll_4', {})
Christian Brabandt3fd74802022-04-20 22:07:41 +0100349 call term_sendkeys(buf, ":windo :set nocursorline nocursorcolumn\<cr>")
350 call term_sendkeys(buf, "0")
351 call term_sendkeys(buf, "40l")
352 call VerifyScreenDump(buf, 'Test_hor_scroll_5', {})
Christian Brabandt2c645e82022-04-20 14:52:01 +0100353
354 call StopVimInTerminal(buf)
Christian Brabandt2c645e82022-04-20 14:52:01 +0100355endfunc
356
Bram Moolenaare7a74d52022-03-19 11:10:15 +0000357
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200358" vim: shiftwidth=2 sts=2 expandtab