changeset 32264:0df66713766e v9.0.1463

patch 9.0.1463: virtual text truncation only works with Unicode 'encoding' Commit: https://github.com/vim/vim/commit/4c42c7eef43ff0f58fa574f7a900c8a3313f372e Author: h-east <h.east.727@gmail.com> Date: Mon Apr 17 21:44:57 2023 +0100 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)
author Bram Moolenaar <Bram@vim.org>
date Mon, 17 Apr 2023 23:00:05 +0200
parents e5aa6508bcc1
children ca3f9e8b3c03
files src/drawline.c src/testdir/dumps/Test_prop_with_text_after_trunc_ambiw_d_1.dump src/testdir/dumps/Test_prop_with_text_after_trunc_not_utf8.dump src/testdir/test_textprop.vim src/version.c
diffstat 5 files changed, 100 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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 '>'
new file mode 100644
--- /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| 
new file mode 100644
--- /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| 
--- a/src/testdir/test_textprop.vim
+++ b/src/testdir/test_textprop.vim
@@ -2949,6 +2949,57 @@ func Test_props_with_text_after_truncate
   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
 
--- 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,