diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index cdedf5cc8c..6eee0f74b4 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -3727,6 +3727,10 @@ bool qf_mark_adjust(buf_T *buf, win_T *wp, linenr_T line1, linenr_T line2, linen FOR_ALL_QFL_ITEMS(qfl, qfp, i) { if (qfp->qf_fnum == buf->b_fnum) { found_one = true; + if (qfp->qf_cleared) { + continue; + } + if (qfp->qf_lnum >= line1 && qfp->qf_lnum <= line2) { if (amount == MAXLNUM) { qfp->qf_cleared = true; diff --git a/test/old/testdir/test_quickfix.vim b/test/old/testdir/test_quickfix.vim index 26bcb9f3ee..c7e214b366 100644 --- a/test/old/testdir/test_quickfix.vim +++ b/test/old/testdir/test_quickfix.vim @@ -2320,6 +2320,53 @@ func Test_adjust_lnum() call Xadjust_qflnum('l') endfunc +func Xqf_undo_after_delete(cchar) + call s:setup_commands(a:cchar) + + enew | only + + let fname = 'Xqfundofile' . a:cchar + call s:create_test_file(fname) + exe 'edit ' . fname + + Xgetexpr [fname . ':5:Line5', + \ fname . ':10:Line10', + \ fname . ':15:Line15'] + + " Delete the line of the second error and undo the deletion. + 10delete + let l = g:Xgetlist() + call assert_equal(5, l[0].lnum) + call assert_equal(10, l[1].lnum) + call assert_equal(14, l[2].lnum) + + undo + call assert_equal('Line10', getline(10)) + let l = g:Xgetlist() + call assert_equal(5, l[0].lnum) + call assert_equal(10, l[1].lnum) + call assert_equal(15, l[2].lnum) + + " Redo and undo again to make sure the line number does not drift. + redo + call assert_equal(14, g:Xgetlist()[2].lnum) + undo + let l = g:Xgetlist() + call assert_equal(10, l[1].lnum) + call assert_equal(15, l[2].lnum) + + call g:Xsetlist([], 'f') + enew! + call delete(fname) +endfunc + +func Test_qf_undo_after_delete() + call setloclist(0, []) + call Xqf_undo_after_delete('c') + call setqflist([]) + call Xqf_undo_after_delete('l') +endfunc + " Tests for the :grep/:lgrep and :grepadd/:lgrepadd commands func s:test_xgrep(cchar) call s:setup_commands(a:cchar)