Mercurial > vim
comparison src/testdir/test_conceal.vim @ 34571:fdd232ab72ea v9.1.0184
patch 9.1.0184: Cursor pos wrong when clicking with conceal and wrap
Commit: https://github.com/vim/vim/commit/d0c1b7723f7e73763597af2f97a53d94ab7ed020
Author: zeertzjq <zeertzjq@outlook.com>
Date: Sat Mar 16 15:03:33 2024 +0100
patch 9.1.0184: Cursor pos wrong when clicking with conceal and wrap
Problem: Cursor position wrong when clicking with conceal and wrap.
Solution: Use the virtual column of the last char for ScreenCols[] in
boguscols. Remove use of MAXCOL in ScreenCols[]. Rename
third argument of wlv_screen_line() to "clear_end" as that's
clearer what it does (zeertzjq).
related: 14192
closes: #14200
Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 16 Mar 2024 15:15:04 +0100 |
parents | ef55fe2ac8be |
children | 563b0a3bd697 |
comparison
equal
deleted
inserted
replaced
34570:68553f944407 | 34571:fdd232ab72ea |
---|---|
387 | 387 |
388 set nolist | 388 set nolist |
389 endfunc | 389 endfunc |
390 | 390 |
391 func Test_conceal_mouse_click() | 391 func Test_conceal_mouse_click() |
392 enew! | 392 call NewWindow(10, 40) |
393 set mouse=a | 393 set mouse=a |
394 setlocal conceallevel=2 concealcursor=nc | 394 setlocal conceallevel=2 concealcursor=nc |
395 syn match Concealed "this" conceal | 395 syn match Concealed "this" conceal |
396 hi link Concealed Search | 396 hi link Concealed Search |
397 call setline(1, 'conceal this click here') | 397 |
398 redraw | 398 " Test with both 'nocursorline' and 'cursorline', as they use two different |
399 call assert_equal(['conceal click here '], ScreenLines(1, 20)) | 399 " code paths to set virtual columns for the cells to clear. |
400 | 400 for cul in [v:false, v:true] |
401 " click on the space between "this" and "click" puts cursor there | 401 let &l:cursorline = cul |
402 call test_setmouse(1, 9) | 402 |
403 call feedkeys("\<LeftMouse>", "tx") | 403 call setline(1, 'conceal this click here') |
404 call assert_equal([0, 1, 13, 0, 13], getcurpos()) | 404 call assert_equal([ |
405 " click on 'h' of "here" puts cursor there | 405 \ 'conceal click here ', |
406 call test_setmouse(1, 16) | 406 \ ], ScreenLines(1, 40)) |
407 call feedkeys("\<LeftMouse>", "tx") | 407 |
408 call assert_equal([0, 1, 20, 0, 20], getcurpos()) | 408 " Click on the space between "this" and "click" puts cursor there. |
409 " click on 'e' of "here" puts cursor there | 409 call test_setmouse(1, 9) |
410 call test_setmouse(1, 19) | 410 call feedkeys("\<LeftMouse>", "tx") |
411 call feedkeys("\<LeftMouse>", "tx") | 411 call assert_equal([0, 1, 13, 0, 13], getcurpos()) |
412 call assert_equal([0, 1, 23, 0, 23], getcurpos()) | 412 " Click on 'h' of "here" puts cursor there. |
413 " click after end of line puts cursor on 'e' without 'virtualedit' | 413 call test_setmouse(1, 16) |
414 call test_setmouse(1, 20) | 414 call feedkeys("\<LeftMouse>", "tx") |
415 call feedkeys("\<LeftMouse>", "tx") | 415 call assert_equal([0, 1, 20, 0, 20], getcurpos()) |
416 call assert_equal([0, 1, 23, 0, 24], getcurpos()) | 416 " Click on 'e' of "here" puts cursor there. |
417 call test_setmouse(1, 21) | 417 call test_setmouse(1, 19) |
418 call feedkeys("\<LeftMouse>", "tx") | 418 call feedkeys("\<LeftMouse>", "tx") |
419 call assert_equal([0, 1, 23, 0, 25], getcurpos()) | 419 call assert_equal([0, 1, 23, 0, 23], getcurpos()) |
420 call test_setmouse(1, 22) | 420 " Click after end of line puts cursor on 'e' without 'virtualedit'. |
421 call feedkeys("\<LeftMouse>", "tx") | 421 call test_setmouse(1, 20) |
422 call assert_equal([0, 1, 23, 0, 26], getcurpos()) | 422 call feedkeys("\<LeftMouse>", "tx") |
423 call test_setmouse(1, 31) | 423 call assert_equal([0, 1, 23, 0, 24], getcurpos()) |
424 call feedkeys("\<LeftMouse>", "tx") | 424 call test_setmouse(1, 21) |
425 call assert_equal([0, 1, 23, 0, 35], getcurpos()) | 425 call feedkeys("\<LeftMouse>", "tx") |
426 call test_setmouse(1, 32) | 426 call assert_equal([0, 1, 23, 0, 25], getcurpos()) |
427 call feedkeys("\<LeftMouse>", "tx") | 427 call test_setmouse(1, 22) |
428 call assert_equal([0, 1, 23, 0, 36], getcurpos()) | 428 call feedkeys("\<LeftMouse>", "tx") |
429 | 429 call assert_equal([0, 1, 23, 0, 26], getcurpos()) |
430 set virtualedit=all | 430 call test_setmouse(1, 31) |
431 redraw | 431 call feedkeys("\<LeftMouse>", "tx") |
432 " click on the space between "this" and "click" puts cursor there | 432 call assert_equal([0, 1, 23, 0, 35], getcurpos()) |
433 call test_setmouse(1, 9) | 433 call test_setmouse(1, 32) |
434 call feedkeys("\<LeftMouse>", "tx") | 434 call feedkeys("\<LeftMouse>", "tx") |
435 call assert_equal([0, 1, 13, 0, 13], getcurpos()) | 435 call assert_equal([0, 1, 23, 0, 36], getcurpos()) |
436 " click on 'h' of "here" puts cursor there | 436 |
437 call test_setmouse(1, 16) | 437 set virtualedit=all |
438 call feedkeys("\<LeftMouse>", "tx") | 438 redraw |
439 call assert_equal([0, 1, 20, 0, 20], getcurpos()) | 439 " Click on the space between "this" and "click" puts cursor there. |
440 " click on 'e' of "here" puts cursor there | 440 call test_setmouse(1, 9) |
441 call test_setmouse(1, 19) | 441 call feedkeys("\<LeftMouse>", "tx") |
442 call feedkeys("\<LeftMouse>", "tx") | 442 call assert_equal([0, 1, 13, 0, 13], getcurpos()) |
443 call assert_equal([0, 1, 23, 0, 23], getcurpos()) | 443 " Click on 'h' of "here" puts cursor there. |
444 " click after end of line puts cursor there with 'virtualedit' | 444 call test_setmouse(1, 16) |
445 call test_setmouse(1, 20) | 445 call feedkeys("\<LeftMouse>", "tx") |
446 call feedkeys("\<LeftMouse>", "tx") | 446 call assert_equal([0, 1, 20, 0, 20], getcurpos()) |
447 call assert_equal([0, 1, 24, 0, 24], getcurpos()) | 447 " Click on 'e' of "here" puts cursor there. |
448 call test_setmouse(1, 21) | 448 call test_setmouse(1, 19) |
449 call feedkeys("\<LeftMouse>", "tx") | 449 call feedkeys("\<LeftMouse>", "tx") |
450 call assert_equal([0, 1, 24, 1, 25], getcurpos()) | 450 call assert_equal([0, 1, 23, 0, 23], getcurpos()) |
451 call test_setmouse(1, 22) | 451 " Click after end of line puts cursor there with 'virtualedit'. |
452 call feedkeys("\<LeftMouse>", "tx") | 452 call test_setmouse(1, 20) |
453 call assert_equal([0, 1, 24, 2, 26], getcurpos()) | 453 call feedkeys("\<LeftMouse>", "tx") |
454 call test_setmouse(1, 31) | 454 call assert_equal([0, 1, 24, 0, 24], getcurpos()) |
455 call feedkeys("\<LeftMouse>", "tx") | 455 call test_setmouse(1, 21) |
456 call assert_equal([0, 1, 24, 11, 35], getcurpos()) | 456 call feedkeys("\<LeftMouse>", "tx") |
457 call test_setmouse(1, 32) | 457 call assert_equal([0, 1, 24, 1, 25], getcurpos()) |
458 call feedkeys("\<LeftMouse>", "tx") | 458 call test_setmouse(1, 22) |
459 call assert_equal([0, 1, 24, 12, 36], getcurpos()) | 459 call feedkeys("\<LeftMouse>", "tx") |
460 | 460 call assert_equal([0, 1, 24, 2, 26], getcurpos()) |
461 bwipe! | 461 call test_setmouse(1, 31) |
462 set mouse& virtualedit& | 462 call feedkeys("\<LeftMouse>", "tx") |
463 call assert_equal([0, 1, 24, 11, 35], getcurpos()) | |
464 call test_setmouse(1, 32) | |
465 call feedkeys("\<LeftMouse>", "tx") | |
466 call assert_equal([0, 1, 24, 12, 36], getcurpos()) | |
467 set virtualedit& | |
468 | |
469 " Test with a wrapped line. | |
470 call setline(1, ['conceal this click here']->repeat(3)->join()) | |
471 call assert_equal([ | |
472 \ 'conceal click here conceal cli ', | |
473 \ 'ck here conceal click here ', | |
474 \ ], ScreenLines([1, 2], 40)) | |
475 " Click on boguscols puts cursor on the last char of a screen line. | |
476 for col in range(33, 40) | |
477 call test_setmouse(1, col) | |
478 call feedkeys("\<LeftMouse>", "tx") | |
479 call assert_equal([0, 1, 40, 0, 40], getcurpos()) | |
480 endfor | |
481 | |
482 " Also test with the last char of a screen line concealed. | |
483 setlocal number signcolumn=yes | |
484 call assert_equal([ | |
485 \ ' 1 conceal click here conceal ', | |
486 \ ' click here conceal click h ', | |
487 \ ' ere ', | |
488 \ ], ScreenLines([1, 3], 40)) | |
489 call test_setmouse(1, 34) | |
490 call feedkeys("\<LeftMouse>", "tx") | |
491 call assert_equal([0, 1, 32, 0, 32], getcurpos()) | |
492 call test_setmouse(2, 7) | |
493 call feedkeys("\<LeftMouse>", "tx") | |
494 call assert_equal([0, 1, 37, 0, 37], getcurpos()) | |
495 " Click on boguscols puts cursor on the last char of a screen line. | |
496 for col in range(35, 40) | |
497 call test_setmouse(1, col) | |
498 call feedkeys("\<LeftMouse>", "tx") | |
499 call assert_equal([0, 1, 34, 0, 34], getcurpos()) | |
500 call test_setmouse(2, col) | |
501 call feedkeys("\<LeftMouse>", "tx") | |
502 call assert_equal([0, 1, 68, 0, 68], getcurpos()) | |
503 endfor | |
504 setlocal number& signcolumn& | |
505 endfor | |
506 | |
507 call CloseWindow() | |
508 set mouse& | |
463 endfunc | 509 endfunc |
464 | 510 |
465 " Test that cursor is drawn at the correct column when it is after end of the | 511 " Test that cursor is drawn at the correct column when it is after end of the |
466 " line with 'virtualedit' and concealing. | 512 " line with 'virtualedit' and concealing. |
467 func Run_test_conceal_virtualedit_after_eol(wrap) | 513 func Run_test_conceal_virtualedit_after_eol(wrap) |