]> granicus.if.org Git - vim/commitdiff
patch 8.2.3454: using a count with "gp" leave cursor in wrong position v8.2.3454
authorBram Moolenaar <Bram@vim.org>
Wed, 22 Sep 2021 14:37:07 +0000 (16:37 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 22 Sep 2021 14:37:07 +0000 (16:37 +0200)
Problem:    Using a count with "gp" leave cursor in wrong position. (Naohiro
            Ono)
Solution:   Count the inserted lines. (closes #8899)

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

index b821a68d5832e025a77e7dbf3312db9f9857e2a4..3ddacb8ee4b9a38536ccff84b46fd30073001839 100644 (file)
@@ -2065,6 +2065,8 @@ do_put(
        }
        else
        {
+           linenr_T    new_lnum = new_cursor.lnum;
+
            // Insert at least one line.  When y_type is MCHAR, break the first
            // line in two.
            for (cnt = 1; cnt <= count; ++cnt)
@@ -2085,6 +2087,7 @@ do_put(
                    STRCAT(newp, ptr);
                    // insert second line
                    ml_append(lnum, newp, (colnr_T)0, FALSE);
+                   ++new_lnum;
                    vim_free(newp);
 
                    oldp = ml_get(lnum);
@@ -2103,10 +2106,13 @@ do_put(
 
                for (; i < y_size; ++i)
                {
-                   if ((y_type != MCHAR || i < y_size - 1)
-                           && ml_append(lnum, y_array[i], (colnr_T)0, FALSE)
+                   if (y_type != MCHAR || i < y_size - 1)
+                   {
+                       if (ml_append(lnum, y_array[i], (colnr_T)0, FALSE)
                                                                      == FAIL)
                            goto error;
+                       new_lnum++;
+                   }
                    lnum++;
                    ++nr_lines;
                    if (flags & PUT_FIXINDENT)
@@ -2138,6 +2144,8 @@ do_put(
                            lendiff -= (int)STRLEN(ml_get(lnum));
                    }
                }
+               if (cnt == 1)
+                   new_lnum = lnum;
            }
 
 error:
@@ -2195,7 +2203,7 @@ error:
                }
                else
                {
-                   curwin->w_cursor.lnum = lnum;
+                   curwin->w_cursor.lnum = new_lnum;
                    curwin->w_cursor.col = col;
                }
            }
index 3d4c5e72305d957570551772ca445d2f32ce1c8a..f03433628612c46e28300f4b9cb719410b8ff0ef 100644 (file)
@@ -122,4 +122,14 @@ func Test_put_visual_delete_all_lines()
   close!
 endfunc
 
+func Test_gp_with_count_leaves_cursor_at_end()
+  new
+  call setline(1, '<---->')
+  call setreg('@', "foo\nbar", 'c')
+  exe "normal 1G3|3gpix\<Esc>"
+  call assert_equal(['<--foo', 'barfoo', 'barfoo', 'barx-->'], getline(1, '$'))
+
+  bwipe!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index b1130882f84a70d7f9670af7acb987d6d8403699..fb36b14a1373a85a57b19dcaff756655516d2232 100644 (file)
@@ -757,6 +757,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3454,
 /**/
     3453,
 /**/