Skip to content

Commit 80a0c35

Browse files
pierluigilenocichrisbra
authored andcommitted
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 <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 54b6c0c commit 80a0c35

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/register.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2021,7 +2021,7 @@ do_put(
20212021
curwin->w_cursor.col += bd.startspaces;
20222022
}
20232023

2024-
changed_lines(lnum, 0, curwin->w_cursor.lnum, nr_lines);
2024+
changed_lines(lnum, 0, curwin->w_cursor.lnum - nr_lines, nr_lines);
20252025

20262026
// Set '[ mark.
20272027
curbuf->b_op_start = curwin->w_cursor;

src/testdir/test_listener.vim

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,4 +782,23 @@ func Test_redraw_listener_partial()
782782
call redraw_listener_add(#{on_start: function("s:OnRedraw", [1])})
783783
endfunc
784784

785+
func Test_listener_blockwise_paste()
786+
new
787+
call setline(1, ['1', '2', '3'])
788+
let s:list = []
789+
let id = listener_add('s:StoreListArgs')
790+
791+
" yank a blockwise selection and paste at the end of the buffer, which
792+
" appends new lines
793+
call feedkeys("1G0\<C-v>2jyGp", 'xt')
794+
call listener_flush()
795+
" the listener should report correct lnume (before the change) and added
796+
call assert_equal(3, s:start)
797+
call assert_equal(4, s:end)
798+
call assert_equal(2, s:added)
799+
800+
call listener_remove(id)
801+
bwipe!
802+
endfunc
803+
785804
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ static char *(features[]) =
734734

735735
static int included_patches[] =
736736
{ /* Add new patch number below this line */
737+
/**/
738+
262,
737739
/**/
738740
261,
739741
/**/

0 commit comments

Comments
 (0)