]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1463: virtual text truncation only works with Unicode 'encoding' v9.0.1463
authorh-east <h.east.727@gmail.com>
Mon, 17 Apr 2023 20:44:57 +0000 (21:44 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 17 Apr 2023 20:44:57 +0000 (21:44 +0100)
Problem:    Virtual text truncation only works with Unicode 'encoding'.
Solution:   Convert the ellipsis character to 'encoding' if needed. (Hirohito
            Higashi, closes #12233)

src/drawline.c
src/testdir/dumps/Test_prop_with_text_after_trunc_ambiw_d_1.dump [new file with mode: 0644]
src/testdir/dumps/Test_prop_with_text_after_trunc_not_utf8.dump [new file with mode: 0644]
src/testdir/test_textprop.vim
src/version.c

index 5c647507d83d9ad7f390e66e77bb0edd7304a29b..c7510a65a2408fc5a910d502194bb00593114eb3 100644 (file)
@@ -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 (file)
index 0000000..dcbf820
--- /dev/null
@@ -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 (file)
index 0000000..ae5b809
--- /dev/null
@@ -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| 
index 3d196d9e13001c38170766f7bbbf018c8e098cce..9cd09bd1bb2133ffeb0d2f7f5c5104e9d451e23c 100644 (file)
@@ -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
 
index 6dc7e34313fd7dc1e8c3bf54a86881936aedf4a5..6c8d76e38afb5ebfe68002405516df3483cb20f1 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1463,
 /**/
     1462,
 /**/