From f53c2578e79877376259390840ccce56963251c4 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sat, 14 Jul 2018 18:32:40 -0400 Subject: [PATCH] vim-patch:8.0.1575: crash when using virtual replace Problem: Crash when using virtual replace. Solution: Adjust orig_line_count. Add more tests. (Christian Brabandt) https://github.com/vim/vim/commit/63e82db6fc910b2d8f1cd018894e50e8b4448155 --- src/nvim/edit.c | 7 ++++ src/nvim/testdir/test_visual.vim | 59 ++++++++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 95c903c90c..4945b2b3c8 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -7486,6 +7486,13 @@ static void ins_del(void) vim_beep(BO_BS); } else { curwin->w_cursor.col = temp; + // Adjust orig_line_count in case more lines have been deleted than + // have been added. That makes sure, that open_line() later + // can access all buffer lines correctly + if (State & VREPLACE_FLAG + && orig_line_count > curbuf->b_ml.ml_line_count) { + orig_line_count = curbuf->b_ml.ml_line_count; + } } } else if (del_char(false) == FAIL) { // delete char under cursor vim_beep(BO_BS); diff --git a/src/nvim/testdir/test_visual.vim b/src/nvim/testdir/test_visual.vim index 6520666d45..fb868e09a5 100644 --- a/src/nvim/testdir/test_visual.vim +++ b/src/nvim/testdir/test_visual.vim @@ -159,6 +159,61 @@ func Test_virtual_replace() call assert_equal(['AB......CDEFGHI.Jkl', \ 'AB IJKLMNO QRst'], getline(12, 13)) enew! + set noai bs&vim t_kD&vim t_kb&vim +endfunc + +" Test Virtual replace mode. +func Test_virtual_replace2() + enew! + set bs=2 + exe "normal a\nabcdefghi\njk\tlmn\n opq rst\n\uvwxyz" + call cursor(1,1) + " Test 1: Test that del deletes the newline + exe "normal gR0\ 1\nA\nBCDEFGHIJ\n\tKL\nMNO\nPQR" + call assert_equal(['0 1', + \ 'A', + \ 'BCDEFGHIJ', + \ ' KL', + \ 'MNO', + \ 'PQR', + \ ], getline(1, 6)) + " Test 2: + " a newline is not deleted, if no newline has been added in virtual replace mode + %d_ + call setline(1, ['abcd', 'efgh', 'ijkl']) + call cursor(2,1) + exe "norm! gR1234\5\\\" + call assert_equal(['abcd', + \ '123h', + \ 'ijkl'], getline(1, '$')) + " Test 3: + " a newline is deleted, if a newline has been inserted before in virtual replace mode + %d_ + call setline(1, ['abcd', 'efgh', 'ijkl']) + call cursor(2,1) + exe "norm! gR1234\\56\\\" + call assert_equal(['abcd', + \ '1234', + \ 'ijkl'], getline(1, '$')) + " Test 4: + " delete add a newline, delete it, add it again and check undo + %d_ + call setline(1, ['abcd', 'efgh', 'ijkl']) + call cursor(2,1) + " break undo sequence explicitly + let &ul = &ul + exe "norm! gR1234\\\56\" + let &ul = &ul + call assert_equal(['abcd', + \ '123456', + \ ''], getline(1, '$')) + norm! u + call assert_equal(['abcd', + \ 'efgh', + \ 'ijkl'], getline(1, '$')) + " clean up + %d_ + set bs&vim endfunc " Test for Visual mode not being reset causing E315 error. @@ -171,14 +226,14 @@ func TriggerTheProblem() exe "normal \" catch /^Vim\%((\a\+)\)\=:E315/ echom 'Snap! E315 error!' - let g:msg='Snap! E315 error!' + let g:msg = 'Snap! E315 error!' endtry endfunc func Test_visual_mode_reset() set belloff=all enew - let g:msg="Everything's fine." + let g:msg = "Everything's fine." enew setl buftype=nofile call append(line('$'), 'Delete this line.')