From: Pierluigi Lenoci Date: Fri, 27 Mar 2026 15:49:27 +0000 (+0000) Subject: patch 9.2.0262: invalid lnum when pasting text copied blockwise X-Git-Tag: v9.2.0262^0 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=80a0c355cff08bc8a20d548cc1e62a11a978babb;p=thirdparty%2Fvim.git patch 9.2.0262: invalid lnum when pasting text copied blockwise 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 Signed-off-by: Christian Brabandt --- diff --git a/src/register.c b/src/register.c index 1fdebce95e..de89b18646 100644 --- a/src/register.c +++ b/src/register.c @@ -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; diff --git a/src/testdir/test_listener.vim b/src/testdir/test_listener.vim index 91f0db2a15..8cbd15377a 100644 --- a/src/testdir/test_listener.vim +++ b/src/testdir/test_listener.vim @@ -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\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 diff --git a/src/version.c b/src/version.c index 2dae07da4c..b1b44b7f2f 100644 --- a/src/version.c +++ b/src/version.c @@ -734,6 +734,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 262, /**/ 261, /**/