Skip to content

Commit 4c42c7e

Browse files
h-eastbrammool
authored andcommitted
patch 9.0.1463: virtual text truncation only works with Unicode 'encoding'
Problem: Virtual text truncation only works with Unicode 'encoding'. Solution: Convert the ellipsis character to 'encoding' if needed. (Hirohito Higashi, closes #12233)
1 parent 42994bf commit 4c42c7e

5 files changed

Lines changed: 100 additions & 2 deletions

File tree

src/drawline.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,10 +739,37 @@ text_prop_position(
739739

740740
if (has_mbyte)
741741
{
742-
// change last character to '…'
742+
char_u buf[MB_MAXBYTES + 1];
743+
char_u *cp = buf;
744+
745+
// change the last character to '…', converted to the
746+
// current 'encoding'
747+
STRCPY(buf, "…");
748+
if (!enc_utf8)
749+
{
750+
vimconv_T vc;
751+
752+
vc.vc_type = CONV_NONE;
753+
convert_setup(&vc, (char_u *)"utf-8", p_enc);
754+
if (vc.vc_type != CONV_NONE)
755+
{
756+
cp = string_convert(&vc, buf, NULL);
757+
if (cp == NULL)
758+
{
759+
// when conversion fails use '>'
760+
cp = buf;
761+
STRCPY(buf, ">");
762+
}
763+
convert_setup(&vc, NULL, NULL);
764+
}
765+
}
766+
767+
lp -= (*mb_ptr2cells)(cp) - 1;
743768
lp -= (*mb_head_off)(l, lp);
744-
STRCPY(lp, "…");
769+
STRCPY(lp, cp);
745770
n_used = lp - l + 3 - before - padding;
771+
if (cp != buf)
772+
vim_free(cp);
746773
}
747774
else
748775
// change last character to '>'
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
|o+0&#ffffff0|n|e| |t|w|o| |t|h|r|e@1| |f|o|u|r| |f|i|v|e| |s|i|x| |s|e|v|e|n| +0&#ffff4012|O|N|E| |a|n|d| |T|W|O| |a|n|d| |T|H|R|E@1| |a|n|…|
2+
|o+0&#ffffff0|n|e| |t|w|o| |t|h|r|e@1| |f|o|u|r| |f|i|v|e| |s|i|x| |s|e|v|e|n| +0&#ffff4012|o|n|e| |A|N|D| |t|w|o| |A|N|D| |t|h|r|e@1| |A|N|…|
3+
|o+0&#ffffff0|n|e| |t|w|o| |t|h|r|e@1| |f|o|u|r| |f|i|v|e| |s|i|x| |s|e|v|e|n| @26
4+
| +0&#ffff4012|o|n|e| |A|N|D| |t|w|o| |A|N|D| |t|h|r|e@1| |A|N|D| |f|o|u|r| |A|N|D| |f|i|v|e| |l|e|t|s| |w|r|a|p| |a|f|t|e|r| |s|…|
5+
|c+0&#ffffff0|u|r|s|o|r| >h|e|r|e| @48
6+
|~+0#4040ff13&| @58
7+
|~| @58
8+
|~| @58
9+
| +0#0000000&@41|4|,|8| @10|A|l@1|
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
|o+0&#ffffff0|n|e| |t|w|o| |t|h|r|e@1| |f|o|u|r| |f|i|v|e| |s|i|x| |s|e|v|e|n| +0&#ffff4012|O|N|E| |a|n|d| |T|W|O| |a|n|d| |T|H|R|E@1| |a|n|…| +0&#ffffff0
2+
|o|n|e| |t|w|o| |t|h|r|e@1| |f|o|u|r| |f|i|v|e| |s|i|x| |s|e|v|e|n| +0&#ffff4012|o|n|e| |A|N|D| |t|w|o| |A|N|D| |t|h|r|e@1| |A|N|…| +0&#ffffff0
3+
|o|n|e| |t|w|o| |t|h|r|e@1| |f|o|u|r| |f|i|v|e| |s|i|x| |s|e|v|e|n| @26
4+
| +0&#ffff4012|o|n|e| |A|N|D| |t|w|o| |A|N|D| |t|h|r|e@1| |A|N|D| |f|o|u|r| |A|N|D| |f|i|v|e| |l|e|t|s| |w|r|a|p| |a|f|t|e|r| |s|…| +0&#ffffff0
5+
|c|u|r|s|o|r| >h|e|r|e| @48
6+
|~+0#4040ff13&| @58
7+
|~| @58
8+
|~| @58
9+
| +0#0000000&@41|4|,|8| @10|A|l@1|

src/testdir/test_textprop.vim

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2949,6 +2949,57 @@ func Test_props_with_text_after_truncated()
29492949
call StopVimInTerminal(buf)
29502950
endfunc
29512951

2952+
func Test_props_with_text_after_truncated_and_ambiwidth_is_double()
2953+
CheckRunVimInTerminal
2954+
2955+
let lines =<< trim END
2956+
set ambiwidth=double
2957+
call setline(1, ['one two three four five six seven'])
2958+
call prop_type_add('afterprop', #{highlight: 'Search'})
2959+
call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE'})
2960+
2961+
call setline(2, ['one two three four five six seven'])
2962+
call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right'})
2963+
2964+
call setline(3, ['one two three four five six seven'])
2965+
call prop_add(3, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five lets wrap after some more text', text_align: 'below'})
2966+
2967+
call setline(4, ['cursor here'])
2968+
normal 4Gfh
2969+
END
2970+
call writefile(lines, 'XscriptPropsWithTextAfterTrunc-and-ambiwidth-is-double', 'D')
2971+
let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterTrunc-and-ambiwidth-is-double', #{rows: 9, cols: 60})
2972+
call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_ambiw_d_1', {})
2973+
2974+
call StopVimInTerminal(buf)
2975+
endfunc
2976+
2977+
2978+
func Test_props_with_text_after_truncated_not_utf8()
2979+
CheckRunVimInTerminal
2980+
2981+
let lines =<< trim END
2982+
set enc=cp932 tenc=utf-8
2983+
call setline(1, ['one two three four five six seven'])
2984+
call prop_type_add('afterprop', #{highlight: 'Search'})
2985+
call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE'})
2986+
2987+
call setline(2, ['one two three four five six seven'])
2988+
call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right'})
2989+
2990+
call setline(3, ['one two three four five six seven'])
2991+
call prop_add(3, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five lets wrap after some more text', text_align: 'below'})
2992+
2993+
call setline(4, ['cursor here'])
2994+
normal 4Gfh
2995+
END
2996+
call writefile(lines, 'XscriptPropsWithTextAfterTrunc-enc-is-not-utf8', 'D')
2997+
let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterTrunc-enc-is-not-utf8', #{rows: 9, cols: 60})
2998+
call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_not_utf8', {})
2999+
3000+
call StopVimInTerminal(buf)
3001+
endfunc
3002+
29523003
func Test_props_with_text_empty_line()
29533004
CheckRunVimInTerminal
29543005

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,8 @@ static char *(features[]) =
695695

696696
static int included_patches[] =
697697
{ /* Add new patch number below this line */
698+
/**/
699+
1463,
698700
/**/
699701
1462,
700702
/**/

0 commit comments

Comments
 (0)