]> granicus.if.org Git - vim/commitdiff
patch 8.2.1511: putting a string in Visual block mode ignores multi-byte v8.2.1511
authorBram Moolenaar <Bram@vim.org>
Sat, 22 Aug 2020 19:08:44 +0000 (21:08 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 22 Aug 2020 19:08:44 +0000 (21:08 +0200)
Problem:    Putting a string in Visual block mode ignores multi-byte
            characters.
Solution:   Adjust the column for Visual block mode. (closes #6767)

src/register.c
src/testdir/test_visual.vim
src/version.c

index 47fcd73824891f876f12987974b73002d567f7d1..61b6b2c25c7e63ba877b44a16dee87ba0a02935b 100644 (file)
@@ -1937,16 +1937,29 @@ do_put(
            --lnum;
        new_cursor = curwin->w_cursor;
 
-       // simple case: insert into current line
+       // simple case: insert into one line at a time
        if (y_type == MCHAR && y_size == 1)
        {
-           linenr_T end_lnum = 0; // init for gcc
+           linenr_T    end_lnum = 0; // init for gcc
+           linenr_T    start_lnum = lnum;
 
            if (VIsual_active)
            {
                end_lnum = curbuf->b_visual.vi_end.lnum;
                if (end_lnum < curbuf->b_visual.vi_start.lnum)
                    end_lnum = curbuf->b_visual.vi_start.lnum;
+               if (end_lnum > start_lnum)
+               {
+                   pos_T   pos;
+
+                   // "col" is valid for the first line, in following lines
+                   // the virtual column needs to be used.  Matters for
+                   // multi-byte characters.
+                   pos.lnum = lnum;
+                   pos.col = col;
+                   pos.coladd = 0;
+                   getvcol(curwin, &pos, NULL, &vcol, NULL);
+               }
            }
 
            do {
@@ -1954,6 +1967,16 @@ do_put(
                if (totlen > 0)
                {
                    oldp = ml_get(lnum);
+                   if (lnum > start_lnum)
+                   {
+                       pos_T   pos;
+
+                       pos.lnum = lnum;
+                       if (getvpos(&pos, vcol) == OK)
+                           col = pos.col;
+                       else
+                           col = MAXCOL;
+                   }
                    if (VIsual_active && col > (int)STRLEN(oldp))
                    {
                        lnum++;
index f286ba9c42cbc1bb42d0977e8adfe09156e5c7b6..3243eb03cf7e8989e6b3af50d1334b7eab9bd932 100644 (file)
@@ -922,4 +922,13 @@ func Test_visual_inner_block()
   close!
 endfunc
 
+func Test_visual_put_in_block()
+  new
+  call setline(1, ['xxxx', 'y∞yy', 'zzzz'])
+  normal 1G2yl
+  exe "normal 1G2l\<C-V>jjlp"
+  call assert_equal(['xxxx', 'y∞xx', 'zzxx'], getline(1, 3))
+  bwipe!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 60726ab942816d038c910e3a31208024a57e746b..6b4fc61732185b5340a59988b5ea95dce021f6b5 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1511,
 /**/
     1510,
 /**/