]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0585: line number wrong after undoing a deletion in quickfix buffer v9.2.0585
authorglepnir <glephunter@gmail.com>
Mon, 1 Jun 2026 20:43:56 +0000 (20:43 +0000)
committerChristian Brabandt <cb@256bit.org>
Mon, 1 Jun 2026 20:43:56 +0000 (20:43 +0000)
Problem:  Deleting a quickfix line and undoing it leaves the entry
          pointing one line below where it should.
Solution: Don't shift already cleared entries in qf_mark_adjust.

closes: #20379

Signed-off-by: glepnir <glephunter@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/quickfix.c
src/testdir/test_quickfix.vim
src/version.c

index 2470902fd182183f0738479de73ac319e84444f8..0c7a9c9a52bbf33965995c8cc4569e929866175a 100644 (file)
@@ -4434,6 +4434,9 @@ qf_mark_adjust(
                if (qfp->qf_fnum == curbuf->b_fnum)
                {
                    found_one = TRUE;
+                   if (qfp->qf_cleared)
+                       continue;
+
                    if (qfp->qf_lnum >= line1 && qfp->qf_lnum <= line2)
                    {
                        if (amount == MAXLNUM)
index b0c4475ccd383e1a987f1f3bdb8b9305fba9428a..6ffc1828a996fef405e356a2ec22ae4fc27e34c6 100644 (file)
@@ -2334,6 +2334,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)
index 208e7164d30787fd33aa8cc6f324e9c2b34384f3..be7bb521b4d6a194841e8efc53bbe0377900d056 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    585,
 /**/
     584,
 /**/