Bram Moolenaar | 9aa1569 | 2017-08-19 15:05:32 +0200 | [diff] [blame] | 1 | " Tests for 'virtualedit'. |
| 2 | |
| 3 | func Test_yank_move_change() |
Bram Moolenaar | d41babe | 2017-08-30 17:01:35 +0200 | [diff] [blame] | 4 | new |
Bram Moolenaar | 9aa1569 | 2017-08-19 15:05:32 +0200 | [diff] [blame] | 5 | call setline(1, [ |
| 6 | \ "func foo() error {", |
| 7 | \ "\tif n, err := bar();", |
| 8 | \ "\terr != nil {", |
| 9 | \ "\t\treturn err", |
| 10 | \ "\t}", |
| 11 | \ "\tn = n * n", |
| 12 | \ ]) |
| 13 | set virtualedit=all |
| 14 | set ts=4 |
| 15 | function! MoveSelectionDown(count) abort |
| 16 | normal! m` |
| 17 | silent! exe "'<,'>move'>+".a:count |
| 18 | norm! `` |
| 19 | endfunction |
| 20 | |
| 21 | xmap ]e :<C-U>call MoveSelectionDown(v:count1)<CR> |
| 22 | 2 |
| 23 | normal 2gg |
| 24 | normal J |
| 25 | normal jVj |
| 26 | normal ]e |
| 27 | normal ce |
| 28 | bwipe! |
| 29 | set virtualedit= |
| 30 | set ts=8 |
| 31 | endfunc |
Bram Moolenaar | d41babe | 2017-08-30 17:01:35 +0200 | [diff] [blame] | 32 | |
| 33 | func Test_paste_end_of_line() |
| 34 | new |
| 35 | set virtualedit=all |
| 36 | call setline(1, ['456', '123']) |
| 37 | normal! gg0"ay$ |
| 38 | exe "normal! 2G$lllA\<C-O>:normal! \"agP\r" |
| 39 | call assert_equal('123456', getline(2)) |
| 40 | |
| 41 | bwipe! |
| 42 | set virtualedit= |
| 43 | endfunc |
Bram Moolenaar | db0eede | 2018-04-25 22:38:17 +0200 | [diff] [blame] | 44 | |
Bram Moolenaar | 630afe8 | 2018-06-28 19:26:28 +0200 | [diff] [blame] | 45 | func Test_replace_end_of_line() |
| 46 | new |
| 47 | set virtualedit=all |
| 48 | call setline(1, range(20)) |
| 49 | exe "normal! gg2jv10lr-" |
| 50 | call assert_equal(["1", "-----------", "3"], getline(2,4)) |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 51 | call setline(1, range(20)) |
| 52 | exe "normal! gg2jv10lr\<c-k>hh" |
| 53 | call assert_equal(["1", "───────────", "3"], getline(2,4)) |
Bram Moolenaar | 630afe8 | 2018-06-28 19:26:28 +0200 | [diff] [blame] | 54 | |
| 55 | bwipe! |
| 56 | set virtualedit= |
| 57 | endfunc |
| 58 | |
Bram Moolenaar | db0eede | 2018-04-25 22:38:17 +0200 | [diff] [blame] | 59 | func Test_edit_CTRL_G() |
| 60 | new |
| 61 | set virtualedit=insert |
| 62 | call setline(1, ['123', '1', '12']) |
| 63 | exe "normal! ggA\<c-g>jx\<c-g>jx" |
| 64 | call assert_equal(['123', '1 x', '12 x'], getline(1,'$')) |
| 65 | |
| 66 | set virtualedit=all |
| 67 | %d_ |
| 68 | call setline(1, ['1', '12']) |
| 69 | exe "normal! ggllix\<c-g>jx" |
| 70 | call assert_equal(['1 x', '12x'], getline(1,'$')) |
| 71 | |
| 72 | |
| 73 | bwipe! |
| 74 | set virtualedit= |
| 75 | endfunc |
Bram Moolenaar | 77ccc00 | 2019-10-31 03:21:25 +0100 | [diff] [blame] | 76 | |
| 77 | func Test_edit_change() |
| 78 | new |
| 79 | set virtualedit=all |
| 80 | call setline(1, "\t⒌") |
| 81 | normal Cx |
| 82 | call assert_equal('x', getline(1)) |
Bram Moolenaar | 3e72dca | 2021-05-29 16:30:12 +0200 | [diff] [blame] | 83 | " Do a visual block change |
| 84 | call setline(1, ['a', 'b', 'c']) |
| 85 | exe "normal gg3l\<C-V>2jcx" |
| 86 | call assert_equal(['a x', 'b x', 'c x'], getline(1, '$')) |
Bram Moolenaar | 77ccc00 | 2019-10-31 03:21:25 +0100 | [diff] [blame] | 87 | bwipe! |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 88 | set virtualedit= |
| 89 | endfunc |
| 90 | |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 91 | " Tests for pasting at the beginning, end and middle of a tab character |
| 92 | " in virtual edit mode. |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 93 | func Test_paste_in_tab() |
| 94 | new |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 95 | call append(0, '') |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 96 | set virtualedit=all |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 97 | |
| 98 | " Tests for pasting a register with characterwise mode type |
| 99 | call setreg('"', 'xyz', 'c') |
| 100 | |
| 101 | " paste (p) unnamed register at the beginning of a tab |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 102 | call setline(1, "a\tb") |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 103 | call cursor(1, 2, 0) |
| 104 | normal p |
| 105 | call assert_equal('a xyz b', getline(1)) |
| 106 | |
| 107 | " paste (P) unnamed register at the beginning of a tab |
| 108 | call setline(1, "a\tb") |
| 109 | call cursor(1, 2, 0) |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 110 | normal P |
| 111 | call assert_equal("axyz\tb", getline(1)) |
| 112 | |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 113 | " paste (p) unnamed register at the end of a tab |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 114 | call setline(1, "a\tb") |
| 115 | call cursor(1, 2, 6) |
| 116 | normal p |
| 117 | call assert_equal("a\txyzb", getline(1)) |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 118 | |
| 119 | " paste (P) unnamed register at the end of a tab |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 120 | call setline(1, "a\tb") |
| 121 | call cursor(1, 2, 6) |
| 122 | normal P |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 123 | call assert_equal('a xyz b', getline(1)) |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 124 | |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 125 | " Tests for pasting a register with blockwise mode type |
| 126 | call setreg('"', 'xyz', 'b') |
| 127 | |
| 128 | " paste (p) unnamed register at the beginning of a tab |
| 129 | call setline(1, "a\tb") |
| 130 | call cursor(1, 2, 0) |
| 131 | normal p |
| 132 | call assert_equal('a xyz b', getline(1)) |
| 133 | |
| 134 | " paste (P) unnamed register at the beginning of a tab |
| 135 | call setline(1, "a\tb") |
| 136 | call cursor(1, 2, 0) |
| 137 | normal P |
| 138 | call assert_equal("axyz\tb", getline(1)) |
| 139 | |
| 140 | " paste (p) unnamed register at the end of a tab |
| 141 | call setline(1, "a\tb") |
| 142 | call cursor(1, 2, 6) |
| 143 | normal p |
| 144 | call assert_equal("a\txyzb", getline(1)) |
| 145 | |
| 146 | " paste (P) unnamed register at the end of a tab |
| 147 | call setline(1, "a\tb") |
| 148 | call cursor(1, 2, 6) |
| 149 | normal P |
| 150 | call assert_equal('a xyz b', getline(1)) |
| 151 | |
| 152 | " Tests for pasting with gp and gP in virtual edit mode |
| 153 | |
| 154 | " paste (gp) unnamed register at the beginning of a tab |
| 155 | call setline(1, "a\tb") |
| 156 | call cursor(1, 2, 0) |
| 157 | normal gp |
| 158 | call assert_equal('a xyz b', getline(1)) |
| 159 | call assert_equal([0, 1, 12, 0, 12], getcurpos()) |
| 160 | |
| 161 | " paste (gP) unnamed register at the beginning of a tab |
| 162 | call setline(1, "a\tb") |
| 163 | call cursor(1, 2, 0) |
| 164 | normal gP |
| 165 | call assert_equal("axyz\tb", getline(1)) |
| 166 | call assert_equal([0, 1, 5, 0, 5], getcurpos()) |
| 167 | |
| 168 | " paste (gp) unnamed register at the end of a tab |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 169 | call setline(1, "a\tb") |
| 170 | call cursor(1, 2, 6) |
| 171 | normal gp |
| 172 | call assert_equal("a\txyzb", getline(1)) |
| 173 | call assert_equal([0, 1, 6, 0, 12], getcurpos()) |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 174 | |
| 175 | " paste (gP) unnamed register at the end of a tab |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 176 | call setline(1, "a\tb") |
| 177 | call cursor(1, 2, 6) |
| 178 | normal gP |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 179 | call assert_equal('a xyz b', getline(1)) |
| 180 | call assert_equal([0, 1, 12, 0, 12], getcurpos()) |
| 181 | |
| 182 | " Tests for pasting a named register |
| 183 | let @r = 'xyz' |
| 184 | |
| 185 | " paste (gp) named register in the middle of a tab |
| 186 | call setline(1, "a\tb") |
| 187 | call cursor(1, 2, 2) |
| 188 | normal "rgp |
| 189 | call assert_equal('a xyz b', getline(1)) |
| 190 | call assert_equal([0, 1, 8, 0, 8], getcurpos()) |
| 191 | |
| 192 | " paste (gP) named register in the middle of a tab |
| 193 | call setline(1, "a\tb") |
| 194 | call cursor(1, 2, 2) |
| 195 | normal "rgP |
| 196 | call assert_equal('a xyz b', getline(1)) |
| 197 | call assert_equal([0, 1, 7, 0, 7], getcurpos()) |
Bram Moolenaar | 6f1f0ca | 2019-12-01 18:16:18 +0100 | [diff] [blame] | 198 | |
| 199 | bwipe! |
| 200 | set virtualedit= |
Bram Moolenaar | 77ccc00 | 2019-10-31 03:21:25 +0100 | [diff] [blame] | 201 | endfunc |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 202 | |
| 203 | " Test for yanking a few spaces within a tab to a register |
| 204 | func Test_yank_in_tab() |
| 205 | new |
| 206 | let @r = '' |
| 207 | call setline(1, "a\tb") |
| 208 | set virtualedit=all |
| 209 | call cursor(1, 2, 2) |
| 210 | normal "ry5l |
| 211 | call assert_equal(' ', @r) |
| 212 | |
| 213 | bwipe! |
| 214 | set virtualedit= |
| 215 | endfunc |
| 216 | |
Bram Moolenaar | 079119b | 2019-12-03 22:59:23 +0100 | [diff] [blame] | 217 | " Insert "keyword keyw", ESC, C CTRL-N, shows "keyword ykeyword". |
| 218 | " Repeating CTRL-N fixes it. (Mary Ellen Foster) |
| 219 | func Test_ve_completion() |
| 220 | new |
| 221 | set completeopt&vim |
| 222 | set virtualedit=all |
| 223 | exe "normal ikeyword keyw\<Esc>C\<C-N>" |
| 224 | call assert_equal('keyword keyword', getline(1)) |
| 225 | bwipe! |
| 226 | set virtualedit= |
| 227 | endfunc |
| 228 | |
| 229 | " Using "C" then then <CR> moves the last remaining character to the next |
| 230 | " line. (Mary Ellen Foster) |
| 231 | func Test_ve_del_to_eol() |
| 232 | new |
| 233 | set virtualedit=all |
| 234 | call append(0, 'all your base are belong to us') |
| 235 | call search('are', 'w') |
| 236 | exe "normal C\<CR>are belong to vim" |
| 237 | call assert_equal(['all your base ', 'are belong to vim'], getline(1, 2)) |
| 238 | bwipe! |
| 239 | set virtualedit= |
| 240 | endfunc |
| 241 | |
| 242 | " When past the end of a line that ends in a single character "b" skips |
| 243 | " that word. |
| 244 | func Test_ve_b_past_eol() |
| 245 | new |
| 246 | set virtualedit=all |
| 247 | call append(0, '1 2 3 4 5 6') |
| 248 | normal gg^$15lbC7 |
| 249 | call assert_equal('1 2 3 4 5 7', getline(1)) |
| 250 | bwipe! |
| 251 | set virtualedit= |
| 252 | endfunc |
| 253 | |
| 254 | " Make sure 'i', 'C', 'a', 'A' and 'D' works |
| 255 | func Test_ve_ins_del() |
| 256 | new |
| 257 | set virtualedit=all |
| 258 | call append(0, ["'i'", "'C'", "'a'", "'A'", "'D'"]) |
| 259 | call cursor(1, 1) |
| 260 | normal $4lix |
| 261 | call assert_equal("'i' x", getline(1)) |
| 262 | call cursor(2, 1) |
| 263 | normal $4lCx |
| 264 | call assert_equal("'C' x", getline(2)) |
| 265 | call cursor(3, 1) |
| 266 | normal $4lax |
| 267 | call assert_equal("'a' x", getline(3)) |
| 268 | call cursor(4, 1) |
| 269 | normal $4lAx |
| 270 | call assert_equal("'A'x", getline(4)) |
| 271 | call cursor(5, 1) |
| 272 | normal $4lDix |
| 273 | call assert_equal("'D' x", getline(5)) |
| 274 | bwipe! |
| 275 | set virtualedit= |
| 276 | endfunc |
| 277 | |
| 278 | " Test for yank bug reported by Mark Waggoner. |
| 279 | func Test_yank_block() |
| 280 | new |
| 281 | set virtualedit=block |
| 282 | call append(0, repeat(['this is a test'], 3)) |
| 283 | exe "normal gg^2w\<C-V>3jy" |
| 284 | call assert_equal("a\na\na\n ", @") |
| 285 | bwipe! |
| 286 | set virtualedit= |
| 287 | endfunc |
| 288 | |
| 289 | " Test "r" beyond the end of the line |
| 290 | func Test_replace_after_eol() |
| 291 | new |
| 292 | set virtualedit=all |
| 293 | call append(0, '"r"') |
| 294 | normal gg$5lrxa |
| 295 | call assert_equal('"r" x', getline(1)) |
Bram Moolenaar | 3e72dca | 2021-05-29 16:30:12 +0200 | [diff] [blame] | 296 | " visual block replace |
| 297 | %d _ |
| 298 | call setline(1, ['a', '', 'b']) |
| 299 | exe "normal 2l\<C-V>2jrx" |
| 300 | call assert_equal(['a x', ' x', 'b x'], getline(1, '$')) |
| 301 | " visual characterwise selection replace after eol |
| 302 | %d _ |
| 303 | call setline(1, 'a') |
| 304 | normal 4lv2lrx |
| 305 | call assert_equal('a xxx', getline(1)) |
Bram Moolenaar | 079119b | 2019-12-03 22:59:23 +0100 | [diff] [blame] | 306 | bwipe! |
| 307 | set virtualedit= |
| 308 | endfunc |
| 309 | |
| 310 | " Test "r" on a tab |
| 311 | " Note that for this test, 'ts' must be 8 (the default). |
| 312 | func Test_replace_on_tab() |
| 313 | new |
| 314 | set virtualedit=all |
| 315 | call append(0, "'r'\t") |
| 316 | normal gg^5lrxAy |
| 317 | call assert_equal("'r' x y", getline(1)) |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 318 | call setline(1, 'aaaaaaaaaaaa') |
| 319 | exe "normal! gg2lgR\<Tab>" |
| 320 | call assert_equal("aa\taaaa", getline(1)) |
Bram Moolenaar | 079119b | 2019-12-03 22:59:23 +0100 | [diff] [blame] | 321 | bwipe! |
| 322 | set virtualedit= |
| 323 | endfunc |
| 324 | |
| 325 | " Test to make sure 'x' can delete control characters |
| 326 | func Test_ve_del_ctrl_chars() |
| 327 | new |
| 328 | set virtualedit=all |
| 329 | call append(0, "a\<C-V>b\<CR>sd") |
| 330 | set display=uhex |
| 331 | normal gg^xxxxxxi[text] |
| 332 | set display= |
| 333 | call assert_equal('[text]', getline(1)) |
| 334 | bwipe! |
| 335 | set virtualedit= |
| 336 | endfunc |
| 337 | |
| 338 | " Test for ^Y/^E due to bad w_virtcol value, reported by |
| 339 | " Roy <royl@netropolis.net>. |
| 340 | func Test_ins_copy_char() |
| 341 | new |
| 342 | set virtualedit=all |
| 343 | call append(0, 'abcv8efi.him2kl') |
| 344 | exe "normal gg^O\<Esc>3li\<C-E>\<Esc>4li\<C-E>\<Esc>4li\<C-E> <--" |
| 345 | exe "normal j^o\<Esc>4li\<C-Y>\<Esc>4li\<C-Y>\<Esc>4li\<C-Y> <--" |
| 346 | call assert_equal(' v i m <--', getline(1)) |
| 347 | call assert_equal(' 8 . 2 <--', getline(3)) |
| 348 | bwipe! |
| 349 | set virtualedit= |
| 350 | endfunc |
| 351 | |
| 352 | " Test for yanking and pasting using the small delete register |
| 353 | func Test_yank_paste_small_del_reg() |
| 354 | new |
| 355 | set virtualedit=all |
| 356 | call append(0, "foo, bar") |
| 357 | normal ggdewve"-p |
| 358 | call assert_equal(', foo', getline(1)) |
| 359 | bwipe! |
| 360 | set virtualedit= |
| 361 | endfunc |
| 362 | |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 363 | " Test for delete that breaks a tab into spaces |
| 364 | func Test_delete_break_tab() |
| 365 | new |
| 366 | call setline(1, "one\ttwo") |
| 367 | set virtualedit=all |
| 368 | normal v3ld |
| 369 | call assert_equal(' two', getline(1)) |
| 370 | set virtualedit& |
| 371 | close! |
| 372 | endfunc |
| 373 | |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 374 | " Test for using <BS>, <C-W> and <C-U> in virtual edit mode |
| 375 | " to erase character, word and line. |
| 376 | func Test_ve_backspace() |
| 377 | new |
| 378 | call setline(1, 'sample') |
| 379 | set virtualedit=all |
| 380 | set backspace=indent,eol,start |
| 381 | exe "normal 15|i\<BS>\<BS>" |
| 382 | call assert_equal([0, 1, 7, 5], getpos('.')) |
| 383 | exe "normal 15|i\<C-W>" |
| 384 | call assert_equal([0, 1, 6, 0], getpos('.')) |
| 385 | exe "normal 15|i\<C-U>" |
| 386 | call assert_equal([0, 1, 1, 0], getpos('.')) |
| 387 | set backspace& |
| 388 | set virtualedit& |
| 389 | close! |
| 390 | endfunc |
| 391 | |
Bram Moolenaar | 3e72dca | 2021-05-29 16:30:12 +0200 | [diff] [blame] | 392 | " Test for delete (x) on EOL character and after EOL |
| 393 | func Test_delete_past_eol() |
| 394 | new |
| 395 | call setline(1, "ab") |
| 396 | set virtualedit=all |
| 397 | exe "normal 2lx" |
| 398 | call assert_equal('ab', getline(1)) |
| 399 | exe "normal 10lx" |
| 400 | call assert_equal('ab', getline(1)) |
| 401 | set virtualedit& |
| 402 | bw! |
| 403 | endfunc |
| 404 | |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 405 | " After calling s:TryVirtualeditReplace(), line 1 will contain one of these |
| 406 | " two strings, depending on whether virtual editing is on or off. |
| 407 | let s:result_ve_on = 'a x' |
| 408 | let s:result_ve_off = 'x' |
| 409 | |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 410 | " Utility function for Test_global_local_virtualedit() |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 411 | func s:TryVirtualeditReplace() |
| 412 | call setline(1, 'a') |
| 413 | normal gg7l |
| 414 | normal rx |
| 415 | endfunc |
| 416 | |
| 417 | " Test for :set and :setlocal |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 418 | func Test_global_local_virtualedit() |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 419 | new |
| 420 | |
| 421 | " Verify that 'virtualedit' is initialized to empty, can be set globally to |
| 422 | " all and to empty, and can be set locally to all and to empty. |
| 423 | call s:TryVirtualeditReplace() |
| 424 | call assert_equal(s:result_ve_off, getline(1)) |
| 425 | set ve=all |
| 426 | call s:TryVirtualeditReplace() |
| 427 | call assert_equal(s:result_ve_on, getline(1)) |
| 428 | set ve= |
| 429 | call s:TryVirtualeditReplace() |
| 430 | call assert_equal(s:result_ve_off, getline(1)) |
| 431 | setlocal ve=all |
| 432 | call s:TryVirtualeditReplace() |
| 433 | call assert_equal(s:result_ve_on, getline(1)) |
| 434 | setlocal ve= |
| 435 | call s:TryVirtualeditReplace() |
| 436 | call assert_equal(s:result_ve_off, getline(1)) |
| 437 | |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 438 | " Verify that :set affects multiple windows. |
| 439 | split |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 440 | set ve=all |
| 441 | call s:TryVirtualeditReplace() |
| 442 | call assert_equal(s:result_ve_on, getline(1)) |
| 443 | wincmd p |
| 444 | call s:TryVirtualeditReplace() |
| 445 | call assert_equal(s:result_ve_on, getline(1)) |
| 446 | set ve= |
| 447 | wincmd p |
| 448 | call s:TryVirtualeditReplace() |
| 449 | call assert_equal(s:result_ve_off, getline(1)) |
| 450 | bwipe! |
| 451 | |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 452 | " Verify that :setlocal affects only the current window. |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 453 | new |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 454 | split |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 455 | setlocal ve=all |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 456 | call s:TryVirtualeditReplace() |
| 457 | call assert_equal(s:result_ve_on, getline(1)) |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 458 | wincmd p |
| 459 | call s:TryVirtualeditReplace() |
| 460 | call assert_equal(s:result_ve_off, getline(1)) |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 461 | bwipe! |
| 462 | call s:TryVirtualeditReplace() |
| 463 | call assert_equal(s:result_ve_off, getline(1)) |
| 464 | |
| 465 | " Verify that the buffer 'virtualedit' state follows the global value only |
| 466 | " when empty and that "none" works as expected. |
| 467 | " |
| 468 | " 'virtualedit' State |
| 469 | " +--------+--------------------------+ |
| 470 | " | Local | Global | |
| 471 | " | | | |
| 472 | " +--------+--------+--------+--------+ |
| 473 | " | | "" | "all" | "none" | |
| 474 | " +--------+--------+--------+--------+ |
| 475 | " | "" | off | on | off | |
| 476 | " | "all" | on | on | on | |
| 477 | " | "none" | off | off | off | |
| 478 | " +--------+--------+--------+--------+ |
| 479 | new |
| 480 | |
| 481 | setglobal ve= |
| 482 | setlocal ve= |
| 483 | call s:TryVirtualeditReplace() |
| 484 | call assert_equal(s:result_ve_off, getline(1)) |
| 485 | setlocal ve=all |
| 486 | call s:TryVirtualeditReplace() |
| 487 | call assert_equal(s:result_ve_on, getline(1)) |
| 488 | setlocal ve=none |
| 489 | call s:TryVirtualeditReplace() |
| 490 | call assert_equal(s:result_ve_off, getline(1)) |
| 491 | |
| 492 | setglobal ve=all |
| 493 | setlocal ve= |
| 494 | call s:TryVirtualeditReplace() |
| 495 | call assert_equal(s:result_ve_on, getline(1)) |
| 496 | setlocal ve=all |
| 497 | call s:TryVirtualeditReplace() |
| 498 | call assert_equal(s:result_ve_on, getline(1)) |
| 499 | setlocal ve=none |
| 500 | call s:TryVirtualeditReplace() |
| 501 | call assert_equal(s:result_ve_off, getline(1)) |
| 502 | setlocal ve=NONE |
| 503 | call s:TryVirtualeditReplace() |
| 504 | call assert_equal(s:result_ve_off, getline(1)) |
| 505 | |
| 506 | setglobal ve=none |
| 507 | setlocal ve= |
| 508 | call s:TryVirtualeditReplace() |
| 509 | call assert_equal(s:result_ve_off, getline(1)) |
| 510 | setlocal ve=all |
| 511 | call s:TryVirtualeditReplace() |
| 512 | call assert_equal(s:result_ve_on, getline(1)) |
| 513 | setlocal ve=none |
| 514 | call s:TryVirtualeditReplace() |
| 515 | call assert_equal(s:result_ve_off, getline(1)) |
| 516 | |
| 517 | bwipe! |
| 518 | |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 519 | " Verify that the 'virtualedit' state is copied to new windows. |
| 520 | new |
| 521 | call s:TryVirtualeditReplace() |
| 522 | call assert_equal(s:result_ve_off, getline(1)) |
| 523 | split |
| 524 | setlocal ve=all |
| 525 | call s:TryVirtualeditReplace() |
| 526 | call assert_equal(s:result_ve_on, getline(1)) |
| 527 | split |
| 528 | call s:TryVirtualeditReplace() |
| 529 | call assert_equal(s:result_ve_on, getline(1)) |
| 530 | setlocal ve= |
| 531 | split |
| 532 | call s:TryVirtualeditReplace() |
| 533 | call assert_equal(s:result_ve_off, getline(1)) |
| 534 | bwipe! |
| 535 | |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 536 | setlocal virtualedit& |
| 537 | set virtualedit& |
| 538 | endfunc |
| 539 | |
Bram Moolenaar | 8fe5b9c | 2023-01-28 16:37:37 +0000 | [diff] [blame] | 540 | func Test_virtualedit_setlocal() |
| 541 | enew |
| 542 | setglobal virtualedit=all |
| 543 | setlocal virtualedit=all |
| 544 | normal! l |
| 545 | redraw |
| 546 | setlocal virtualedit=none |
| 547 | call assert_equal(1, wincol()) |
| 548 | |
| 549 | setlocal virtualedit& |
| 550 | set virtualedit& |
| 551 | endfunc |
| 552 | |
Bram Moolenaar | 8f49e69 | 2022-08-09 14:19:40 +0100 | [diff] [blame] | 553 | func Test_virtualedit_mouse() |
| 554 | let save_mouse = &mouse |
| 555 | set mouse=a |
| 556 | set virtualedit=all |
| 557 | new |
| 558 | |
| 559 | call setline(1, ["text\tword"]) |
| 560 | redraw |
| 561 | call test_setmouse(1, 4) |
| 562 | call feedkeys("\<LeftMouse>", "xt") |
| 563 | call assert_equal([0, 1, 4, 0, 4], getcurpos()) |
| 564 | call test_setmouse(1, 5) |
| 565 | call feedkeys("\<LeftMouse>", "xt") |
| 566 | call assert_equal([0, 1, 5, 0, 5], getcurpos()) |
| 567 | call test_setmouse(1, 6) |
| 568 | call feedkeys("\<LeftMouse>", "xt") |
| 569 | call assert_equal([0, 1, 5, 1, 6], getcurpos()) |
| 570 | call test_setmouse(1, 7) |
| 571 | call feedkeys("\<LeftMouse>", "xt") |
| 572 | call assert_equal([0, 1, 5, 2, 7], getcurpos()) |
| 573 | call test_setmouse(1, 8) |
| 574 | call feedkeys("\<LeftMouse>", "xt") |
| 575 | call assert_equal([0, 1, 5, 3, 8], getcurpos()) |
| 576 | call test_setmouse(1, 9) |
| 577 | call feedkeys("\<LeftMouse>", "xt") |
| 578 | call assert_equal([0, 1, 6, 0, 9], getcurpos()) |
| 579 | call test_setmouse(1, 15) |
| 580 | call feedkeys("\<LeftMouse>", "xt") |
| 581 | call assert_equal([0, 1, 10, 2, 15], getcurpos()) |
| 582 | |
| 583 | bwipe! |
| 584 | let &mouse = save_mouse |
| 585 | set virtualedit& |
| 586 | endfunc |
| 587 | |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 588 | " this was replacing the NUL at the end of the line |
Bram Moolenaar | c249913 | 2022-09-16 22:16:59 +0100 | [diff] [blame] | 589 | func Test_virtualedit_replace_after_tab() |
| 590 | new |
| 591 | s/\v/ 0 |
| 592 | set ve=all |
| 593 | let @" = '' |
| 594 | sil! norm vPvr0 |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 595 | |
Bram Moolenaar | c249913 | 2022-09-16 22:16:59 +0100 | [diff] [blame] | 596 | call assert_equal("\t0", getline(1)) |
| 597 | set ve& |
| 598 | bwipe! |
| 599 | endfunc |
| 600 | |
| 601 | |
Bram Moolenaar | 54c8d22 | 2019-12-02 20:41:39 +0100 | [diff] [blame] | 602 | " vim: shiftwidth=2 sts=2 expandtab |