]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0262: invalid lnum when pasting text copied blockwise v9.2.0262
authorPierluigi Lenoci <pierluigi.lenoci@gmail.com>
Fri, 27 Mar 2026 15:49:27 +0000 (15:49 +0000)
committerChristian Brabandt <cb@256bit.org>
Fri, 27 Mar 2026 15:49:27 +0000 (15:49 +0000)
Problem:  invalid lnum when pasting text copied blockwise
          (KillTheMule)
Solution: Subtract nr_lines from curwin->w_cursor.lnum when calling
          changed_lines() in do_put() (Pierluigi Lenoci)

When doing a blockwise paste beyond the end of the buffer, new lines are
appended and nr_lines is incremented accordingly. However, the
changed_lines() call used curwin->w_cursor.lnum as the "lnume" argument
(the first line below the changed lines BEFORE the change), which is
incorrect because the cursor has already been moved past the newly
appended lines.

Fix by subtracting nr_lines from curwin->w_cursor.lnum, so that lnume
correctly reflects the state before the change, as documented in
changed_lines().

Add a listener test to verify the correct values are reported.

Port of neovim/neovim#12733.

fixes:  #6660
closes: #19844

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/register.c
src/testdir/test_listener.vim
src/version.c

index 1fdebce95ef22f50a16dba94c5499f508f8ab964..de89b18646d2bd5f8c214c331ba772a7dd6b2243 100644 (file)
@@ -2021,7 +2021,7 @@ do_put(
                curwin->w_cursor.col += bd.startspaces;
        }
 
-       changed_lines(lnum, 0, curwin->w_cursor.lnum, nr_lines);
+       changed_lines(lnum, 0, curwin->w_cursor.lnum - nr_lines, nr_lines);
 
        // Set '[ mark.
        curbuf->b_op_start = curwin->w_cursor;
index 91f0db2a15e344de7e556ca5195bc24e247b61d0..8cbd15377a4176b0b24458ebdd8cc9cd36a278cf 100644 (file)
@@ -782,4 +782,23 @@ func Test_redraw_listener_partial()
   call redraw_listener_add(#{on_start: function("s:OnRedraw", [1])})
 endfunc
 
+func Test_listener_blockwise_paste()
+  new
+  call setline(1, ['1', '2', '3'])
+  let s:list = []
+  let id = listener_add('s:StoreListArgs')
+
+  " yank a blockwise selection and paste at the end of the buffer, which
+  " appends new lines
+  call feedkeys("1G0\<C-v>2jyGp", 'xt')
+  call listener_flush()
+  " the listener should report correct lnume (before the change) and added
+  call assert_equal(3, s:start)
+  call assert_equal(4, s:end)
+  call assert_equal(2, s:added)
+
+  call listener_remove(id)
+  bwipe!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 2dae07da4c17b25093160cae1eae7f5cd117ad95..b1b44b7f2ff48d36dcb583ea56dbd9c86b3fc89b 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    262,
 /**/
     261,
 /**/