blob: f4c58dec11bd7bda5d43899e81db7fe611bb6b36 [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 Moolenaar410e98a2019-09-09 22:05:49 +02003source check.vim
Bram Moolenaar017ba072019-09-14 21:01:23 +02004source screendump.vim
Bram Moolenaar410e98a2019-09-09 22:05:49 +02005
Bram Moolenaar97f0eb12022-10-06 19:49:13 +01006func s:screen_attr(lnum) abort
Bram Moolenaar410e98a2019-09-09 22:05:49 +02007 return map(range(1, 8), 'screenattr(a:lnum, v:val)')
Bram Moolenaar97f0eb12022-10-06 19:49:13 +01008endfunc
Bram Moolenaar410e98a2019-09-09 22:05:49 +02009
Bram Moolenaar97f0eb12022-10-06 19:49:13 +010010func s:test_windows(h, w) abort
Bram Moolenaar410e98a2019-09-09 22:05:49 +020011 call NewWindow(a:h, a:w)
Bram Moolenaar97f0eb12022-10-06 19:49:13 +010012endfunc
Bram Moolenaar410e98a2019-09-09 22:05:49 +020013
Bram Moolenaar97f0eb12022-10-06 19:49:13 +010014func s:close_windows() abort
Bram Moolenaar410e98a2019-09-09 22:05:49 +020015 call CloseWindow()
Bram Moolenaar97f0eb12022-10-06 19:49:13 +010016endfunc
Bram Moolenaar410e98a2019-09-09 22:05:49 +020017
Bram Moolenaar97f0eb12022-10-06 19:49:13 +010018func s:new_hi() abort
Bram Moolenaar410e98a2019-09-09 22:05:49 +020019 redir => save_hi
20 silent! hi CursorLineNr
21 redir END
22 let save_hi = join(split(substitute(save_hi, '\s*xxx\s*', ' ', ''), "\n"), '')
23 exe 'hi' save_hi 'ctermbg=0 guibg=Black'
24 return save_hi
Bram Moolenaar97f0eb12022-10-06 19:49:13 +010025endfunc
Bram Moolenaar410e98a2019-09-09 22:05:49 +020026
27func Test_cursorline_highlight1()
28 let save_hi = s:new_hi()
29 try
30 call s:test_windows(10, 20)
31 call setline(1, repeat(['aaaa'], 10))
32 redraw
33 let attr01 = s:screen_attr(1)
34 call assert_equal(repeat([attr01[0]], 8), attr01)
35
36 setl number numberwidth=4
37 redraw
38 let attr11 = s:screen_attr(1)
39 call assert_equal(repeat([attr11[0]], 4), attr11[0:3])
40 call assert_equal(repeat([attr11[4]], 4), attr11[4:7])
41 call assert_notequal(attr11[0], attr11[4])
42
43 setl cursorline
44 redraw
45 let attr21 = s:screen_attr(1)
46 let attr22 = s:screen_attr(2)
47 call assert_equal(repeat([attr21[0]], 4), attr21[0:3])
48 call assert_equal(repeat([attr21[4]], 4), attr21[4:7])
49 call assert_equal(attr11, attr22)
50 call assert_notequal(attr22, attr21)
51
52 setl nocursorline relativenumber
53 redraw
54 let attr31 = s:screen_attr(1)
Bram Moolenaar49474ca2019-10-05 21:57:12 +020055 call assert_equal(attr22[0:3], attr31[0:3])
Bram Moolenaar410e98a2019-09-09 22:05:49 +020056 call assert_equal(attr11[4:7], attr31[4:7])
57
58 call s:close_windows()
59 finally
60 exe 'hi' save_hi
61 endtry
62endfunc
63
64func Test_cursorline_highlight2()
65 CheckOption cursorlineopt
66
67 let save_hi = s:new_hi()
68 try
69 call s:test_windows(10, 20)
70 call setline(1, repeat(['aaaa'], 10))
71 redraw
72 let attr0 = s:screen_attr(1)
73 call assert_equal(repeat([attr0[0]], 8), attr0)
74
75 setl number
76 redraw
77 let attr1 = s:screen_attr(1)
78 call assert_notequal(attr0[0:3], attr1[0:3])
79 call assert_equal(attr0[0:3], attr1[4:7])
80
81 setl cursorline cursorlineopt=both
82 redraw
83 let attr2 = s:screen_attr(1)
84 call assert_notequal(attr1[0:3], attr2[0:3])
85 call assert_notequal(attr1[4:7], attr2[4:7])
86
87 setl cursorlineopt=line
88 redraw
89 let attr3 = s:screen_attr(1)
90 call assert_equal(attr1[0:3], attr3[0:3])
91 call assert_equal(attr2[4:7], attr3[4:7])
92
93 setl cursorlineopt=number
94 redraw
95 let attr4 = s:screen_attr(1)
96 call assert_equal(attr2[0:3], attr4[0:3])
97 call assert_equal(attr1[4:7], attr4[4:7])
98
99 setl nonumber
100 redraw
101 let attr5 = s:screen_attr(1)
102 call assert_equal(attr0, attr5)
103
104 call s:close_windows()
105 finally
106 exe 'hi' save_hi
107 endtry
108endfunc
Bram Moolenaar017ba072019-09-14 21:01:23 +0200109
110func Test_cursorline_screenline()
111 CheckScreendump
112 CheckOption cursorlineopt
Bram Moolenaarc9e7e342021-07-22 21:33:03 +0200113
Bram Moolenaar017ba072019-09-14 21:01:23 +0200114 let filename='Xcursorline'
115 let lines = []
116
117 let file_content =<< trim END
118 1 foooooooo ar eins‍zwei drei vier fünf sechs sieben acht un zehn elf zwöfl dreizehn v ierzehn fünfzehn
119 2 foooooooo bar eins zwei drei vier fünf sechs sieben
120 3 foooooooo bar eins zwei drei vier fünf sechs sieben
121 4 foooooooo bar eins zwei drei vier fünf sechs sieben
122 END
123 let lines1 =<< trim END1
124 set nocp
125 set display=lastline
126 set cursorlineopt=screenline cursorline nu wrap sbr=>
127 hi CursorLineNr ctermfg=blue
128 25vsp
129 END1
130 let lines2 =<< trim END2
131 call cursor(1,1)
132 END2
133 call extend(lines, lines1)
134 call extend(lines, ["call append(0, ".. string(file_content).. ')'])
135 call extend(lines, lines2)
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100136 call writefile(lines, filename, 'D')
Bram Moolenaar017ba072019-09-14 21:01:23 +0200137 " basic test
138 let buf = RunVimInTerminal('-S '. filename, #{rows: 20})
Bram Moolenaar017ba072019-09-14 21:01:23 +0200139 call VerifyScreenDump(buf, 'Test_'. filename. '_1', {})
140 call term_sendkeys(buf, "fagj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200141 call VerifyScreenDump(buf, 'Test_'. filename. '_2', {})
142 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200143 call VerifyScreenDump(buf, 'Test_'. filename. '_3', {})
144 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200145 call VerifyScreenDump(buf, 'Test_'. filename. '_4', {})
146 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200147 call VerifyScreenDump(buf, 'Test_'. filename. '_5', {})
148 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200149 call VerifyScreenDump(buf, 'Test_'. filename. '_6', {})
150 " test with set list and cursorlineopt containing number
151 call term_sendkeys(buf, "gg0")
152 call term_sendkeys(buf, ":set list cursorlineopt+=number listchars=space:-\<cr>")
153 call VerifyScreenDump(buf, 'Test_'. filename. '_7', {})
154 call term_sendkeys(buf, "fagj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200155 call VerifyScreenDump(buf, 'Test_'. filename. '_8', {})
156 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200157 call VerifyScreenDump(buf, 'Test_'. filename. '_9', {})
158 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200159 call VerifyScreenDump(buf, 'Test_'. filename. '_10', {})
160 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200161 call VerifyScreenDump(buf, 'Test_'. filename. '_11', {})
162 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200163 call VerifyScreenDump(buf, 'Test_'. filename. '_12', {})
164 if exists("+foldcolumn") && exists("+signcolumn") && exists("+breakindent")
Dominique Pelle81b573d2022-03-22 21:14:55 +0000165 " test with set foldcolumn signcolumn and breakindent
Bram Moolenaar017ba072019-09-14 21:01:23 +0200166 call term_sendkeys(buf, "gg0")
167 call term_sendkeys(buf, ":set breakindent foldcolumn=2 signcolumn=yes\<cr>")
168 call VerifyScreenDump(buf, 'Test_'. filename. '_13', {})
169 call term_sendkeys(buf, "fagj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200170 call VerifyScreenDump(buf, 'Test_'. filename. '_14', {})
171 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200172 call VerifyScreenDump(buf, 'Test_'. filename. '_15', {})
173 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200174 call VerifyScreenDump(buf, 'Test_'. filename. '_16', {})
175 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200176 call VerifyScreenDump(buf, 'Test_'. filename. '_17', {})
177 call term_sendkeys(buf, "gj")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200178 call VerifyScreenDump(buf, 'Test_'. filename. '_18', {})
zeertzjq4f33bc22021-08-05 17:57:02 +0200179 call term_sendkeys(buf, ":set breakindent& foldcolumn& signcolumn&\<cr>")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200180 endif
zeertzjq4f33bc22021-08-05 17:57:02 +0200181 " showbreak should not be highlighted with CursorLine when 'number' is off
182 call term_sendkeys(buf, "gg0")
183 call term_sendkeys(buf, ":set list cursorlineopt=screenline listchars=space:-\<cr>")
184 call term_sendkeys(buf, ":set nonumber\<cr>")
185 call VerifyScreenDump(buf, 'Test_'. filename. '_19', {})
186 call term_sendkeys(buf, "fagj")
zeertzjq4f33bc22021-08-05 17:57:02 +0200187 call VerifyScreenDump(buf, 'Test_'. filename. '_20', {})
188 call term_sendkeys(buf, "gj")
zeertzjq4f33bc22021-08-05 17:57:02 +0200189 call VerifyScreenDump(buf, 'Test_'. filename. '_21', {})
190 call term_sendkeys(buf, "gj")
zeertzjq4f33bc22021-08-05 17:57:02 +0200191 call VerifyScreenDump(buf, 'Test_'. filename. '_22', {})
192 call term_sendkeys(buf, "gj")
zeertzjq4f33bc22021-08-05 17:57:02 +0200193 call VerifyScreenDump(buf, 'Test_'. filename. '_23', {})
194 call term_sendkeys(buf, "gj")
zeertzjq4f33bc22021-08-05 17:57:02 +0200195 call VerifyScreenDump(buf, 'Test_'. filename. '_24', {})
196 call term_sendkeys(buf, ":set list& cursorlineopt& listchars&\<cr>")
Bram Moolenaar017ba072019-09-14 21:01:23 +0200197
198 call StopVimInTerminal(buf)
Bram Moolenaar017ba072019-09-14 21:01:23 +0200199endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200200
Bram Moolenaarc9e7e342021-07-22 21:33:03 +0200201func Test_cursorline_redraw()
202 CheckScreendump
203 CheckOption cursorlineopt
204
205 let textlines =<< END
206 When the option is a list of flags, {value} must be
207 exactly as they appear in the option. Remove flags
208 one by one to avoid problems.
209 Also see |:set-args| above.
210
211The {option} arguments to ":set" may be repeated. For example: >
212 :set ai nosi sw=3 ts=3
213If you make an error in one of the arguments, an error message will be given
214and the following arguments will be ignored.
215
216 *:set-verbose*
217When 'verbose' is non-zero, displaying an option value will also tell where it
218was last set. Example: >
219 :verbose set shiftwidth cindent?
220< shiftwidth=4 ~
221 Last set from modeline line 1 ~
222 cindent ~
223 Last set from /usr/local/share/vim/vim60/ftplugin/c.vim line 30 ~
224This is only done when specific option values are requested, not for ":verbose
225set all" or ":verbose set" without an argument.
226When the option was set by hand there is no "Last set" message.
227When the option was set while executing a function, user command or
228END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100229 call writefile(textlines, 'Xtextfile', 'D')
Bram Moolenaarc9e7e342021-07-22 21:33:03 +0200230
231 let script =<< trim END
232 set cursorline scrolloff=2
233 normal 12G
234 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100235 call writefile(script, 'Xscript', 'D')
Bram Moolenaarc9e7e342021-07-22 21:33:03 +0200236
237 let buf = RunVimInTerminal('-S Xscript Xtextfile', #{rows: 20, cols: 40})
238 call VerifyScreenDump(buf, 'Test_cursorline_redraw_1', {})
239 call term_sendkeys(buf, "zt")
240 call TermWait(buf)
241 call term_sendkeys(buf, "\<C-U>")
242 call VerifyScreenDump(buf, 'Test_cursorline_redraw_2', {})
243
244 call StopVimInTerminal(buf)
Bram Moolenaarc9e7e342021-07-22 21:33:03 +0200245endfunc
246
Bram Moolenaare7a74d52022-03-19 11:10:15 +0000247func Test_cursorline_callback()
248 CheckScreendump
249 CheckFeature timers
250
251 let lines =<< trim END
252 call setline(1, ['aaaaa', 'bbbbb', 'ccccc', 'ddddd'])
253 set cursorline
254 call cursor(4, 1)
255
256 func Func(timer)
257 call cursor(2, 1)
258 endfunc
259
260 call timer_start(300, 'Func')
261 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100262 call writefile(lines, 'Xcul_timer', 'D')
Bram Moolenaare7a74d52022-03-19 11:10:15 +0000263
264 let buf = RunVimInTerminal('-S Xcul_timer', #{rows: 8})
265 call TermWait(buf, 310)
266 call VerifyScreenDump(buf, 'Test_cursorline_callback_1', {})
267
268 call StopVimInTerminal(buf)
Bram Moolenaare7a74d52022-03-19 11:10:15 +0000269endfunc
270
Bram Moolenaarbf269ed2022-03-26 13:28:14 +0000271func Test_cursorline_screenline_update()
272 CheckScreendump
273
274 let lines =<< trim END
275 call setline(1, repeat('xyz ', 30))
276 set cursorline cursorlineopt=screenline
277 inoremap <F2> <Cmd>call cursor(1, 1)<CR>
278 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100279 call writefile(lines, 'Xcul_screenline', 'D')
Bram Moolenaarbf269ed2022-03-26 13:28:14 +0000280
281 let buf = RunVimInTerminal('-S Xcul_screenline', #{rows: 8})
282 call term_sendkeys(buf, "A")
283 call VerifyScreenDump(buf, 'Test_cursorline_screenline_1', {})
284 call term_sendkeys(buf, "\<F2>")
285 call VerifyScreenDump(buf, 'Test_cursorline_screenline_2', {})
286 call term_sendkeys(buf, "\<Esc>")
287
288 call StopVimInTerminal(buf)
Bram Moolenaarbf269ed2022-03-26 13:28:14 +0000289endfunc
290
Christian Brabandt2c645e82022-04-20 14:52:01 +0100291func Test_cursorline_cursorbind_horizontal_scroll()
292 CheckScreendump
293
294 let lines =<< trim END
Christian Brabandt3fd74802022-04-20 22:07:41 +0100295 call setline(1, 'aa bb cc dd ee ff gg hh ii jj kk ll mm' ..
Bram Moolenaar6ed545e2022-05-09 20:09:23 +0100296 \ ' nn oo pp qq rr ss tt uu vv ww xx yy zz')
Christian Brabandt2c645e82022-04-20 14:52:01 +0100297 set nowrap
298 " The following makes the cursor apparent on the screen dump
299 set sidescroll=1 cursorcolumn
300 " add empty lines, required for cursorcolumn
301 call append(1, ['','','',''])
302 20vsp
303 windo :set cursorbind
304 END
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100305 call writefile(lines, 'Xhor_scroll', 'D')
Christian Brabandt2c645e82022-04-20 14:52:01 +0100306
307 let buf = RunVimInTerminal('-S Xhor_scroll', #{rows: 8})
308 call term_sendkeys(buf, "20l")
309 call VerifyScreenDump(buf, 'Test_hor_scroll_1', {})
310 call term_sendkeys(buf, "10l")
311 call VerifyScreenDump(buf, 'Test_hor_scroll_2', {})
312 call term_sendkeys(buf, ":windo :set cursorline\<cr>")
313 call term_sendkeys(buf, "0")
314 call term_sendkeys(buf, "20l")
315 call VerifyScreenDump(buf, 'Test_hor_scroll_3', {})
316 call term_sendkeys(buf, "10l")
317 call VerifyScreenDump(buf, 'Test_hor_scroll_4', {})
Christian Brabandt3fd74802022-04-20 22:07:41 +0100318 call term_sendkeys(buf, ":windo :set nocursorline nocursorcolumn\<cr>")
319 call term_sendkeys(buf, "0")
320 call term_sendkeys(buf, "40l")
321 call VerifyScreenDump(buf, 'Test_hor_scroll_5', {})
Christian Brabandt2c645e82022-04-20 14:52:01 +0100322
323 call StopVimInTerminal(buf)
Christian Brabandt2c645e82022-04-20 14:52:01 +0100324endfunc
325
Bram Moolenaare7a74d52022-03-19 11:10:15 +0000326
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200327" vim: shiftwidth=2 sts=2 expandtab