]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0112: Remove undo information, when cleaning quickfix buffer v9.1.0112
authorChristian Brabandt <cb@256bit.org>
Thu, 15 Feb 2024 19:15:04 +0000 (20:15 +0100)
committerChristian Brabandt <cb@256bit.org>
Thu, 15 Feb 2024 19:15:04 +0000 (20:15 +0100)
Problem:  When the quickfix buffer has been modified an autocommand
          may invalidate the undo stack (kawarimidoll)
Solution: When clearing the quickfix buffer, also wipe the undo stack

fixes: #13905
closes: #13928

Signed-off-by: Christian Brabandt <cb@256bit.org>
src/quickfix.c
src/testdir/test_autocmd.vim
src/version.c

index dd681ca239274697d041ede34ce6bd0a7c2cd70b..3e2d3dfcc0a70902c4b5b38efef7970237b66285 100644 (file)
@@ -4829,8 +4829,18 @@ qf_fill_buffer(qf_list_T *qfl, buf_T *buf, qfline_T *old_last, int qf_winid)
        }
 
        // delete all existing lines
+       //
+       // Note: we cannot store undo information, because
+       // qf buffer is usually not allowed to be modified.
+       //
+       // So we need to clean up undo information
+       // otherwise autocommands may invalidate the undo stack
        while ((curbuf->b_ml.ml_flags & ML_EMPTY) == 0)
            (void)ml_delete((linenr_T)1);
+
+       // Remove all undo information
+       u_blockfree(curbuf);
+       u_clearall(curbuf);
     }
 
     // Check if there is anything to display
index 6e1223275f24eb1156e673e779cf8b3132a86fb0..90dc3c1d32d66c67ae254fb6d27914d70a62c50f 100644 (file)
@@ -4413,4 +4413,32 @@ func Test_autocmd_shortmess()
   delfunc SetupVimTest_shm
 endfunc
 
+func Test_autocmd_invalidates_undo_on_textchanged()
+  CheckRunVimInTerminal
+  let script =<< trim END
+    set hidden
+    " create quickfix list (at least 2 lines to move line)
+    vimgrep /u/j %
+
+    " enter quickfix window
+    cwindow
+
+    " set modifiable
+    setlocal modifiable
+
+    " set autocmd to clear quickfix list
+
+    autocmd! TextChanged <buffer> call setqflist([])
+    " move line
+    move+1
+  END
+  call writefile(script, 'XTest_autocmd_invalidates_undo_on_textchanged', 'D')
+  let buf = RunVimInTerminal('XTest_autocmd_invalidates_undo_on_textchanged', {'rows': 20})
+  call term_sendkeys(buf, ":so %\<cr>")
+  call term_sendkeys(buf, "G")
+  call WaitForAssert({-> assert_match('^XTest_autocmd_invalidates_undo_on_textchanged\s*$', term_getline(buf, 20))}, 1000)
+
+  call StopVimInTerminal(buf)
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 72495c2f912d028167e9008aa9a490c9c00396ed..d23c9ce5af34b0249b2e241122513c20d127d191 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    112,
 /**/
     111,
 /**/