Skip to content

Commit 010e153

Browse files
zeertzjqchrisbra
authored andcommitted
patch 9.1.0180: Cursor pos wrong when double-width chars are concealed
Problem: Cursor pos wrong when double-width chars are concealed. Solution: Advance one more virtual column for a double-width char. Run some tests with both 'wrap' and 'nowrap' (zeertzjq). closes: #14197 Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 9352c28 commit 010e153

11 files changed

Lines changed: 137 additions & 21 deletions

src/drawline.c

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3225,7 +3225,7 @@ win_line(
32253225

32263226
// Make sure, the highlighting for the tab char will be
32273227
// correctly set further below (effectively reverts the
3228-
// FIX_FOR_BOGSUCOLS macro).
3228+
// FIX_FOR_BOGUSCOLS macro).
32293229
if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
32303230
&& wp->w_lcs_chars.tab1)
32313231
tab_len += vc_saved;
@@ -3494,6 +3494,21 @@ win_line(
34943494
else
34953495
c = ' ';
34963496

3497+
if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3498+
// When the first char to be concealed is double-width,
3499+
// need to advance one more virtual column.
3500+
wlv.n_extra++;
3501+
3502+
mb_c = c;
3503+
if (enc_utf8 && utf_char2len(c) > 1)
3504+
{
3505+
mb_utf8 = TRUE;
3506+
u8cc[0] = 0;
3507+
c = 0xc0;
3508+
}
3509+
else
3510+
mb_utf8 = FALSE; // don't draw as UTF-8
3511+
34973512
prev_syntax_id = syntax_seqnr;
34983513

34993514
if (wlv.n_extra > 0)
@@ -3522,15 +3537,6 @@ win_line(
35223537
is_concealing = TRUE;
35233538
skip_cells = 1;
35243539
}
3525-
mb_c = c;
3526-
if (enc_utf8 && utf_char2len(c) > 1)
3527-
{
3528-
mb_utf8 = TRUE;
3529-
u8cc[0] = 0;
3530-
c = 0xc0;
3531-
}
3532-
else
3533-
mb_utf8 = FALSE; // don't draw as UTF-8
35343540
}
35353541
else
35363542
{
@@ -3990,10 +3996,21 @@ win_line(
39903996
#ifdef FEAT_CONCEAL
39913997
else if (wp->w_p_cole > 0 && is_concealing)
39923998
{
3999+
int concealed_wide = has_mbyte && (*mb_char2cells)(mb_c) > 1;
4000+
39934001
--skip_cells;
39944002
++wlv.vcol_off_co;
4003+
if (concealed_wide)
4004+
{
4005+
// When a double-width char is concealed,
4006+
// need to advance one more virtual column.
4007+
++wlv.vcol;
4008+
++wlv.vcol_off_co;
4009+
}
4010+
39954011
if (wlv.n_extra > 0)
39964012
wlv.vcol_off_co += wlv.n_extra;
4013+
39974014
if (wp->w_p_wrap)
39984015
{
39994016
// Special voodoo required if 'wrap' is on.
@@ -4026,8 +4043,7 @@ win_line(
40264043
n_attr = 0;
40274044
}
40284045

4029-
4030-
if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
4046+
if (concealed_wide)
40314047
{
40324048
// Need to fill two screen columns.
40334049
# ifdef FEAT_RIGHTLEFT
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
|a+0&#ffffff0@4|β+0#e0e0e08#6c6c6c255|b+0#0000000#ffffff0@4|β+0#e0e0e08#6c6c6c255|c+0#0000000#ffffff0@3>c| @11| +0&#ffd7d7255| +0&#ffffff0@44
2+
|f|o@1|b|a|r| @22| +0&#ffd7d7255| +0&#ffffff0@44
3+
|~+0#4040ff13&| @73
4+
| +0#0000000&@56|1|,|2|9|-|2|5| @6|A|l@1|
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
|a+0&#ffffff0@4|β+0#e0e0e08#6c6c6c255|b+0#0000000#ffffff0@1>b@2|β+0#e0e0e08#6c6c6c255|c+0#0000000#ffffff0@4| @11| +0&#ffd7d7255| +0&#ffffff0@44
2+
|f|o@1|b|a|r| @22| +0&#ffd7d7255| +0&#ffffff0@44
3+
|~+0#4040ff13&| @73
4+
| +0#0000000&@56|1|,|1|5|-|1|3| @6|A|l@1|
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
|a+0&#ffffff0@4|b@1>b@2|c@4| @13| +0&#ffd7d7255| +0&#ffffff0@44
2+
|f|o@1|b|a|r| @22| +0&#ffd7d7255| +0&#ffffff0@44
3+
|~+0#4040ff13&| @73
4+
|:+0#0000000&|s|e|t| |c|o|n|c|e|a|l@1|e|v|e|l|=|3| @37|1|,|1|5|-|1|3| @6|A|l@1|
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
|a+0&#ffffff0@4|b@4|c@3>c| @13| +0&#ffd7d7255| +0&#ffffff0@44
2+
|f|o@1|b|a|r| @22| +0&#ffd7d7255| +0&#ffffff0@44
3+
|~+0#4040ff13&| @73
4+
|:+0#0000000&|s|e|t| |c|o|n|c|e|a|l@1|e|v|e|l|=|3| @37|1|,|2|9|-|2|5| @6|A|l@1|
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
|a+0&#ffffff0@9|β+0#e0e0e08#6c6c6c255|b+0#0000000#ffffff0@4| @3
2+
|b@4|β+0#e0e0e08#6c6c6c255|c+0#0000000#ffffff0@8>c| @3
3+
|~+0#4040ff13&| @18
4+
| +0#0000000&@9|1|,|4@1|-|4|0| @2
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
|a+0&#ffffff0@9|β+0#e0e0e08#6c6c6c255|b+0#0000000#ffffff0@4| @3
2+
>b@4|β+0#e0e0e08#6c6c6c255|c+0#0000000#ffffff0@9| @3
3+
|~+0#4040ff13&| @18
4+
| +0#0000000&@9|1|,|2|3|-|2|1| @2
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
|a+0&#ffffff0@9|b@4| @4
2+
>b@4|c@9| @4
3+
|~+0#4040ff13&| @18
4+
|:+0#0000000&|s|e|t| |c|o|n|c|e|1|,|2|3|-|2|1| @2
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
|a+0&#ffffff0@9|b@4| @4
2+
|b@4|c@8>c| @4
3+
|~+0#4040ff13&| @18
4+
|:+0#0000000&| @8|1|,|4@1|-|4|0| @2

src/testdir/test_conceal.vim

Lines changed: 75 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ func Test_conceal_mouse_click()
441441
call test_setmouse(1, 19)
442442
call feedkeys("\<LeftMouse>", "tx")
443443
call assert_equal([0, 1, 23, 0, 23], getcurpos())
444-
" click after end of line puts cursor there without 'virtualedit'
444+
" click after end of line puts cursor there with 'virtualedit'
445445
call test_setmouse(1, 20)
446446
call feedkeys("\<LeftMouse>", "tx")
447447
call assert_equal([0, 1, 24, 0, 24], getcurpos())
@@ -464,10 +464,9 @@ endfunc
464464

465465
" Test that cursor is drawn at the correct column when it is after end of the
466466
" line with 'virtualedit' and concealing.
467-
func Test_conceal_virtualedit_after_eol()
468-
CheckScreendump
469-
470-
let code =<< trim [CODE]
467+
func Run_test_conceal_virtualedit_after_eol(wrap)
468+
let code =<< trim eval [CODE]
469+
let &wrap = {a:wrap}
471470
call setline(1, 'abcdefgh|hidden|ijklmnpop')
472471
syntax match test /|hidden|/ conceal
473472
set conceallevel=2 concealcursor=n virtualedit=all
@@ -489,12 +488,17 @@ func Test_conceal_virtualedit_after_eol()
489488
call StopVimInTerminal(buf)
490489
endfunc
491490

492-
" Same as Test_conceal_virtualedit_after_eol(), but with 'rightleft' set.
493-
func Test_conceal_virtualedit_after_eol_rightleft()
494-
CheckFeature rightleft
491+
func Test_conceal_virtualedit_after_eol()
495492
CheckScreendump
496493

497-
let code =<< trim [CODE]
494+
call Run_test_conceal_virtualedit_after_eol(1)
495+
call Run_test_conceal_virtualedit_after_eol(0)
496+
endfunc
497+
498+
" Same as Run_test_conceal_virtualedit_after_eol(), but with 'rightleft'.
499+
func Run_test_conceal_virtualedit_after_eol_rightleft(wrap)
500+
let code =<< trim eval [CODE]
501+
let &wrap = {a:wrap}
498502
call setline(1, 'abcdefgh|hidden|ijklmnpop')
499503
syntax match test /|hidden|/ conceal
500504
set conceallevel=2 concealcursor=n virtualedit=all rightleft
@@ -516,4 +520,66 @@ func Test_conceal_virtualedit_after_eol_rightleft()
516520
call StopVimInTerminal(buf)
517521
endfunc
518522

523+
func Test_conceal_virtualedit_after_eol_rightleft()
524+
CheckFeature rightleft
525+
CheckScreendump
526+
527+
call Run_test_conceal_virtualedit_after_eol_rightleft(1)
528+
call Run_test_conceal_virtualedit_after_eol_rightleft(0)
529+
endfunc
530+
531+
" Test that cursor position is correct when double-width chars are concealed.
532+
func Run_test_conceal_double_width(wrap)
533+
let code =<< trim eval [CODE]
534+
let &wrap = {a:wrap}
535+
call setline(1, ['aaaaa口=口bbbbb口=口ccccc', 'foobar'])
536+
syntax match test /口=口/ conceal cchar=β
537+
set conceallevel=2 concealcursor=n colorcolumn=30
538+
normal! $
539+
[CODE]
540+
call writefile(code, 'XTest_conceal_double_width', 'D')
541+
let buf = RunVimInTerminal('-S XTest_conceal_double_width', {'rows': 4})
542+
call VerifyScreenDump(buf, 'Test_conceal_double_width_1', {})
543+
call term_sendkeys(buf, "gM")
544+
call VerifyScreenDump(buf, 'Test_conceal_double_width_2', {})
545+
call term_sendkeys(buf, ":set conceallevel=3\<CR>")
546+
call VerifyScreenDump(buf, 'Test_conceal_double_width_3', {})
547+
call term_sendkeys(buf, "$")
548+
call VerifyScreenDump(buf, 'Test_conceal_double_width_4', {})
549+
550+
" clean up
551+
call StopVimInTerminal(buf)
552+
endfunc
553+
554+
func Test_conceal_double_width()
555+
CheckScreendump
556+
557+
call Run_test_conceal_double_width(1)
558+
call Run_test_conceal_double_width(0)
559+
endfunc
560+
561+
" Test that line wrapping is correct when double-width chars are concealed.
562+
func Test_conceal_double_width_wrap()
563+
CheckScreendump
564+
565+
let code =<< trim [CODE]
566+
call setline(1, 'aaaaaaaaaa口=口bbbbbbbbbb口=口cccccccccc')
567+
syntax match test /口=口/ conceal cchar=β
568+
set conceallevel=2 concealcursor=n
569+
normal! $
570+
[CODE]
571+
call writefile(code, 'XTest_conceal_double_width_wrap', 'D')
572+
let buf = RunVimInTerminal('-S XTest_conceal_double_width_wrap', {'rows': 4, 'cols': 20})
573+
call VerifyScreenDump(buf, 'Test_conceal_double_width_wrap_1', {})
574+
call term_sendkeys(buf, "gM")
575+
call VerifyScreenDump(buf, 'Test_conceal_double_width_wrap_2', {})
576+
call term_sendkeys(buf, ":set conceallevel=3\<CR>")
577+
call VerifyScreenDump(buf, 'Test_conceal_double_width_wrap_3', {})
578+
call term_sendkeys(buf, "$")
579+
call VerifyScreenDump(buf, 'Test_conceal_double_width_wrap_4', {})
580+
581+
" clean up
582+
call StopVimInTerminal(buf)
583+
endfunc
584+
519585
" vim: shiftwidth=2 sts=2 expandtab

0 commit comments

Comments
 (0)