]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0056: wrong number of trailing spaces inserted after blockwise put v9.1.0056
authorVanaIgr <vanaigranov@gmail.com>
Thu, 25 Jan 2024 20:50:41 +0000 (21:50 +0100)
committerChristian Brabandt <cb@256bit.org>
Thu, 25 Jan 2024 20:58:33 +0000 (21:58 +0100)
Problem:  Incorrect number of trailing spaces inserted for multibyte
  characters when pasting a blockwise register in blockwise visual
          mode (VanaIgr)
Solution: Skip over trailing UTF-8 bytes when computing the number of trailing
          spaces (VanaIgr)

When pasting in blockwise visual mode, and the register type is <CTRL-V>, Vim
aligns the text after the replaced area by inserting spaces after pasted
lines that are shorter than the longest line. When a shorter line contains
multibyte characters, each trailing UTF-8 byte's width is counted in addition
to the width of the character itself. Each trailing byte counts as being 4
cells wide (since it would be displayed as <xx>).

closes: #13909

Signed-off-by: VanaIgr <vanaigranov@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/register.c
src/testdir/test_put.vim
src/version.c

index 8a4ae674897659b64517924f9af49512d78c21f4..3f1506a5d81a418a953e7b2584f97cc2271a6c3b 100644 (file)
@@ -1903,10 +1903,10 @@ do_put(
                spaces = y_width + 1;
                init_chartabsize_arg(&cts, curwin, 0, 0,
                                                      y_array[i], y_array[i]);
-               for (j = 0; j < yanklen; j++)
+
+               while (*cts.cts_ptr != NUL)
                {
-                   spaces -= lbr_chartabsize(&cts);
-                   ++cts.cts_ptr;
+                   spaces -= lbr_chartabsize_adv(&cts);
                    cts.cts_vcol = 0;
                }
                clear_chartabsize_arg(&cts);
index 72479ac7d4779e722b3768f68d8301c3c9399a40..559a4dccd697ab1e456899e22ca964cd8295c403 100644 (file)
@@ -12,6 +12,16 @@ func Test_put_block()
   bwipe!
 endfunc
 
+func Test_put_block_unicode()
+  new
+  call setreg('a', "À\nÀÀ\naaaaaaaaaaaa", "\<C-V>")
+  call setline(1, [' 1', ' 2', ' 3'])
+  exe "norm! \<C-V>jj\"ap"
+  let expected = ['À           1', 'ÀÀ          2', 'aaaaaaaaaaaa3']
+  call assert_equal(expected, getline(1, 3))
+  bw!
+endfunc
+
 func Test_put_char_block()
   new
   call setline(1, ['Line 1', 'Line 2'])
index 2a654c1d7560bf9d70a380255dff99c34eae8721..d06e7e99a519cf4ae4f56b8ee195f3aae42fe558 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    56,
 /**/
     55,
 /**/