summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorh-east <h.east.727@gmail.com>2023-04-17 21:44:57 +0100
committerBram Moolenaar <Bram@vim.org>2023-04-17 21:44:57 +0100
commit4c42c7eef43ff0f58fa574f7a900c8a3313f372e (patch)
tree5ee60a73f7f90435130816f1fc91196deb336932
parent42994bf678f46dc9ca66e49f512261da8864fff6 (diff)
downloadvim-git-4c42c7eef43ff0f58fa574f7a900c8a3313f372e.tar.gz
patch 9.0.1463: virtual text truncation only works with Unicode 'encoding'v9.0.1463
Problem: Virtual text truncation only works with Unicode 'encoding'. Solution: Convert the ellipsis character to 'encoding' if needed. (Hirohito Higashi, closes #12233)
-rw-r--r--src/drawline.c31
-rw-r--r--src/testdir/dumps/Test_prop_with_text_after_trunc_ambiw_d_1.dump9
-rw-r--r--src/testdir/dumps/Test_prop_with_text_after_trunc_not_utf8.dump9
-rw-r--r--src/testdir/test_textprop.vim51
-rw-r--r--src/version.c2
5 files changed, 100 insertions, 2 deletions
diff --git a/src/drawline.c b/src/drawline.c
index 5c647507d..c7510a65a 100644
--- a/src/drawline.c
+++ b/src/drawline.c
@@ -739,10 +739,37 @@ text_prop_position(
if (has_mbyte)
{
- // change last character to '…'
+ char_u buf[MB_MAXBYTES + 1];
+ char_u *cp = buf;
+
+ // change the last character to '…', converted to the
+ // current 'encoding'
+ STRCPY(buf, "…");
+ if (!enc_utf8)
+ {
+ vimconv_T vc;
+
+ vc.vc_type = CONV_NONE;
+ convert_setup(&vc, (char_u *)"utf-8", p_enc);
+ if (vc.vc_type != CONV_NONE)
+ {
+ cp = string_convert(&vc, buf, NULL);
+ if (cp == NULL)
+ {
+ // when conversion fails use '>'
+ cp = buf;
+ STRCPY(buf, ">");
+ }
+ convert_setup(&vc, NULL, NULL);
+ }
+ }
+
+ lp -= (*mb_ptr2cells)(cp) - 1;
lp -= (*mb_head_off)(l, lp);
- STRCPY(lp, "…");
+ STRCPY(lp, cp);
n_used = lp - l + 3 - before - padding;
+ if (cp != buf)
+ vim_free(cp);
}
else
// change last character to '>'
diff --git a/src/testdir/dumps/Test_prop_with_text_after_trunc_ambiw_d_1.dump b/src/testdir/dumps/Test_prop_with_text_after_trunc_ambiw_d_1.dump
new file mode 100644
index 000000000..dcbf82046
--- /dev/null
+++ b/src/testdir/dumps/Test_prop_with_text_after_trunc_ambiw_d_1.dump
@@ -0,0 +1,9 @@
+|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|…|
+|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|…|
+|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
+| +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|…|
+|c+0&#ffffff0|u|r|s|o|r| >h|e|r|e| @48
+|~+0#4040ff13&| @58
+|~| @58
+|~| @58
+| +0#0000000&@41|4|,|8| @10|A|l@1|
diff --git a/src/testdir/dumps/Test_prop_with_text_after_trunc_not_utf8.dump b/src/testdir/dumps/Test_prop_with_text_after_trunc_not_utf8.dump
new file mode 100644
index 000000000..ae5b809df
--- /dev/null
+++ b/src/testdir/dumps/Test_prop_with_text_after_trunc_not_utf8.dump
@@ -0,0 +1,9 @@
+|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
+|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
+|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
+| +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
+|c|u|r|s|o|r| >h|e|r|e| @48
+|~+0#4040ff13&| @58
+|~| @58
+|~| @58
+| +0#0000000&@41|4|,|8| @10|A|l@1|
diff --git a/src/testdir/test_textprop.vim b/src/testdir/test_textprop.vim
index 3d196d9e1..9cd09bd1b 100644
--- a/src/testdir/test_textprop.vim
+++ b/src/testdir/test_textprop.vim
@@ -2949,6 +2949,57 @@ func Test_props_with_text_after_truncated()
call StopVimInTerminal(buf)
endfunc
+func Test_props_with_text_after_truncated_and_ambiwidth_is_double()
+ CheckRunVimInTerminal
+
+ let lines =<< trim END
+ set ambiwidth=double
+ call setline(1, ['one two three four five six seven'])
+ call prop_type_add('afterprop', #{highlight: 'Search'})
+ call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE'})
+
+ call setline(2, ['one two three four five six seven'])
+ call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right'})
+
+ call setline(3, ['one two three four five six seven'])
+ 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'})
+
+ call setline(4, ['cursor here'])
+ normal 4Gfh
+ END
+ call writefile(lines, 'XscriptPropsWithTextAfterTrunc-and-ambiwidth-is-double', 'D')
+ let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterTrunc-and-ambiwidth-is-double', #{rows: 9, cols: 60})
+ call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_ambiw_d_1', {})
+
+ call StopVimInTerminal(buf)
+endfunc
+
+
+func Test_props_with_text_after_truncated_not_utf8()
+ CheckRunVimInTerminal
+
+ let lines =<< trim END
+ set enc=cp932 tenc=utf-8
+ call setline(1, ['one two three four five six seven'])
+ call prop_type_add('afterprop', #{highlight: 'Search'})
+ call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE'})
+
+ call setline(2, ['one two three four five six seven'])
+ call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right'})
+
+ call setline(3, ['one two three four five six seven'])
+ 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'})
+
+ call setline(4, ['cursor here'])
+ normal 4Gfh
+ END
+ call writefile(lines, 'XscriptPropsWithTextAfterTrunc-enc-is-not-utf8', 'D')
+ let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterTrunc-enc-is-not-utf8', #{rows: 9, cols: 60})
+ call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_not_utf8', {})
+
+ call StopVimInTerminal(buf)
+endfunc
+
func Test_props_with_text_empty_line()
CheckRunVimInTerminal
diff --git a/src/version.c b/src/version.c
index 6dc7e3431..6c8d76e38 100644
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1463,
+/**/
1462,
/**/
1461,